Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- August 17, 2018
- DHT library from:
- https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib
- If you use non-standard Arduino libraries, you should ALWAYS note what library you used, and where you got it from!
- There are many examples of different libraries from different sources, that use the same names.
- Also--I don't know if this sketch really works, as I don't have one of these sensors on hand to use.
- */
- #include <dht.h>
- //dht DHT; // I prefer to differentiate the instance from the class, by more than just capitalization.
- dht my_dht; // Like so.
- int DHT11_PIN = 7;
- int FAN = 6;
- int GREENLED = 5;
- int REDLED = 4;
- void setup() {
- Serial.begin(9600);
- pinMode(6, OUTPUT);
- pinMode(5, OUTPUT);
- pinMode(4, OUTPUT);
- }
- void loop() {
- int chk = my_dht.read11(DHT11_PIN);
- Serial.print("Temperature = ");
- Serial.println(my_dht.temperature);
- Serial.print("Humidity = ");
- Serial.println(my_dht.humidity);
- delay(5000);
- if (my_dht.temperature >= 24) {
- digitalWrite(FAN, HIGH);
- }
- if (my_dht.temperature < 24) {
- digitalWrite(FAN, LOW);
- }
- if (digitalRead(FAN) == HIGH) { // This was one error.
- // You were checking the value of FAN (which is set to 6, because it's pin #6) but what you wanted was the pin state of pin #6.
- // Also you were using the (=) when you need to be using (==) to do comparisons.
- digitalWrite(GREENLED, HIGH);
- //digitalWrite(REDLED, LOW); // this could be combined from the below if() statement
- }
- else {
- digitalWrite(GREENLED, LOW);
- //digitalWrite(REDLED, HIGH); // this could be combined from the below if() statement
- }
- if (digitalRead(FAN) == LOW) { // Same error as above. And also,,,, you don't really need these as two separate if() statements.
- digitalWrite(REDLED, HIGH);
- }
- else {
- digitalWrite(REDLED, LOW);
- }
- }
- // ~~~~~~~~ end ~~~~~~~~~~
Add Comment
Please, Sign In to add comment