Professional Documents
Culture Documents
In this lesson, we will use two potentiometers and an LCD1602 to make a voltmeter.
Components
- 2 * Potentiometer(50k)
- 1 * LCD1602
- 1 * Breadboard
Experimental Principle
One potentiometer is used to adjust the contrast of the LCD1602. And the other is used to
divide voltage. When you adjust the potentiometer connected to pin A0 of the SunFounder Uno
board, the resistance of the potentiometer will change and the voltage at pin A0 will change
accordingly. This voltage change is converted into digital values by A/D converter on the
SunFounder Uno board. We can see this change on the serial monitor. Then convert the digital
values into voltage with the following formula: the voltage equals the digital value divides by
1024 and then multiplies by 5.0. Finally, display the voltage on the LCD1602.
Experimental Procedures
#include <LiquidCrystal.h>
/****************************************************/
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 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