thermistor-kylskap.ino (1792B)
1 #include <SimpleDHT.h> 2 #include <Wire.h> 3 #include <LiquidCrystal_I2C.h> 4 5 LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display 6 7 // for DHT11, 8 // VCC: 5V or 3V 9 // GND: GND 10 // DATA: 2 11 int pinDHT11 = 8; 12 SimpleDHT11 dht11(pinDHT11); 13 int setDegrees = 10; 14 long startTime = millis(); 15 long readTime = millis(); 16 byte temperature = 0; 17 byte humidity = 0; 18 int err = SimpleDHTErrSuccess; 19 20 void setup() { 21 Serial.begin(115200); 22 lcd.init(); 23 lcd.backlight(); 24 pinMode(2, OUTPUT); 25 pinMode(9, INPUT_PULLUP); //knapp 1 26 pinMode(10, INPUT_PULLUP); //knapp 3 27 } 28 29 void loop() { 30 readTime = millis() - startTime; 31 if (readTime > 5000) { 32 startTime = millis(); 33 // start working... 34 Serial.println("================================="); 35 Serial.println("Sample DHT11..."); 36 37 // read without samples. 38 if ((err = dht11.read(&temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { 39 Serial.print("Read DHT11 failed, err="); Serial.print(SimpleDHTErrCode(err)); 40 Serial.print(","); Serial.println(SimpleDHTErrDuration(err)); delay(100); 41 return; 42 } 43 } 44 45 if (digitalRead(9) == LOW){ 46 setDegrees -= 1; 47 lcd.setCursor(1,1); 48 lcd.print(" "); 49 } 50 51 if (digitalRead(10) == LOW){ 52 setDegrees += 1; 53 } 54 55 if (temperature > setDegrees) { 56 digitalWrite(2, LOW); //relay 57 } 58 59 if (temperature < (setDegrees - 3)) { 60 digitalWrite(2, HIGH); //relay 61 } 62 63 Serial.print("Sample OK: "); 64 lcd.setCursor(1,0); 65 lcd.print("Temp: " + String(temperature) + " C"); 66 lcd.setCursor(1,1); 67 lcd.print("Set: " + String(setDegrees) + " C"); 68 Serial.print((int)temperature); Serial.print(" *C, "); 69 Serial.print((int)humidity); Serial.println(" H"); 70 delay(150); 71 }