#include <LiquidCrystal.h>
const int analogInPin = A0; // Analog input pin for current measurement
const float R1 = 1000.0; // Resistance value of R1 in ohms
const float R2 = 1000.0; // Resistance value of R2 in ohms
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Initialize the library with the numbers of the interface pins
void setup() {
//Serial.begin(9600); // Initialize serial communication
lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
lcd.print("Current:"); // Print initial message on LCD
}
void loop() {
// Read the analog input
int sensorValue = analogRead(analogInPin);
// Convert analog reading to voltage
float voltage = sensorValue * (5.0 / 1023.0); // Assuming 5V reference
// Calculate current using voltage divider formula
float current = voltage / ((R1 + R2) / R2); // I = V / (R1 + R2)
// Print current value to serial monitor
//Serial.print("Current: ");
//Serial.print(current, 3); // Print with 3 decimal places
//Serial.println(" A");
// Print current value to LCD
lcd.setCursor(0, 1); // Set cursor to column 0, row 1 (second row)
lcd.print(" "); // Clear the previous reading
lcd.setCursor(0, 1); // Reset cursor to column 0, row 1
lcd.print(current, 3); // Print current value with 3 decimal places
delay(1000); // Delay for readability
}