#include <LiquidCrystal.h> // include standard LCD library
// Define LCD pin connections
LiquidCrystal lcd(12, 11, 10, 9, 8, 7); // RS, E, D4, D5, D6, D7
// Analog pins for simulating voltage and current
const int potPin1 = A0; // Pin A0 for voltage
const int potPin2 = A1; // Pin A1 for current
// Declare variables for the analog readings
int pot1Value, pot2Value = 0;
float pot1Voltage = 0.00;
float pot2Current = 0.00;
float Power = 0.00;
float Energy = 0.00;
float IncrementalPower = 0.00;
void setup() {
Serial.begin(9600); // Initialize serial communication
lcd.begin(16, 2); // Initialize the LCD
}
void loop() {
// Read the analog values from the potentiometers
pot1Value = analogRead(potPin1);
pot2Value = analogRead(potPin2);
// Convert the analog reading to voltage (range 0-5V instead of 0-3.3V)
pot1Voltage = (5.0 * pot1Value) / 1023.0;
pot2Current = (5.0 * pot2Value) / 1023.0; // Assuming current sensor scales similarly
// Calculate power
Power = pot1Voltage * pot2Current;
IncrementalPower += Power;
Energy = IncrementalPower / 3600;
// Print the values to the serial monitor
Serial.println((String)pot1Value + ", " + (String)pot2Value);
Serial.println((String)pot1Voltage + "V, " + (String)pot2Current + "A");
Serial.println(String(pot1Voltage, 3) + "V, " + String(pot2Current, 3) + "A");
Serial.println((String)Power + "W");
Serial.println(String(IncrementalPower, 3) + " Wh");
Serial.println((String)Energy + "Wh");
// Display values on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(pot1Voltage, 3); lcd.print("V "); lcd.print(pot2Current, 3); lcd.print("A");
lcd.setCursor(0, 1);
lcd.print(Power, 3); lcd.print("W");
// Wait for a second before the next loop
delay(1000);
}