#include <LiquidCrystal_I2C.h> // Include LCD library
/* ========== SENSOR PINS ========== */
#define CURRENT_PIN 34 // ACS712
#define VOLTAGE_PIN 35 // ZMPT101B
/* ========== CALIBRATION VALUES ========== */
float currentSensitivity = 0.185; // ACS712 5A = 185mV/A
float voltageCalibration = 250.0; // Max 250V (simulation)
/* ========== THRESHOLD VALUES ========== */
float currentThresholdLow = 0.5; // Low current threshold (in Amps)
float currentThresholdHigh = 5.0; // High current threshold (in Amps)
float voltageThresholdLow = 100.0; // Low voltage threshold (in Volts)
float voltageThresholdHigh = 240; // High voltage threshold (in Volts)
/* ========== LCD SETTINGS ========== */
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change address and size as needed
void setup() {
// Start Serial Monitor for debugging
Serial.begin(115200);
// Initialize LCD
lcd.begin();
lcd.backlight();
// Print a startup message
lcd.setCursor(0, 0);
lcd.print("System Started");
delay(1000);
lcd.clear();
}
void loop() {
// Read current and voltage
float current = readCurrent();
float voltage = readVoltage();
// Display values on LCD
lcd.setCursor(0, 0);
lcd.print("Current: " + String(current) + " A");
lcd.setCursor(0, 1);
lcd.print("Voltage: " + String(voltage) + " V");
// Send data to Wokwi or handle threshold events
if (current > currentThresholdHigh || voltage > voltageThresholdHigh) {
// Example of threshold exceeded action
lcd.setCursor(0, 1);
lcd.print("Threshold Exceeded!");
}
// Delay for readability
delay(1000);
}
float readCurrent() {
int rawCurrent = analogRead(CURRENT_PIN);
float voltageCurrent = (rawCurrent * 3.3) / 4095.0; // Convert ADC value to voltage
return (voltageCurrent - 2.5) / currentSensitivity; // Convert voltage to current
}
float readVoltage() {
int rawVoltage = analogRead(VOLTAGE_PIN);
float voltageSensor = (rawVoltage * 3.3) / 4095.0; // Convert ADC value to voltage
return voltageSensor * voltageCalibration; // Convert to actual voltage
}