Reading voltage with Arduino is easy. You’ll need only a potentiometer to adjust the resistance. Despite being easy, this project is great for kids because it explains the basics of the 5V logic of electronics. The components you need are a breadboard, an Arduino Uno R3, a potentiometer and two jumpers.
With digital input, 5V is perceived as HIGH and 0V as LOW. But, electricity does not only have two values 5V and 0V, but they can also be more. The microcontrollers can not understand the values such as 12.23456 V. For that reason, we need the analogue values to be converted to digital values. This methodology is done by hardware named analogue to digital converter. Arduino UNO already has an analog-to-digital converter (ADC).
The analogue to digital converter (ADC) divides the voltage into several equal parts. For Arduino Uno, 0-5V values are divided into 1023 equal parts. So, for a 3V input, for example, 614 will be the closest digital value. So the equation to calculate an unknown voltage will be:
Digital reading * (5.0 / 1023.0)
The potentiometer has three legs. The middle leg is required to be connected to the A0 pin of Arduino. The left pin and right pin are required to be connected to pay load (Arduino’s 5V for calibration or testing) and GND (required to be made common with Arduino’s GND). This is the sketch:
const int VOL_PIN = A0;
Serial.begin( 9600 );
value = analogRead( VOL_PIN );
volt = value * 5.0 / 1023.0;
Serial.print( "Value: " );
Serial.print( value );
Serial.print( " Volt: " );
Serial.println( volt );
delay( 500 );
Now, when you open your Serial Monitor in the Arduino IDE. You should see a steady stream of numbers ranging from 0.0 – 5.0. As you turn the potentiometer, the values will change.