Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TM1637.h> // include TM1637 libary "DigitalTube"
- #include "DHT.h" // include dht libary
- const int SO = 9; // setting pin 9 for trouble shooting
- const int CLK = 2; // pin CLK is connected to
- const int DIO = 3; // pin DIO is connected to
- const int DHTpin = 5; // pin dht is connected to
- #define DHTTYPE DHT11 // the type of DHT sensor
- TM1637 tm1637(CLK,DIO); // initalize TM1637 to pin
- DHT dht(DHTpin, DHTTYPE); // initalize dht to pin and type
- const int relay = 4; // pin relay is on
- void setup() {
- dht.begin(); // initalize dht
- tm1637.init(); // initalize tm1637
- tm1637.set(2); // set brightness of tm1637
- pinMode(relay, OUTPUT); // set relay pin as output
- pinMode(SO, INPUT_PULLUP); // setting TS pin as a input
- Serial.begin(9600); // start serial at 9600 baud
- }
- void loop() {
- int humidity = dht.readHumidity(); // set humidity to the sensor humidity reading
- int temp = dht.readTemperature(true); // set temp to temperature reading from sensor - true is added for Fahrenheit setting
- int d1t = temp / 10; // set d1t to first digit of temp
- int d2t = temp % 10; // set d2t to second digit of temp
- int d1h = humidity / 10; // set d1h to first digit of humidity
- int d2h = humidity % 10; // set d2h to second digit of humidity
- if (humidity >= 55) digitalWrite(relay, HIGH); // if humidity is at or over 55 turn on relay
- if (humidity <= 50) digitalWrite(relay, LOW); // if humidity is at or less than 50 turn off relay
- tm1637.display(0,d1t); // display first temp digit on segment 0
- tm1637.display(1,d2t); // display second temp digit on segment 1
- tm1637.display(2,d1h); // display first humidity digit on segment 2
- tm1637.display(3,d2h); // display second humidity digit on segment 3
- if (temp == 00 || humidity == 00) { // if sensor is showing 00 prints EEEE
- tm1637.display(0,14);
- tm1637.display(1,14);
- tm1637.display(2,14);
- tm1637.display(3,14);
- }
- if (digitalRead(SO) == LOW) { // if SO is high we will start a serial display
- Serial.println(" START DIAG SCREEN ");
- Serial.print(dht.readHumidity()); // read humidity data from sensor
- Serial.println(" Humidity from sensor ");
- Serial.print(humidity); // read humidity data from humidity
- Serial.println(" Humidity value stored ");
- Serial.print(dht.readTemperature(true)); // read temp from sensor
- Serial.println(" Temp from sensor ");
- Serial.print(temp); // read temp data from temp
- Serial.println(" Temp value stored ");
- Serial.print(digitalRead(relay)); // read if relay is high or low
- Serial.println(" Relay value ");
- Serial.print(digitalRead(SO)); // read if SO is high or low
- Serial.println(" SO value ");
- Serial.println(" END DIAG SCREEN ");
- }
- delay(60000); // 60 second delay
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement