It's easy to make a simple digital voltmeter using an Arduino and 16x2 liquid crystal display (LCD).

It's relatively simple to use an Arduino to measure voltages. The Arduino has several analog input pins that connect to an analog-to-digital converter (ADC) inside the Arduino. The Arduino ADC is a ten-bit converter, meaning that the output value will range from 0 to 1023. We will obtain this value by using the analogRead() function. If you know the reference voltage--in this case we will use 5 V--you can easily calculate the voltage present at the analog input. 

To display the measured voltage, we will use a liquid crystal display (LCD) that has two lines of 16 characters. LCDs are widely used to display data by devices such as calculators, microwave ovens, and many other electrical appliances.

This project will also show you how to measure voltages above the reference voltage by using a voltage divider. 


Experiment 1

In this experiment, we will make digital voltmeter capable of measuring up to 5V using an Arduino board and a 16x2 LCD. 


Hardware Required

  • 1 x Arduino Mega2560
  • 1x LCD (Liquid Crystal Display)
  • 1x 5 kohm potentiometer
  • 1x breadboard
  • female connectors
  • jumper wires


Wiring Diagram 

The 16x2 LCD used in this experiment has a total of 16 pins. As shown in the table below, eight of the pins are data lines (pins 7-14), two are for power and ground (pins 1 and 16), three are used to control the operation of LCD (pins 4-6), and one is used to adjust the LCD screen brightness (pin 3). The remaining two pins (15 and 16) power the backlight.

Terminal 1GND
Terminal 2+5V
Terminal 3Mid terminal of Potentiometer (for brightness control)
Terminal 4Resistor Select (RS)
Terminal 5Read/Write (RW)
Terminal 6Enable(EN)
Terminal 7DB0
Terminal 8DB1
Terminal 9DB2
Terminal 10DB3
Terminal 11DB4
Terminal 12DB5
Terminal 13DB6
Terminal 14DB7
Terminal 15+4.2-5V
Terminal 16GND

 

Refer to the diagram below to see how to connect the LCD to the Arduino. Note that the potentiometer is connected to the 5V source and GND and the middle terminal is connecto to pin 3 of LCD. Rotating this pot changes the brightness of the LCD. The four data pins DB4-DB7 are connected to the Arduino pins 4-7. Enable is connected to the pin 9 of Arduino and RS is connected to the pin 8 of Arduino where, RW is connected to ground. The back light LED is connected to 5V and ground. The following table shows the pin connections:

DB4 ----->pin4

DB5 ----->pin5

DB6 ----->pin6

DB7 ----->pin7

RS   ----->pin8

EN   ----->pin9



Code

The program below uses the LiquidCrystal library. This library contains all of the functions needed to write to the LCD.

The loop reads the analog value from the the analog input, and because the reference voltage is 5 V, it multiples that value by 5, then divides by 1024 to calculate the actual voltage value. Once the voltage has been calculated, the value is written to the LCD. 

The photo below shows a typical display.

                    #include "LiquidCrystal.h"

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

float input_voltage = 0.0;
float temp=0.0;


void setup()
{
   Serial.begin(9600);     //  opens serial port, sets data rate to 9600 bps
   lcd.begin(16, 2);       //// set up the LCD's number of columns and rows: 
   lcd.print("DIGITAL VOLTMETER");
}
void loop()
{

//Conversion formula for voltage
   
   int analog_value = analogRead(A0);
   input_voltage = (analog_value * 5.0) / 1024.0; 

   
   if (input_voltage < 0.1) 
   {
     input_voltage=0.0;
   } 
    Serial.print("v= ");
    Serial.println(input_voltage);
    lcd.setCursor(0, 1);
    lcd.print("Voltage= ");
    lcd.print(input_voltage);
    delay(300);
}
                  

  Download Code  


Experiment 2

In order to measure voltages greater than the 5 V reference voltage, you need to  divide the input voltage so that the voltage actually input to the Arduino is 5 V or less. in this experiment, we will use a 100 kohm and a 10 kohm resistor to create a 10:1 divider. This will allow us to measure voltages up to 50 V.


Hardware Required

  • 1 x Arduino Mega2560
  • 1x 100k ohm resistor
  • 1x 10k ohm resistor
  • 1x LCD (Liquid Crystal Display)
  • 1x 5k Potentiometer
  • 1x breadboard
  • female connector
  • jumper wires


Wiring Diagram

The circuit for this experiment is exactly the same as Experiment #1, except that we now have a voltage divider, made up of a 100 kohm resistor and a 10 kohm resistor connected to the input. See the diagram below.

Program

The program for this experiment is nearly the same as for Experiment #1. The only difference is that now we have to divide the calculated voltage value by the ratio R1/R2, which in this case is 10,000/1,000 or 10.


Code

                    #include "LiquidCrystal.h"

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

float input_voltage = 0.0;
float temp=0.0;
float r1=100000.0;
float r2=10000.0;


void setup()
{
   Serial.begin(9600);     //  opens serial port, sets data rate to 9600 bps
   lcd.begin(16, 2);       //// set up the LCD's number of columns and rows: 
   lcd.print("DIGITAL VOLTMETER");
}
void loop()
{
   
//Conversion formula

   int analog_value = analogRead(A0);
    temp = (analog_value * 5.0) / 1024.0; 
   input_voltage = temp / (r2/(r1+r2));
   
   if (input_voltage < 0.1) 
   {
     input_voltage=0.0;
   } 
    Serial.print("v= ");
    Serial.println(input_voltage);
    lcd.setCursor(0, 1);
    lcd.print("Voltage= ");
    lcd.print(input_voltage);
    delay(300);
}
                  

  Download Code  


Videos



Tags:

 

Comments

4 Comments


  • sophiap 2015-08-23

    I am currently doing this project and am currently confused. What the video shows doesn’t match up to the given diagram. The LCD is connected to the breadboard, how was this done?

  • Laszlo Lebrun 2015-10-03

    “in this experiment, we will use a 100 kohm and a 10 kohm resistor to create a 10:1 divider.”
    Sorry: Your voltage divider formula isn’t correct.
    The correct formula is R1+R2/R2

    You should use a 90,9KΩ and a 10,0KΩ resistor pair.

  • SeSandoval 2016-03-31

    I just burn 3 POTS. Is it right the second diagram?.

  • magicChristian 2016-11-21

    The ATMEGA internal ADC has 3 valuable possibilies for this project:
    first it has in internal reference of 2.56 V and this makes your meter not depending on the 5 V supply.
    second it allows for differntial ADC conversion which allows for measuring also negativ voltages
    third it has a build in amplifier x10 which could be used for low voltages.
    For voltages higher than the reference voltage you can use any voltage divider, with R2 being 10 kohm (because this is best for the internal ADC). The reading is the multiplication of ADC result by a cal constant, which have to fixed of a one time calibration with a second voltage meter.
    I would recomend a capacitor on the input of ADC to filter AC voltages to achieve more stable readings.