How To Read Analog Inputs In Arduino
Reading analog inputs will help us to better interact our arduino project with the external environment around us. As many sensors are providing analog output when measuring some property. Like distance, temperature, speed, light brightness and much more. In our case we are going to use the potentiometer we just saw as simple analog sensor to start learning how to read analog input. Ok, so for reading an analog input, assuming all hardware is already connected.We should perform the following steps:
- Setup analog pin as input.
- Well this is not needed as the 6 analog pins are.
- Only used as input !!! So we don't need to that.
- Digital means something is either on or off.
- But analog means it can have a continuous range of values.
- The arduino has some built-in module called adc – analog to digital convertor.
- That convert the voltage seen on the pin to a number that we can be used in our program.
- This module will return a value between 0 and 1023, this is like 10 bits.
- So, 0v would read as 0 number and 5v would read as the maximum:1023.
- So we will use the analogread function to read the analog sensor value in voltage.
- Translate that to digital value and store it in a integer variable to be used later in our code.
- The digital value range that we will get from an analog sensor should be tested before being used.
- The easy way to do that is by using the serial monitoring.
- Only than mapping the input value range to the needed output range.
- Now, let’s start to do it in step by step.
Watch this tutorial and practical demonstration of this article for better understanding.
Dear visitor. Click on "Follow" button from right side above and sign in with your Gmail account. Write unlimited comments on every post. 100% Free