#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int analogInput = A1;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0;
float R2 = 10000.0;
int value = 0;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("DC VOLTMETER");
}
void loop() {
value = analogRead(analogInput);
vout = (value * 5.0) / 1024.0;
vin = vout / (R2 / (R1 + R2));
if (vin < 0.01) vin = 0.0;
Serial.print("Vout (A1 Pin): ");
Serial.print(vout, 2);
Serial.print("V | Vin (Calculated): ");
Serial.print(vin, 2);
Serial.println("V");
lcd.setCursor(0, 1);
lcd.print("INPUT V= ");
lcd.print(vin, 2);
lcd.print(" ");
delay(500);
}