#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int pump = 2;
int temp_sensor = 6;
// Pass our oneWire reference to Dallas Temperature sensor
OneWire oneWirePin(temp_sensor);
DallasTemperature sensors(&oneWirePin);
float temperature = 0;
int higherLimit = 35;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.clear();
pinMode(pump, OUTPUT);
lcd.setCursor(0, 0);
lcd.print("ROOF COOLING");
lcd.setCursor(0, 1);
lcd.print("SYSTEM IS ON ");
delay(2000);
sensors.begin();
}
void loop() {
int value = analogRead(A0);
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
temperature = sensors.getTempCByIndex(0);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("ROOF TEMP: ");
lcd.print(temperature);
lcd.setCursor(0, 1);
lcd.print("W LEVEL :");
Serial.println(value);
if (value == 0) {
lcd.print("EMPTY ");
} else if (value > 1 && value < 350) {
lcd.print("LOW ");
} else if (value > 350 && value < 510) {
lcd.print("MEDIUM");
} else if (value > 510){
lcd.print("HIGH ");
}
if (temperature >= higherLimit) {
digitalWrite(pump, HIGH);
}
else {
digitalWrite(pump, LOW);
}
}