You are on page 1of 2

Lesson 6.

Making a Voltmeter with LCD Display


Components #include <Wire.h>
1 Arduino Uno board #include <LiquidCrystal_I2C.h>
1 USB data cable LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to
Several jumper wires 0x27 for a 16 chars and 2 line display
12 x 2 I2C LCD Display
float vol = 0;
int input = 0;

void setup() {
lcd.begin();
lcd.backlight();
lcd.setCursor(1, 0);
lcd.clear();
lcd.print("Arduino");
lcd.setCursor(0, 1);
lcd.print("Voltmeter");
delay(1500);
lcd.clear();
lcd.print("By - The ");
lcd.setCursor(0, 1);
lcd.print("IoT Projects");
delay(2000);
lcd.clear();
pinMode(A0, INPUT);
Serial.begin(9600); // starting the Serial Monitor
}
void loop() {
input = analogRead(A0); //analogRead function is used to
recive analog data
vol = (input * 9.0) / 1024.0; //formula using for perform action
lcd.print("voltage is:");
lcd.setCursor(0, 1);
delay(100);
lcd.print(vol);

delay(1000);
lcd.clear();
}Lesson 6. Making a Voltmeter with Serial Monitor float r1 = 1000000; //1000 kOhm resistor [change this if used a
different resistor value]
float r2 = 100000; //10 kOhm resister [change this if used a
Components different resistor value]<br>
1 Arduino Uno board
1 USB data cable void setup() {
Several jumper wires Serial.begin(9600); //speed = 9600
1 resistor ( 1K Ω)
1 resistor (10 K Ω) // Send ANSI terminal codes
Serial.print("\x1B");
Serial.print("[2J");
Serial.print("\x1B");
Serial.println("[H");
// End ANSI terminal codes

Serial.println("--------------------");
Serial.println("DC VOLTMETER");
Serial.print("Maximum Voltage: ");
Serial.print((int)(vPow / (r2 / (r1 + r2))));
Serial.println("V");
Serial.println("--------------------");
Serial.println("");

delay(2000); //wait 2000 ms before starting


}

void loop() {
float v = (analogRead(0) * vPow) / 1024.0; //when reading
analog values, divide by 1024
float v2 = v / (r2 / (r1 + r2));

// Send ANSI terminal codes


Serial.print("\x1B");
/** // End ANSI terminal codesr</p><p> Serial.print("Voltage
Copy the following code into the Arduino IDE. Compile and run it. (Volts) = ");
**/ Serial.println(v2);
float vPow = 4.7; //amount of power supple into arduino. Should
be 5V, but through USB cable usually less than 5 }

You might also like