/*
Simple Arduino DC Voltmeter with LCD (I2C)
┌──────────────┐
│ Arduino │
│ │
│ A0 ◄─────●───────┐
│ │ │
│ [R1] VIN (+)
│ 100kΩ │
│ │ │
│ ●─────[R2]───► GND
│ 10kΩ
│
│ SDA (A4) ─────────► LCD SDA
│ SCL (A5) ─────────► LCD SCL
│ 5V ─────────► LCD VCC
│ GND ─────────► LCD GND
└──────────────┘
- R1 = 100kΩ (top resistor, VIN to A0)
- R2 = 10kΩ (bottom resistor, A0 to GND)
- Voltage divider ratio = 11
- Max input voltage ≈ 55V
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int analogPin = A0;
const float Vref = 5.0;
const float R1 = 100000.0;
const float R2 = 10000.0;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
}
void loop() {
int raw = analogRead(analogPin);
float Vout = (raw * Vref) / 1023.0;
float Vin = Vout * ((R1 + R2) / R2);
if (Vin < 0.09) Vin = 0.0;
lcd.setCursor(0, 0);
lcd.print("Voltage: ");
lcd.print(Vin, 2);
lcd.print(" V");
delay(500);
}