Guest User

Digit Squad - March 2016 - Relay + DHT

a guest
Feb 11th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Code displaying usage of relay using the DHT11 - Connect Signal pin to Digital pin no. 7 AND SWITCH to 8
  3.  * Available for reproduction with proper attributions
  4.  * Commented wherever necessary
  5.  */
  6. #include <dht.h>                      
  7. #define switch 8
  8. dht DHT;
  9. #define DHT11_PIN 7
  10. void setup()
  11. {  
  12.    Serial.begin(9600);
  13.    pinMode(switch, OUTPUT);      
  14. }
  15.    void loop()
  16. {
  17.    int chk = DHT.read11(DHT11_PIN);
  18.   if (DHT.temperature > 20){ //Checks whether the temperature is above 20Degree or not
  19.    digitalWrite(switch,0); // Turns ON Switch
  20.    Serial.println("Appliance is now ON");
  21.    delay(1000); // Waiting is good
  22.    } else {
  23.    digitalWrite(switch,1); //Turns OFF the Switch
  24.    Serial.println("Light OFF"); //for info
  25.    delay(1000); //time in 1 sec = 1000ms
  26.    }
  27. }
Add Comment
Please, Sign In to add comment