#include<Wire.h>
#include <LiquidCrystal_I2C.h>
#define VOLTAGE_SENSOR_PIN 39 // Analog pin for the voltage sensor
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define ACS712_PIN 34 // Analog pin for the ACS712 sensor
#define ACS712_ADDRESS 0x40 // Address of the ACS712 sensor
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(VOLTAGE_SENSOR_PIN, INPUT);
pinMode(ACS712_PIN, INPUT);
lcd.init();
// Turn on the LCD backlight
lcd.backlight();
// Put text on the LCD
// lcd.print("EV Batt Test");
}
void loop()
{
// put your main code here, to run repeatedly:
int sensorValueVoltage = analogRead(VOLTAGE_SENSOR_PIN);
// Convert the analog value to voltage (assuming 5V reference)
float voltageBattery = (sensorValueVoltage / 1023.0) * 5.0;
float overflowThreshold = 14.0; // Set your overflow threshold voltage here
float lowBatteryThreshold = 10.0; // Set your low battery threshold voltage here
float Battery = (12.0, 13.0); // Set your Normal battery voltage here
lcd.setCursor(0, 0);
lcd.print("Batt_Vtg: ");
lcd.print(voltageBattery , 2);
lcd.print(" V");
Serial.print("Batt_Voltage: ");
Serial.print(voltageBattery , 2);
Serial.println(" V ");
int sensorValueACS = analogRead(ACS712_PIN);
// Convert the analog value to voltage
float voltageCurrent = sensorValueACS * (5.0 / 1023.0);
// Convert voltage to current using the ACS712 sensitivity (100mV/A)
float current = voltageCurrent / 0.1; // 100mV per A
lcd.setCursor(0, 1);
lcd.print("Current: ");
lcd.print(current, 2);
lcd.print(" A");
// Display current on Serial Monitor
Serial.print("Current: ");
Serial.print(current);
Serial.println(" A");
delay(1000);
}