safwan092

Untitled

Nov 28th, 2021
949
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "DHT.h"
  2. #define relayPin 8
  3. #define LEDPin 9
  4. #define LDRPin A0
  5. #define DHTPIN 2
  6. #define DHTTYPE DHT11
  7.  
  8. DHT dht(DHTPIN, DHTTYPE);
  9.  
  10. int sensorValue = 0;
  11. int setValue = 300; // Light
  12. int setValue2 = 27; // Temp
  13.  
  14. void setup() {
  15.   Serial.begin(9600);
  16.   pinMode(LEDPin, OUTPUT);
  17.   pinMode(relayPin, OUTPUT);
  18.   digitalWrite(relayPin, LOW);
  19.   dht.begin();
  20.   delay(5000);
  21. }
  22.  
  23. void loop() {
  24.   float t = dht.readTemperature();
  25.   sensorValue = analogRead(LDRPin);
  26.  
  27.   Serial.println(sensorValue);
  28.   Serial.println(t);
  29.  
  30.   if (sensorValue <= setValue && t < setValue2) {
  31.     digitalWrite(LEDPin, HIGH);
  32.     digitalWrite(relayPin, LOW);
  33.   }
  34.  
  35.   else if (sensorValue <= setValue && t >= setValue2) {
  36.     digitalWrite(LEDPin, HIGH);
  37.     digitalWrite(relayPin, HIGH);
  38.   }
  39.   else if (sensorValue > setValue && t < setValue2) {
  40.     digitalWrite(LEDPin, LOW);
  41.     digitalWrite(relayPin, LOW);
  42.   }
  43.   else if (sensorValue > setValue && t >= setValue2) {
  44.     digitalWrite(LEDPin, LOW);
  45.     digitalWrite(relayPin, HIGH);
  46.   }
  47.  
  48.   delay(10);
  49. }
RAW Paste Data