Learn to code

Arduino Home

Lessons 1
Arduino - Getting Started
Lessons 2
Arduino - Basics
Lessons 3
Arduino - Serial Communication
Lessons 4
Arduino - Digital / Analog
Lessons 5
Arduino - Visual Output
Lessons 6
Arduino - Motor Control
Lessons 7
Arduino -LCD Displays
Lessons 8
Arduino -LCD Displays

Arduino Tutorial: 4.0 Introduction into digital / analog pins

in Arduino Digital / Analog

The following tutorials cover the Arduino’s ability to sense digital and analog inputs and to respond to these inputs. The upcoming tutorials introduces techniques that you can use for these inputs. We explore the use of a digital input by using the example of a button. Furthermore, we will look at the basic technique of how to read analog values.

Digital input pins sense the presence and absence of voltage on a pin. Analog input pins measure a range of voltages on a pin. In the below picture of the Arduino Uno Board, you can see where the Digital /  Analog pins are on the board.

Arduino Uno

Digital and Analog Pins

To read digital input Arduino uses a function called digitalRead() and it tells you if a voltage on a pin is HIGH (5volts) or LOW (0) volts. Before you can read the digital pin you will need to tell the Arduino that the pin will be used for reading input. Therefore, we use the function pinMode(pin, input) to configure the pin. 

On the Arduino Uno Board, see the picture above, there are 14 digital pins (numbered 0 to 13). Pins 0 and 1 (named RX and TX) are for serial connection and should not be used for other uses. In the case that 14 digital pins are not enough you can always use the analog pins as digital pins.

Another important for digital and analog inputs are the use of external resistors. The tutorials on this website will use external resistors for providing the voltage that is measured by digitalRead. Resistors are called pulled-up when the pull-up voltage from the 5V line on a breadboard. When voltage is pulled down to 0 volts by a resistor we call the resister a pull-down resistor. 

Unlike a digital value, which is on or off, analog values have multiple readings. For example, the volume settings on your mobile. It is not just on or off, but it can have a range of values between on and off. Arduino uses a function named analogRead to get the sensor value proportional to the voltage it sees on the analog pin.

The value will be 0 if there are 0 volts on the pin and the value will be 1023 if there are 5 volts on the pin. The value in between will be proportional. So 2.5 volts will give a value of 511. On the Arduino Uno Board, there are six analog pins (numbered from 0 to 5). Remember, these pins can also be used as digital pins. In the upcoming tutorials, we will see how we can adjust the voltage on a pin manually or by sensing the environment from the sensor. 

let’s go in and make a button that controls a LED: Arduino Tutorial: 4.1 Control a LED with a button. If you would like to know more about LEDs, please go to chapter 5 of the tutorials.

Next Post
Controlling a LED with a button for Arduino
You must be logged in to post a comment.