Voltage and current are two most important parameters of electricity. This project teaches you to build a simple volt-amp meter using avr microcontroller. This project may not enable you to build a high end measurement tool but will be a good diy project which gives a better understanding on A/D converter in microcontrollers. This meter is capable of measuring voltage ranging from 0 to 30V and current ranging from 0 to 5A. Care must be taken while using so that the input should not exceed the specifications.
SETTING UP THE SENSORS:
A simple potential divider is employed to measure the voltage. The above potential divider was set up in such a way it gives 5v as output when 30v input is applied to it since the input voltage given to AVR should be less than or equal to 5V.
The formula for setting the potential divider resistor is
Vout = Vin x R2 / (R1 + R2)
We knew our Vout should be <= 5V. So applying this and fixing a resistor R2 as 10k will give
5v = 30 x 10k /(R1 + 10k)
R1 = 50k.
We are using a pretty straight forward approach to measure current. Here we are using a Hall effect current sensor to measure current. This sensor can measure current up to 5A. 1A of current is equivalent to 185mv of change in output voltage. There are also 20A and 30A version of this chip available. Read more about this sensor here.
The next task is to perform the calibration to display the real values using our Microcontroller. So in order to do that we need to know the Step Size of our A/D converter in AVR microcontroller. It was given by the formula
Step size = Vref / 2^10 (Since it is a 10 bit ADC) .
= 5/1024 = 4.88mv
This is the step size of our A/D converter in AVR microcontroller that is for every 4.88mv change in input there will be a change in ADC value in the register.
TO CALCULATE VOLTAGE:
As i have previously mentioned the voltage sensing is done by using a Voltage divider which bears the formula
Vout = Vin x R2 / (R1 + R2)
Am going to use this formula to derive the real voltage from the sensed voltage. Since we obtain the sensed voltage in the form of digital numbers we need to make a conversion to obtain Vout value from it. So
Vout = Digital Value read from A/D register * Vref / 2^10
Vout = Digital Value read from A/D register * 5 / 1024 , Simplifying this we get
Vout = Digital Value * 0.00488
This will give us exact Vout voltage from the voltage divider, now applying this Vout in the divider equation will give the real voltage given as input to the voltage divider.
Vin= Vout * (R1+R2) /R2
Vin = Vout * 60k / 10K
Vin = Vout * 6
The above final equation i have added in the 41 line of the code, This will give the real voltage that needs to be measured and displayed.
Read More: Volt-Amp meter using AVR microcontroller