#include <OneWire.h>
#include <DallasTemperature.h>
#include<Wire.h>
#include <LiquidCrystal_I2C.h>
#define VOLTAGE_SENSOR_PIN A1 // Analog pin for the voltage sensor
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define ACS712_PIN A2 // Analog pin for the ACS712 sensor
#define ACS712_ADDRESS 0x40 // Address of the ACS712 sensor
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(VOLTAGE_SENSOR_PIN, INPUT);
pinMode(ACS712_PIN, INPUT);
sensors.begin();
delay(20);
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
// Current test
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
// Temperature Test
sensors.requestTemperatures();
float T = sensors.getTempCByIndex(0);
lcd.setCursor(5, 0);
lcd.print("EV batt Testing ");
lcd.setCursor(0, 1);
lcd.print("Batt_Vtg: ");
lcd.print(voltageBattery , 2);
lcd.print(" V");
Serial.print("Batt_Voltage: ");
Serial.print(voltageBattery , 2);
Serial.println(" V ");
lcd.setCursor(0, 2);
lcd.print("Current: ");
lcd.print(current, 2);
lcd.print(" A");
// Display current on Serial Monitor
Serial.print("Current: ");
Serial.print(current);
Serial.println(" A");
// lcd.setCursor(0, 3);
// lcd.print("Temp: ");
// lcd.print(T,2);
// lcd.print(" C");
Serial.print("Temperature: ");
Serial.print(T);
Serial.println("°C");
delay(1000);
}