If you are new to Arduino, you can get started with Arduino Tutorials for newbie.
How it worksWe can use Arduino analog input pin to measure voltage. However, the maximum measurable voltage is 5V.
To increase the measurable voltage, we need to use a voltage divisor
InTheory
We has:
V_measure = (R1 + R2) / R2 * V_in
ratio = (R1 + R2) / R2
=> V_measure = ratio * V_in
If we choose R1 = 10 * R2, we have:
V_measure = 11 * V_in
Since the maximum of the allowable V_in is 5V => The maximum of the measurable voltage is 55V
To limit the current run though Arduino's pin, which may cause damage to Arduino, we need to choose resistor value as big as possible.
I choose R1 = 1 Mohm, R2 = 100Kohm
In Practice
There is some problems in practice
- Value of R1 and R2 has errors. The errors cause the error of V_measure
- Power source of of Arduino may be unstable. It makes the V_REF of analog input is unstable. Therefore, it causes the error in calculation of V_in. => it causes error in calculation of V_measure
These problems are solved on the Calibration part
Calibration1. Measure the real value of (R1 + R2) / R2
This need to be done only one time to get the ratio
Wiring as bellow image:
ratio = (R1 + R2) / R2 = V_measure / V_in = A1_read_value / A0_read_value
ratio = A1_read_value / A0_read_value
Code for this calibration => see ResisterCalibration.ino in code part
2. Instability of power supply
Instability of power supply causes instability in voltage reference of analog pin. It causes the wrong measure in voltage calculation.
To solve it, we need to measure the voltage reference frequently.
How to measure the voltage reference?
Connect 3.3V to pin A1
The voltage reference is measured indirectly based on value in A1:
V_reference= 1023 * 3.3 / A1_value
How to calculate the V_measure:
V_in = mapFloat(A0_value, 0, 1023, 0, V_reference);V_measure = ratio * V_in;
Main wiring:
- Wiring as "resistor calibration wiring" circuit
- Upload ResistorCalibration.ino
- Open Serial Plotter
- Copy the ratio value
- Replace this value in line 5 of Voltmeter.ino
- Re-wiring as "main wiring"
- Upload Voltmeter.ino
- Upload Web User Interface (voltmeter.php and voltmeter_body.jpg) to PHPoC Shield
- Access Web page http://phpoc_shield_ip_address/voltmeter.php to see the voltage.
You can view the voltage on smart phone as follows:
Wiring Tips:
Comments