#include <LiquidCrystal_I2C.h>
// Set the I2C address and LCD dimensions (16x2)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define the potentiometer pin
const int potPin = A0;
void setup() {
// Initialize the LCD and turn on the backlight
lcd.init();
lcd.backlight();
// Print a welcome message
lcd.setCursor(0, 0);
lcd.print("ADC1: ");
}
void loop() {
// Read the value from the potentiometer (0 to 1023)
int potValue = analogRead(potPin);
// Calculate the corresponding voltage (assuming a 5V system)
float voltage = potValue * (5.0 / 1023.0);
// Convert the potentiometer value to a percentage (0 to 100)
int percentage = map(potValue, 0, 1023, 0, 100);
// Display the ADC value, voltage, and percentage on the LCD
lcd.setCursor(0, 0); // Set cursor to the first line
lcd.print("ADC1: ");
lcd.print(potValue);
lcd.setCursor(0, 1); // Set cursor to the second line
lcd.print("V: ");
lcd.print(voltage, 2); // Display voltage with 2 decimal places
lcd.print("V ");
lcd.print(percentage);
lcd.print("% "); // Adding spaces to clear previous text
// Small delay to avoid flickering
delay(500);
}