The first thing that came to my mind when I started microcontroller programming was to set an automatic room heating cum humidifier system.
First off – bought a DHT11 sensor module. Then went about setting up the circuit. Added the LCD to boot – to show the temperature and humidity.
Set up the circuit as follows:
Code as follows:
#include #include #define DHT11PIN 13 #define RELAY1 2 // Connect humidifier to Relay1 #define RELAY2 3 // Connect heater to Relay2 #define TEMP_SET 20.0 #define HUM_SET 35.0 dht11 DHT11; LiquidCrystal lcd(7, 8, 9, 10, 11, 12); void setup() { lcd.begin(16, 2); pinMode(DHT11PIN, INPUT); pinMode(RELAY1, OUTPUT); pinMode(RELAY2, OUTPUT); } void loop() { // put your main code here, to run repeatedly: int chk = DHT11.read(DHT11PIN); // Serial.print("Read sensor: "); switch (chk) { case DHTLIB_OK: // Serial.println("OK"); break; case DHTLIB_ERROR_CHECKSUM: // Serial.println("Checksum error"); break; case DHTLIB_ERROR_TIMEOUT: // Serial.println("Time out error"); break; default: lcd.println("Unknown error"); break; } lcd.setCursor(0, 0); lcd.print("Humidity: "); lcd.print((float)DHT11.humidity, 2); lcd.setCursor(0, 1); lcd.print("Temp: "); lcd.print((float)DHT11.temperature, 2); if(DHT11.humidity < 50){ digitalWrite(RELAY1, HIGH); lcd.print("H1"); } else { digitalWrite(RELAY1,LOW); // lcd.print("H0"); } if(DHT11.temperature < 25){ digitalWrite(RELAY2, HIGH); // lcd.print("T1"); } else { digitalWrite(RELAY2,LOW); lcd.print("T0"); } delay(900000); }
Worked like a charm – next steps:
- Add two buttons to change the temperature presets – save preset in EEPROM
- Create a standalone arduino so that I don’t have to give up my Induino for this small project