#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Initialize the library with the numbers of the interface pins
#define A0 10 // Analog pin A0 for voltage measurement
// Define the voltage divider resistor values
const float R1 = 10000.0; // 10k Ohms
const float R2 = 5000.0; // 5k Ohms
void setup() {
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int rawValue = analogRead(A0); // Read the raw analog value from pin A0
float voltage = rawValue * (5.0 / 1023.0); // Convert the raw value to voltage (0-5V)
// Calculate the actual voltage using voltage divider
float actualVoltage = voltage * ((R1 + R2) / R2);
// Print the voltage on Serial monitor
Serial.print("Voltage = ");
Serial.print(actualVoltage);
Serial.println("V");
// Print the voltage on LCD
lcd.clear(); // Clear the LCD screen
lcd.setCursor(0, 0); // Set the cursor to the first column (0) and first row (0)
lcd.print("Voltage = ");
lcd.print(actualVoltage);
lcd.print("V");
delay(1000); // Delay for 1 second
}