Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Code displaying usage of relay using the DHT11 - Connect Signal pin to Digital pin no. 7 AND SWITCH to 8
- * Available for reproduction with proper attributions
- * Commented wherever necessary
- */
- #include <dht.h>
- #define switch 8
- dht DHT;
- #define DHT11_PIN 7
- void setup()
- {
- Serial.begin(9600);
- pinMode(switch, OUTPUT);
- }
- void loop()
- {
- int chk = DHT.read11(DHT11_PIN);
- if (DHT.temperature > 20){ //Checks whether the temperature is above 20Degree or not
- digitalWrite(switch,0); // Turns ON Switch
- Serial.println("Appliance is now ON");
- delay(1000); // Waiting is good
- } else {
- digitalWrite(switch,1); //Turns OFF the Switch
- Serial.println("Light OFF"); //for info
- delay(1000); //time in 1 sec = 1000ms
- }
- }
Add Comment
Please, Sign In to add comment