Project

# Make a Digital Voltmeter Using an Arduino

June 04, 2015 by Tim Youngblood

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

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

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 connected 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 pin 9 of the Arduino and RS is connected to pin 8 of the Arduino. RW is connected to ground. The backlight 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

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);
}



Make_A_Digital_Voltmeter.zip

### 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 90.9 kohm resistor and a 10 kohm resistor to create a 10:1 divider. This will allow us to measure voltages up to 50 V.

#### Hardware Required

• 1x Arduino Mega2560
• 1x 90.9 kohm resistor
• 1x 10 kohm resistor
• 1x LCD (Liquid Crystal Display)
• 1x 5k potentiometer
• 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 90.9 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 by the ratio R2/(R1 + R2), which in this case is 10,000/(90,900 + 10,000) ≈ 0.1.

#### Code


#include "LiquidCrystal.h"

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

float input_voltage = 0.0;
float temp=0.0;
float r1=90900.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

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);
}



digital_voltmeter_with_arduino_1.ino.zip

#### Videos

Give this project a try for yourself! Get the BOM.

• S
sophiap August 23, 2015

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?

Like.
• Laszlo Lebrun October 03, 2015

“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.

Like.