## Introduction: How to Make a 5V Voltmeter With Arduino

Is there a moment when you want to test the voltage of the device or some point in the circuit, but you don’t have a voltmeter or multimeter at hand? Rushing out to buy? That's a long way and long time… Before you do that, how about MAKING one yourself? With just simple components, you can try to build one really. Let's check how!

## Step 1: Prepare the Components

SunFounder Uno/Mars board - http://bit.ly/2tkaMba

USB data cable

2 x Potentiometer (50k)

LCD1602 - http://bit.ly/2ubNEfi

Several jumper wires

## Step 2: Wire LCD1602 and SunFounder Uno

Before wiring, let's first get to understand how it works. Here

use the SunFounder Uno board for the major data processing part of the voltmeter, the LCD1602 as screen display, a potentiometer to adjust the contrast of the LCD and another one to divide the voltage. When you spin the pot connected to the Uno board, the resistor of the pot changes, thus changing the voltage on it. The voltage signal will be sent to the Uno board via pin A0, and Uno will convert the analog signal received into digital and write it to the LCD. Thus you can see the voltage value at the current pot resistance.

LCD1602 has two operation modes: 4-bit and 8-bit. When the IOs of the MCU are insufficient, you can choose the 4-bit mode, under which only pins D4~D7 are used.

## Step 3: Wiring

Now follow the tablet to wire the two.

## Step 4: Connect the Potentiometer to LCD1602

Connect the middle pin of the pot to pin Vo of the LCD1602, and either of the rest pins to GND.

## Step 5: Wire Another Pot to Uno A0

Connect the middle pin of the pot to pin A0 of the SunFounder Uno, and one of the rest to 5V when the other to GND.

## Step 6: Upload the Code

Here is the code:

```#include
/****************************************************/const int analogIn = A0;//potentiometer attach to
A0LiquidCrystal lcd(4, 6, 10, 11, 12,
13);//lcd(RS,E,D4,D5,D6.D7)float val = 0;// define the variable as value=0/****************************************************/void setup(){
Serial.begin(9600);//Initialize the serial
lcd.begin(16, 2);// set the position of the characters on the LCD as
Line 2, Column 16
lcd.print("Voltage Value:");//print "Voltage Value:"}/****************************************************/void loop(){  val =
val/1024*5.0;// Convert the data to the corresponding voltage value in a math
way
Serial.print(val);//Print the number of val on the serial monitor
Serial.print("V"); // print the unit as V, short for voltage
on the serial monitor
lcd.setCursor(6,1);//Place the cursor at Line 1, Column 6. From here the
characters are to be displayed
lcd.print(val);//Print the number of val on the LCD
lcd.print("V");//Then print the unit as V, short for voltage
on the LCD
delay(200); //Wait for 200ms}```

## Step 7: Spin the Pot to Check Its Voltage on LCD1602 in Real Time

Here's a tricky thing. After I run the code, characters did appear on the LCD1602. Then adjust the contrast of the screen (the gradual change from black to white) by spinning the potentiometer clockwise or anticlockwise, until the screen displays characters clearly.

## Step 8: Measure the Voltage of a Battery!

Take two batteries here to measure their voltages: 1.5V and 3.7V. Unhook the second pot's connection to pin A0 and GND, meaning removing the pot from the circuit. Pinch the wire end of A0 to anode of the battery and circuit GND to cathode. DO NOT connect them inversely, or a short circuit will happen to the battery. The value is 0V is inverse connection happens.

So, the voltage of the battery is shown on the LCD now. There may be some gap between the value and the rated one since the battery is not fully charged. And that's why I need to measure, because I want to use the battery and not sure whether it's powerful enough. In this way, all problems tackled.

P.S.: Refer to this FAQ for LCD not display problems: http://wiki.sunfounder.cc/index.php?title=LCD1602/I2C_LCD1602_FAQ

robertbu (author)2017-07-24

input voltage which is not necessarily 5.0v. You can get around this
problem (with some loss of precision) by using Arduino’s built-in voltage
reference

SunFounder Maker (author)2017-07-26

Thanks for your kind suggestion! In this experiment, it's our mistake to have no consideration on over-voltage protection. The readings is relative to the input voltage. The 5V we mentioned is not only a 5V voltage detecting, but the voltage range.