1)Detect the rain then active the motor and directly close the roof
2)when the humidity increase and temperature decreasing until certain set point, motor will active. (close roof)
3)LDR is only detect the daylight, when sunlight getting dim mean night time, the motor also active.(close roof)
Meanwhile other than this 3 condition is opening roof.
The problem that i encounter is when i try to combine all coding, i cant make it . i not really expert in program C. someone plz help me correct my coding. thx a lot. i will appreciate it .
- CODE: SELECT_ALL_CODE
#include "DHT.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
DHT dht;
int LDR = 3;
int LDRValue=0;
int humidity= 0;
int temperature=0;
int tempValue=0;
int daynight=400;
int temp_sensitivity=33;
int humidity_sensitivity=60;
const int buttonState = 4;
int E1 = 6;
int M1 = 7;
void setup()
{
dht.setup(2);
Serial.begin(9600);
pinMode(buttonState,INPUT);
digitalWrite(4, HIGH);
lcd.begin(16, 2);
lcd.clear();
pinMode(M1, OUTPUT);
}
void loop()
{
int value;
LDRValue = analogRead(LDR);
delay(dht.getMinimumSamplingPeriod());
float humidity = dht.getHumidity();
float temperature = dht.getTemperature();
// Serial.print(dht.getStatusString());
lcd.setCursor(0,0);
lcd.print("Humidity");
lcd.setCursor(0,1);
lcd.print(humidity, 1);
lcd.setCursor(6,1);
lcd.print(LDRValue, 1);
lcd.setCursor(12,0);
lcd.print("Temp");
lcd.setCursor(12, 1);
lcd.print(temperature, 1);
if (LDRValue > daynight)
{
lcd.clear();
lcd.print("Night mode");
delay(1000);
lcd.clear();
if (buttonState == LOW) { //limit switch recoil
digitalWrite(M1, LOW); //motor forward motion
analogWrite(E1, 1);
delay(50);
lcd.print("ROOF ClOSED");
delay(2000);
}
}
else {
analogWrite(E1, 0); //motor stop moving
delay(50);
}
}
if (temperature> temp_sensitivity)
{
if ( humidity> humidity_sensitivity)
{
if(buttonState == LOW) //limit switch recoil
{
lcd.clear();
lcd.print("ROOF OPENED");
delay(1000);
lcd.clear();
digitalWrite(M1, HIGH); //motor reverse motion
analogWrite(E1, 255);
delay(50);
} }
else {
analogWrite(E1, 0);
delay(50);
}
}
}