Hello I have created a incubator with Arduino uno, lcd1602 and DHt11.
My Arduino freeze after some days or hours, I have test with many power supply but no result.
This is the code:
#include <LiquidCrystal.h> // eshte e LCD
#include <Wire.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);// eshte e LCD, shiko skemen e lidhjes "LCD1"
#define heaterPin 6
#define humidifierPin 5
//-----S RTC
#include "RTClib.h"// eshte RTC
RTC_DS1307 rtc;
DateTime now;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
//-----E RTC
// Temperatura Humidity DHT11 start
#include <dht11.h>
dht11 DHT11;
#define PIN_DHT11 2
// Temperatura Humidity DHT11 finish
//const int heaterPin = 5; jane percaktuar mesiper
//const int humidifierPin = 6; jane mesiper
const float temperatureThreshold = 37.5;
const float humidityThreshold = 60.0;
void setup() {
pinMode(heaterPin, OUTPUT);
pinMode(humidifierPin, OUTPUT);
lcd.begin(16, 2);
// you can now interact with the LCD, e.g.:
lcd.print("Hello World!");
//kodi i meposhtem eshte RTC
Serial.begin(115200);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
lcd.begin(0, 1);
lcd.print("JO RTC");
Serial.flush();
delay(2000);
// abort();
}
// rtc.adjust(DateTime(2022, 1, 1,18, 55, 2));
//deri ketu RTC
//e reja rtc
if(!rtc.isrunning()){
// Serial.println("RTC power failure, resetting the time!");
rtc.adjust(DateTime(F(DATE), F(TIME)));
lcd.begin(0, 1);
lcd.print("JO runni");
}
// e reja mbyllet
}
void loop() {
//----------
DateTime now = rtc.now();
lcd.begin(0, 1);
lcd.print("Current time: ");
delay(2000);
lcd.begin(0, 1);
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.print(" (");
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.print(") ");
delay(1000);
lcd.begin(0, 1);
lcd.print("ORA : ");
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
lcd.println("Seko");
delay(2000);
// Temperature code start
DHT11.read(PIN_DHT11);
float humidity = DHT11.humidity;
float temperature=DHT11.temperature;
lcd.begin(0, 1);
lcd.print("Current Humidity: ");
delay(1000);
lcd.begin(0, 1);
lcd.print((float)DHT11.humidity, 2);
delay(3000);
lcd.begin(0, 1);
delay(1000);
lcd.print("Temperature (oC): ");
delay(1000);
lcd.begin(0, 1);
lcd.print((float)DHT11.temperature, 2);
delay(3000);
//Temperature code finish
if (temperature < temperatureThreshold) {
digitalWrite(heaterPin, HIGH); //heater pin eshte pin 5
} else {
digitalWrite(heaterPin, LOW);
}
if (humidity < humidityThreshold) {
digitalWrite(humidifierPin, HIGH); // eshte pin 6
} else {
digitalWrite(humidifierPin, LOW);
}
delay(1000);
}
PleAE GIVE A CORRECT ANSWER
Thank you!!