#include <LiquidCrystal.h>
#include <LiquidCrystal.h>
#include <DFRobot_DHT11.h>
// Initialize LCD
const int rs =4, en =5, d4 =6, d5 =7, d6 =8, d7=9;
LiquidCrystal lcd(4, 5, 6, 7, 8, 9);
// Define LDR and LED pin
int LEDV = 1;//RED
int LEDT = 2;//YELLOW
int dht11=A1;
const int Battery_voltage = A0;//
int fan_Ctrl = 26;//connect fan
int AC_POWER_F = 27;
int HIGH_DC = 28;
int CHARGER_FAIL = 29;
int fan_LED =13 ;//connect fan
int AC_POWER_LED = 10;
int HIGH_DC_LED = 11;
int CHARGER_LED= 12;
// Define threshold value
const int Threshold_V = 3 ; // declare in VOLTAGE
const int thermometerPin = A1;//represented by a potentiomete
int battery_voltage_raw = 0;//raw value measered in zero
void setup() {
int Battery_Voltage = analogRead(Battery_voltage);//read themometer
int mappedValeu = map(Battery_Voltage,0,1023,0,9);//EQUATE VOLTEGE TO POTENTIOMETER ADJUSTMENT
// Define LDR and LED pin
int LEDT = 10;
int LEDV = 2;
// Define threshold value
const int Threshold_T = 813 ; // declare in maximum temperature(kelvins)
const int Threshold_V = 2.5 ;// DECLCRE MIN VOLTAGE
// Set up the LCD
Serial.begin(9600);
lcd.begin(20, 4);
lcd.clear();
// Set LED pin as output
pinMode(A0, INPUT);
pinMode(2, OUTPUT);//low charge
pinMode(A1,INPUT);
pinMode(3, OUTPUT);//high temprature
pinMode(LEDT,OUTPUT);
//set alarm inputs
pinMode(fan_Ctrl,INPUT);
pinMode(AC_POWER_F,INPUT);
pinMode(HIGH_DC,INPUT);
pinMode(CHARGER_FAIL,INPUT);
//set alarm LED outputs
pinMode(fan_LED,OUTPUT);
pinMode(AC_POWER_LED, OUTPUT);
pinMode(HIGH_DC_LED,OUTPUT);
pinMode(CHARGER_LED,OUTPUT);
dht11.begin();
float tempC = dht11.readTemperature();
// Print initial messages on LCd
int tempValue = analogRead(thermometerPin);//read themometer
int mappedtemp = map(tempValue,0,1023,0,900);
// Set up the LCD
Serial.begin(9600);
lcd.begin(20, 4);
lcd.clear();
// Set LED pin as output
pinMode(A1, INPUT);
pinMode(10, OUTPUT);
pinMode(A0, INPUT);
// Print initial messages on LCD
lcd.setCursor(0, 0);
lcd.print("Battery_Volt:");
lcd.setCursor(0, 1);
lcd.print("");
lcd.setCursor(0, 1);
lcd.print("Threshold(c): 813");
lcd.setCursor(0, 2);
lcd.print("ThermoMeter(c): "); //set value read by thermometr @ line 3
lcd.setCursor(8,3);
lcd.setCursor(0, 3);
lcd.print("SYSTEM:");//set stystem reort @ line 4
}
void loop() {
// Read the LDR value
int Battery_voltage_raw = 0;//raw value measered in zero
int Battery_Voltage= analogRead(A0);//read themometer
int Battery = analogRead(Battery_Voltage);
Battery_voltage_raw = analogRead(Battery_voltage);
Battery = (Battery_voltage_raw *11)/1023;
// Define threshold value
const int Threshold_T = 813 ; // declare in maximum temperature(kelvins)
const int Threshold_V = 3 ;// DECLCRE MIN VOLTAGE
int mappedValue = map(Battery_Voltage,0,1023,0,9);//EQUATE VOLTEGE TO POTENTIOMETER ADJUSTMENT
lcd.setCursor(15,0);
lcd.print(mappedValue);
// Display VOLTAGE value on LCD
lcd.setCursor(0,17);
lcd.print(A0);
// Display LDR value on LCD
// Check if battery voltage falls below threshold
if (Battery_Voltage > Threshold_V) {
// Turn on LED
digitalWrite(LEDV, HIGH);
lcd.setCursor(0, 3);
lcd.print("Battery_LOW");
} else {
// Turn off LED
digitalWrite(LEDV, LOW);
}
delay(500); // Adjust delay time as needed
//read the temparature in kelvins
// Read the LDR value
int temp = DHT.read11(outpin);
float t = DHT.temperature;
lcd.setCursor(2,14);
lcd.print(t);
lcd.print("c |");
serial.pritn((T*9.0)/5.0+32.0);
// Check if tempurature is above threshold
if (tempValue > Threshold_T) {
// Turn on LED
digitalWrite(LEDT, HIGH);
digitalWrite(fan_Ctrl,HIGH);
lcd.setCursor(7, 4);
lcd.print("OVERHEAT");
} else {
// Turn off LED
digitalWrite(LEDT, LOW);
}
//TRIGGERING AC ALARM WITH A DIP SWITCH
digitalWrite(10, LOW);
digitalRead(AC_POWER_F);
digitalRead(fan_Ctrl);
digitalRead(HIGH_DC);
digitalRead(CHARGER_FAIL);
//triggering ac power failure
if (digitalRead(AC_POWER_F) == HIGH){
digitalWrite(AC_POWER_LED, HIGH);
lcd.setCursor(7, 4);
lcd.print("AC POWER FAIL");}
else {
digitalWrite(AC_POWER_LED,LOW);
}
//triggering fan led alarm with a dip switch
if (digitalRead(fan_Ctrl) == HIGH){
digitalWrite(fan_LED, HIGH);
lcd.setCursor(7,4);
lcd.print("fan");}
else{
digitalWrite(fan_LED,LOW);}
//TRIGGERING HIGH DC POWER ALARM
if (digitalRead(HIGH_DC) == HIGH){
digitalWrite(HIGH_DC_LED, HIGH);
lcd.setCursor(7, 4);
lcd.print("HIGH.DC");}
else {
digitalWrite(HIGH_DC_LED,LOW);
}
//triggering charger fail
if ( digitalRead(CHARGER_FAIL) == HIGH){
digitalWrite(CHARGER_LED, HIGH);
lcd.setCursor(7, 4);
lcd.print("charger_f");}
else{
digitalWrite(CHARGER_LED,LOW);
}
}
//LINK REFERENCE https://www.youtube.com/watch?v=gNEYa1qNdX8