Newbie Zone


MicroController

Arduino

Arduino Starting

Arduino Setup

Arduino Blink

Arduino Digital Pin

Arduino Digital I/O

Arduino Digital I/O

Digital or discrete inputs and outputs are the most common types of signals found in microprocessor systems. Digital I/O usually deals with TTL level voltage changes directly. The typical input signal voltages range from 0v to 0.8v for a low state, and 2v to 5v for a high state. The typical output signal voltages range from 0v to 0.5v for a low state and 2.7v to 5v for a high state.

Digital Input

The most common digital input device is contact switch. By applying electrical signal to the switch, the opening and closing of contact can be used to change the voltage level at the interface circuitry of input pin.

image

In order to prevent the floating of pin, resistors are added to the input circuits. The using of pull-up resistors are the most common method.

image

The other ways are the using of pull-down resistors.

image

Digital Output

A simple application of digital output is turning a LED on or off. The digital output signal can be used to drive a LED circuit directly by changing the voltage level of the digital output pin at the interface circuitry.

image

Code


Code to test the combination of different types of digital inputs and outputs.
/*
 Digital I/O
 
 Turns on and off LEDs connected to digital output pins
 by switching a DIP switch connected to digital input pins.
 
 The circuit:
 * Switch input with pull up circuits connected to pin 4 and pin 5.
 * Switch input with pull down circuits connected to pin 6 and pin 7 
 
 * LEDs connected from pin 8 and pin 10 to ground (source current).
 * LEDs connected from 5V to pin 9 and pin 11 (sink current)
   
 digital_io.pde
 Created 20 July 2010
 by Aaron 
  
 */

// The setup() method runs once, when the sketch starts

void setup()   {                
  // initialize the digital pin as an input:
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(7, INPUT);
  // initialize the digital pin as an output:
  pinMode(8, OUTPUT);  
  pinMode(9, OUTPUT); 
  pinMode(10, OUTPUT);  
  pinMode(11, OUTPUT); 
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()                     
{
  if (digitalRead(4)==HIGH) {
     // set the pin output high
     digitalWrite(8,HIGH); 
  }
  else {
     // set the pin output low
     digitalWrite(8,LOW); 
  }
  if (digitalRead(5)==HIGH) {
     // set the pin output high
     digitalWrite(9,HIGH); 
  }
  else {
     // set the pin output low
     digitalWrite(9,LOW); 
  }
  if (digitalRead(6)==HIGH) {
     // set the pin output high
     digitalWrite(10,HIGH); 
  }
  else {
     // set the pin output low
     digitalWrite(10,LOW); 
  }
  if (digitalRead(7)==HIGH) {
     // set the pin output high
     digitalWrite(11,HIGH); 
  }
  else {
     // set the pin output low
     digitalWrite(11,LOW); 
  }
}

Hardware

Hardware to examine the combination of different types of digital inputs and outputs.

image


Last Modified on 7/23/2010


Copyright © 2000-2019 Sideway . All rights reserved Disclaimers last modified on 29 August 2019


Valid XHTML 1.0 Transitional Valid CSS! Firefox47 IExplorern/a