0-5V voltmeter using arduino.

This article is about a simple 3 digit voltmeter using arduino. The circuit can measure anything between 0 to 5V at an accuracy of 50mV. The circuit uses minimum number of external components and can be easily modified for different voltage ranges. The display device is a common anode multiplexed seven segment LED display module (Type No:E1-3056ASR1). Let’s have a look at the display device first.

E1-3056ASR1.

It is a low cost multiplexed 3 digit seven segment LED module of common anode type. Using such a multiplexed module instead of three separate display modules save a lot of wiring and effort. Such multiplexed modules of different configurations are now commonly available in the market. The figure below shows  pin out of the E1-3056ASR1 display module used here.

E1-3056ASR1 pinout

Read this article Voltmeter using  8051 for a better grasp. The idea is same  but instead of an 8051 microcontroller Arduino-uno is used here. Circuit diagram of the voltmeter using arduino is shown in the figure below.

Circuit diagram.

arduino voltmeterCommon anode terminals of each display are interfaced to the digital output pins 1, 2, 3 of the arduino respectively. Segments a to dotpoint of the display are interfaced to the digital output pins (5 to 12) of the arduino. The voltage to be measured is applied to the analog input pin A0 of the arduino. Arduino-Uno has six analog input channels named A0, A1, A2, A3, A4 and A5. The voltage in the range of 0 to 5V applied to each of the pin can be converted into a digital value in the range 0 to 1023 using “analogRead” function. That means the sensitivity of each internal ADC channel is 5/1023 which  is equal to 4.88mV. The program for  digital voltmeter using arduino is shown below.

Program.

int a;
int vin;
int input=A0;
int disp1=1;
int disp2=2;
int disp3=3;
int segA=5;
int segB=6;
int segC=7;
int segD=8;
int segE=9;
int segF=10;
int segG=11;
int segDP=12;
void setup()
{
pinMode(disp1, OUTPUT);
pinMode(disp2, OUTPUT);
pinMode(disp3, OUTPUT);
pinMode(segA, OUTPUT);
pinMode(segB, OUTPUT);
pinMode(segC, OUTPUT);
pinMode(segD, OUTPUT);
pinMode(segE, OUTPUT);
pinMode(segF, OUTPUT);
pinMode(segG, OUTPUT);
pinMode(segDP, OUTPUT);
pinMode(input,INPUT);
}
void loop()
{
vin=analogRead(input);
vin=vin/2.046;
a = vin%10;
if(a<=5)
{a=0;}
else
{a=5;}
digitalWrite(disp1,LOW);
digitalWrite(disp2,LOW);
digitalWrite(disp3, HIGH);
digitalWrite(segDP,HIGH);
display(a);
delay(5);
vin = vin/10;
a = vin%10;
digitalWrite(disp3,LOW);
digitalWrite(disp2,HIGH);
digitalWrite(segDP,HIGH);
display(a);
delay(5);
vin=vin/10;
a=vin;
digitalWrite(disp2,LOW);
digitalWrite(disp1,HIGH);
digitalWrite(segDP,LOW);
display(a);
delay(5);

}
int display (int a)
{
switch (a)
{
case 0:
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
break;

case 1:
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;

case 2:
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
break;

case 3:
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
break;

case 4:
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;

case 5:
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, HIGH);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;

case 6:
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;

case 7:
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
break;

case 8:
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;

case 9:
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, HIGH);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
break;
}}

About the program.

The analog voltage applied to analog input pin A0 is read using analogRead function. The digital equivalent on the analog input voltage is stored in variable vin. For example  if 2.5V is the analog input, then the data loaded into variable “vin” after analogRead will be 2.5V/4.8mV= 511. The digital value in variable “vin” is divided by2.056 in order to make a 0 t0 500 swing in the digital reading corresponding to the 0 to 5V swing in the input voltage. The variable “vin” is over written by the result of the division. The next job of the program is to display the number in the variable “vin”.

For that each digit in the variable “vin” is isolated and displayed on the appropriate segments. For example, if 256 is the number in “vin”, then 2 is displayed on display 1, 5 is displayed on display 2 and 6 is displayed on display 3. A small delay of around 5 mS is given in between switching of the segments. This is done continuously and the observer feels like 256 due to persistence of vision.  Decimal point of the first display is also kept activated while switching the first segment. The individual digits are isolated and displayed by the following method.

Suppose 256 is the number to be displayed. Firstly modulus of 256 is determined using “%” operator and the result will be 6. Then it is stored in variable “a”. The the variable “a” is checked using the if statement. If “a” is less than five then “a” is overwritten by 0 and if “a” is greater than 5 it is over written by 5. This reduces the sensitivity of the voltmeter but makes the third digit stable. Then the third display is switched ON and other displays are held OFF. Then the function “display” for displaying 6 is called. The result will be 6 displayed on the third display. Then a delay of 5 ms is called.

After this delay, 256 is divided by 10 and variable “vin” is overwritten by the quotient which is 25. Then the modulus of 25 is determined. The modulus of 25 is 5 and it is stored in variable a. The second display is activated and the other displays are deactivated. Then the function display is called again. The result will be 5 displayed on the second display. A delay of 5 mS is called again.

Then the number 25 in variable “vin” is divided by ten again. The quotient of the operation will be 2. This 2 is overwritten to variable “vin”. Then the variable “vin” is copied to variable a .The first display is activated and the other displays are deactivated. The decimal point of the first display is also activated. Then the display function is called again. The result will be the digit 2 displayed on the third display. A delay of 5 mS is called again and the entire cycle is repeated.

The function display is implemented using conditional branching based on “switch” and “break” statements. Whenever the “display” function is called it will output the segment drive pattern for the current digit in variable “a” on the digital output pins (5 to 12). This is done by checking the current digit in variable “a” and jumping to the appropriate case. Suppose 6 is the digit in variable “a”. Then the statement  “switch(a)” will make the program to jump to “case:6” which will result in writing the segment drive pattern of 6 on the digital output pins ( 5 to 12) appropriately.

LCD version of the arduino voltmeter.

This is just an LCD version of the voltmeter shown above. JHD162A is the LCD display used here. It is a 16×2 LCD display with back light. The circuit diagram of the LCD voltmeter using arduino is shown in the figure below.

Circuit diagram.
arduino voltmeter LCD displayProgram.
#include<LiquidCrystal.h>
int vin=A0;
float value;
LiquidCrystal lcd(12,11,5,4,3,2); //library initialization
void setup()
{
  pinMode(vin,INPUT);
  lcd.begin(16,2);
  lcd.setCursor(1,0);
  lcd.print("LCD VOLTMETER");
}
void loop()
{
value=analogRead(vin);
value=value/200;
value=value*0.978;
lcd.setCursor(3,1);
lcd.print(value);
lcd.print(" volts");
delay(300);
}
Author

11 Comments

  1. SARBJIT SINGH

    PLS DEVIDE BY 2.042 FOR ACCURATE READINGS

  2. Homemade Circutis

    Please tell me can we replace 7 segment with LCD?

  3. This looks very interesting, but HOW do you put the program into the “arduino” IC? I see no pins for inputing a program! Thanks.

  4. Shiharan

    Hi,

    Its always a good practice to include the pic connections as comments, in the beginning of the program.

  5. google.com

    It is really a nice and helpful piece of info.
    I am satisfied that you simply shared this helpful information with us.
    Please keep us up to date like this. Thanks for sharing.

  6. how can i increase the range of this voltmeter

  7. Yash Patil

    sir can you pls post on Quad Copter using arduino uno

    • praveen

      i am planning of it. But it will take some time.