Arduino:
Digital Input/output
Toby, Samuel and Dolapo
Digital vs. Analog
• Binary vs. continuous signals
• Binary/Digital = “whether or not”
• Continuous/Analog = “how much” or “faster”,
“brighter”, etc.
Analog Vs. Digital
Analog
Digital
What is digital?
• Digital signals are based on a 2 – value logic.
Everything is either TRUE or FALSE, ON or OFF
• It is how computers calculate and reason
• Example of digital signals
Digital signals as voltage
• Digital hardware read voltage as either high or low
• The middle range is usually not understood and gives
unpredictable readings.
Digital signal as Voltage Cont.
• The actual value of these voltage differ in different families of
devices
• TTL use voltage range of 0- 5V, while CMOS use 0-3.3V.
Arduino Digital I/O
Arduino I/O Voltages
• They are very flexible
• Digital inputs can be considered perfect measuring devices if
they draw no current and interpret the voltage 2.6 – 5V as
HIGH and 0 – 2.1V as LOW
Arduino Digital Output
• Most designs involve digital I/O pins
Using Digital Pins on Arduino
• pinMode()
• digitalRead()
• digitalWrite()
pinMode()
• Description: Configures the specified pin to behave either as an
input or an output. See the description of digital pins for details
on the functionality of the pins.
• Syntax: pinMode(pin, mode)
• Parameters:
• pin = the number of the pin whose mode you wish to set
• mode = INPUT, OUTPUT, or INPUT_PULLUP
digitalWrite()
• Description: Write a HIGH or a Low value to a digital pin. If the
pin has been configured as an OUTPUT with pinMode(), its
voltage will be set to the corresponding value: 5V (or 3.3V on
3.3V boards) for HIGH, 0V (ground) for LOW.
• Syntax: digitalWrite(pin, value)
• Parameters:
• pin = the pin number
• Value = HIGH or LOW
digitalRead()
• Description: Reads the value from a specified digital pin, either
HIGH or LOW.
• Syntax: digitalRead(pin)
• Parameters:
• Pin = the number of the digital pin you want to read (int)
• Returns: HIGH or LOW
Blink Example: Hardware
Blink Example : Code
Button example: Hardware
Button example: Code
More on buttons
• Button and serial
• Button counter
Questions