#include <LiquidCrystal.h>
LiquidCrystal lcd(18, 17, 16, 15, 19, 23); // Set the pins used for the LCD
const int voltagePin = 4; // Analog pin connected to the voltage divider output
void setup() {
// Initialize the LCD with 16 columns and 2 rows
lcd.begin(16, 2);
// Set the voltagePin as an input (for reading the analog voltage)
pinMode(voltagePin, INPUT);
Serial.begin(115200);
}
void loop() {
// Read the analog voltage from the voltage divider
int sensorValue = analogRead(voltagePin);
Serial.print("Sensor Value: ");
Serial.println(sensorValue);
// Convert the analog value to voltage (0-50V range)
float voltage = (sensorValue / 1023.0) * 50.0;
Serial.print("Voltage: ");
Serial.print(voltage, 1);
Serial.println(" V");
// Display the voltage on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Voltage: ");
lcd.print(voltage, 1);
lcd.print(" V");
delay(1000);
}