Ahh yes, the same old cliche "my first project", well it is, and I have swallowed my pride and calling for help!
The project
A unit to control the temperature and humility in a cupboard for drying cloths using a liquid filled tube heater and an extract fan for when the humidity is too high, these will operate through relays. I have used codes that I have found on the net and the temp/hum sensors working the relays and displayed on the LCD all works fine.
What I want to do now is add a timer to it that will display on the LCD, when it reaches '0' will turn off the heater. This is what I thought would be then easy part but is proving not to be. Now I have found various sketches to do this but when I integrate it into the excising code it becomes a bit out of my league, attached is what I have so far and is also open to change and suggestions. Thanks.
#include <DHT22.h>
#include <LiquidCrystal.h>LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
#define DHT22_PIN 2
int temp_relayPin = 13;
int hum_relayPin = 4;// Temp/Humidity sensor
DHT22 myDHT22(DHT22_PIN);void setup()
{
pinMode(temp_relayPin, OUTPUT);
pinMode(hum_relayPin, OUTPUT);lcd.begin(16, 2);
Serial.begin(9600);
Serial.println("DHT22 Library Demo");
lcd.print("Please Wait.........");
}void loop(void)
{
temp_updateOutputs();
hum_updateOutputs();
DHT22_ERROR_t errorCode;delay(2000);
Serial.print("Requesting data...");
errorCode = myDHT22.readData();
switch(errorCode)
{
case DHT_ERROR_NONE:
lcd.begin(16,2);
Serial.print("Got Data ");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Hum% TempC TimeM");
lcd.setCursor(0,1);
lcd.print(myDHT22.getHumidity());
lcd.setCursor(6,1);
lcd.print(myDHT22.getTemperatureC());break;
case DHT_ERROR_CHECKSUM:
Serial.print("check sum error ");
Serial.print(myDHT22.getTemperatureC());
Serial.print("C ");
Serial.print(myDHT22.getHumidity());
Serial.println("%");
break;
case DHT_BUS_HUNG:
Serial.println("BUS Hung ");
break;
case DHT_ERROR_NOT_PRESENT:
Serial.println("Not Present ");
break;
case DHT_ERROR_ACK_TOO_LONG:
Serial.println("ACK time out ");
break;
case DHT_ERROR_SYNC_TIMEOUT:
Serial.println("Sync Timeout ");
break;
case DHT_ERROR_DATA_TIMEOUT:
Serial.println("Data Timeout ");
break;
case DHT_ERROR_TOOQUICK:
Serial.println("Polled to quick ");
break;
}
}void temp_updateOutputs()
{
if (myDHT22.getTemperatureC() < 25)
{
digitalWrite(temp_relayPin, HIGH);
}
else if (myDHT22.getTemperatureC() > 25)
{
digitalWrite(temp_relayPin, LOW);
}
}void hum_updateOutputs()
{
if (myDHT22.getHumidity() < 58)
{
digitalWrite(hum_relayPin, LOW);
}
else if (myDHT22.getHumidity() > 58)
{
digitalWrite(hum_relayPin, HIGH);
}
}