How to Make a 5V Voltmeter With Arduino

by SunFounder Maker in Circuits > Arduino

9680 Views, 21 Favorites, 0 Comments

How to Make a 5V Voltmeter With Arduino

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!

Prepare the Components

1.jpg

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

USB data cable

2 x Potentiometer (50k)

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

Breadboard - http://bit.ly/2slvfrB

Several jumper wires

Wire LCD1602 and SunFounder Uno

2 副本.JPG
3.jpg

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.

Wiring

4.jpg

Now follow the tablet to wire the two.

Connect the Potentiometer to LCD1602

5.jpg

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

Wire Another Pot to Uno A0

6 副本.jpg

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.

Upload the Code

Here is the code:

#include

/****************************************************/

const int analogIn = A0;//potentiometer attach to A0

LiquidCrystal 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 = analogRead(A0);//Read the value of the potentiometer to val

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

}

Spin the Pot to Check Its Voltage on LCD1602 in Real Time

7.jpg

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.

Measure the Voltage of a Battery!

8.jpg
9.jpg
10.jpg

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