Voltage Measurement Using Arduino
Voltage Measurement Using Arduino
by indoorgeek 54
47
Voltage Measurement using Arduino
STEP 1: Basics
First, we will see how to measure voltage with a maximum voltage of 5V. This is
very easy as no special modifications are required. To simulate the varying voltage,
we will use a potentiometer whose middle pin is connected to any one of the 6
channels. We will now write the code to read the values from ADC and convert
them back into useful voltage readings.
Reading the analog pin A0
value = analogRead(A0);
Now, the variable 'value' contains a value between 0 to 1023 depending upon the
voltage.
voltage = value * 5.0/1023;
The obtained value is now multiplied by the resolution (5/1023 = 4.9mV per unit)
to get the actual voltage.
And finally, display the measured voltage on the Serial monitor.
Serial.print("Voltage = ");
Serial.println(voltage);
But the problem arises when the voltage to be measured exceeds 5 volts. This can
be solved using a voltage divider circuit which consists of 2 resistors connected in
series as shown. One end of this series connection is connected to the voltage to
be measured (Vm) and the other end to the ground. A voltage (V1) proportional to
the measured voltage will appear at the junction of two resistors. This junction can
then be connected to the analog pin of the Arduino. The voltage can be found out
using this formula.
V1 = Vm * (R2/(R1+R2))
The voltage V1 is then measured by the Arduino.
Now to build this voltage divider, we first need to find out the values of resistors.
Follow these steps to calculate the value of resistors.
Determine the maximum voltage which is to be measured.
Decide a suitable and standard value for R1 in kilo-ohm range.
Using formula, calculate R2.
If the value of R2 is not (or close to) a standard value, change R1 and repeat
the above steps.
Since Arduino can handle a maximum of 5V, V1 = 5V.
For example, Let the maximum voltage (Vm) to be measured be 12V and R1 = 47
kilo-ohms. Then using the formula R2 comes out to be equal to 33k.
Now, Build a voltage divider circuit using these resistors.
With this setup, we now have an upper and lower limit. For Vm = 12V we get V1 =
5V and for Vm = 0V we get V1 = 0V. That is, for 0 to 12V at Vm, there will be a
proportional voltage from 0 to 5V at V1 which can then be fed into the Arduino as
before.
The commonly available Voltage Sensor Modules are nothing but just a voltage
divider circuit. These are rated for 0 to 25V with 30 kiloohm and 7.5 kilo-ohm
resistors.
So, Why to BUY, when you can DIY!
Thank you for sticking till the end. I hope that this tutorial would have helped you.
Subscribe to my YouTube channel for more upcoming projects and tutorials.
Thanks once again!
27 Comments
Chadman25 1 year ago
Hi,
Thank you for the tutorial. I tried this with 200K and 10K ohms for the Rs,
which gives me up to 110V as far I understand. when I connect a 9V
battery to test, it gets around 15V measured.
Any ideas? I don't have 200Kohm so I did: