#include <OneWire.h>
#include <DallasTemperature.h>
#include<Wire.h>
#include <LiquidCrystal_I2C.h>
#define VOLTAGE_SENSOR_PIN 36 // Analog pin for the voltage sensor
#define Solar_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
#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(Solar_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 overflowThreshold1 = 14.0; // Set your overflow threshold voltage here
float lowBatteryThreshold1 = 10.0; // Set your low battery threshold voltage here
float Battery = (12.0, 13.0); // Set your Normal battery voltage here
//lcd.setCursor(5, 0);
//lcd.print("EV batt Testing ");
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 SolarValueVoltage = analogRead(Solar_SENSOR_PIN);
// Convert the analog value to voltage (assuming 5V reference)
float voltageSolar = (SolarValueVoltage / 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 Solar = (12.0, 13.0); // Set your Normal battery voltage here
//lcd.setCursor(5, 0);
//lcd.print("EV batt Testing ");
lcd.setCursor(0, 1);
lcd.print("Solar_Vtg: ");
lcd.print(voltageSolar , 2);
lcd.print(" V");
Serial.print("Solar_Voltage: ");
Serial.print(voltageSolar , 2);
Serial.println(" V ");
// 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
lcd.setCursor(0, 2);
lcd.print("Current: ");
lcd.print(current, 3);
lcd.print(" A");
// Display current on Serial Monitor
Serial.print("Current: ");
Serial.print(current);
Serial.println(" A");
delay(1000);
// Temperature Test
sensors.requestTemperatures();
float T = sensors.getTempCByIndex(0);
Serial.print("Temperature is: ");
delay(10);
Serial.print(T);
Serial.println(" *C");
delay(1000);
lcd.setCursor(0, 3);
lcd.print("Temp: ");
lcd.print(T);
lcd.print("C");
Serial.print("Temperature: ");
Serial.print(T);
Serial.println("°C");
}