Documente Academic
Documente Profesional
Documente Cultură
https://www.allaboutcircuits.com/projects/learn-how-to-use-the-arduinos-digital-i-o/ 1/8
3/17/2018 How to Use the Arduino’s Digital I/O
The digital inputs and outputs (digital I/O) on the Arduino are
what allow you to connect the Arduino sensors, actuators,
and other ICs. Learning how to use them will allow you to
use the Arduino to do some really useful things, such as
reading switch inputs, lighting indicators, and controlling
relay outputs.
Digital signals
Unlike analog signals, which may take on any value within a range of values,
digital signals have two distinct values: HIGH (1) or LOW (0). You use digital
signals in situations
where the input or output will have one of those two values. For example,
one way that you might use a digital signal is to turn an LED on or off.
Functions
The Arduino functions associated with digital signals that we will be using in
this tutorial are:
pinMode()
digitalRead()
digitalWrite()
Because the Arduino digital I/O pins can be used for either input or output,
you should first configure the pins you intend to use for digital I/O with this
function. pin is the
number of the pin you wish to configure. mode must be one of three values:
INPUT, OUTPUT, our INPUT_PULLUP. When mode is set to
INPUT_PULLUP, a 20 kohm pullup resistor is internally connected to the pin
https://www.allaboutcircuits.com/projects/learn-how-to-use-the-arduinos-digital-i-o/ 2/8
3/17/2018 How to Use the Arduino’s Digital I/O
digitalWrite(pin_number,value)
This function writes a digital value to a pin. pin specifies which Arduino pin
the digital value will be written to, and value is the digital value to which the
pin is set. value
must be either HIGH or LOW.
digitalRead(pin_number)
This function reads a digital value from a pin. pin is the number of the digital
I/O pin you want to read. This function returns one of two values: HIGH or
LOW.
Hardware Required
1 x LED
1 x 220 ohm resistor
1 x Arduino UNO
1 x breadboard
2 x jumper Wires
Wiring Diagram
https://www.allaboutcircuits.com/projects/learn-how-to-use-the-arduinos-digital-i-o/ 3/8
3/17/2018 How to Use the Arduino’s Digital I/O
The figure above shows how to connect the LED and the 220 ohm resistor to
the Arduino. As shown, the LED connects to digital I/O pin 8 of the Arduino
through the resistor. The resistor controls the current through the LED. The
program below first configures pin 8 to be an OUTPUT, then sets the digital
I/O pin to HIGH for 1000 ms, then to LOW for another 1000 ms.
void loop()
{
delay(1000); //delay 1000 milliseconds
digitalWrite(led,HIGH); //set pin 8 HIGH, turning on LED
delay(1000); //delay 1000 milliseconds
digitalWrite(led,LOW); //set pin 8 LOW, turning off LED
}
https://www.allaboutcircuits.com/projects/learn-how-to-use-the-arduinos-digital-i-o/ 4/8
3/17/2018 How to Use the Arduino’s Digital I/O
3. Connect the Arduino to the PC using Arduino USB cable and transfer
the program to Arduino using Arduino IDE software.
Hardware Required
1 x LED
2 x 220 ohm resistor
1x pushbutton switch
1 x Arduino UNO
1 x breadboard
6 x jumper Wires
https://www.allaboutcircuits.com/projects/learn-how-to-use-the-arduinos-digital-i-o/ 5/8
3/17/2018 How to Use the Arduino’s Digital I/O
Wiring Diagram
As you can see from the diagram above, we are now using two Arduino
digital I/O pins. An LED is connected to pin 8, which is configured as an
OUTPUT. A pushbutton is connected to pin 9, which is configured as an
INPUT. When someone presses the pushbutton switch, pin 9 is set to HIGH,
and the program will then set the output of pin 8 to HIGH and turning on the
LED. Releasing the pushbutton resets pin 9 to LOW. The program then sets
pin 8 to LOW, which turns off the LED.
Code
https://www.allaboutcircuits.com/projects/learn-how-to-use-the-arduinos-digital-i-o/ 6/8
3/17/2018 How to Use the Arduino’s Digital I/O
Videos
https://www.allaboutcircuits.com/projects/learn-how-to-use-the-arduinos-digital-i-o/ 7/8
3/17/2018 How to Use the Arduino’s Digital I/O
https://www.allaboutcircuits.com/projects/learn-how-to-use-the-arduinos-digital-i-o/ 8/8