[code]
#include <LiquidCrystal.h>
#define DHTPIN 8
#define DHTTYPE DHT11
#define dht
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//
int Relaypin = 7; //Relay digital pin
double Timer; //Humidity monitor timer;
boolean HighHumid_B = 0 , LowHumid_B = 0 , Wait_state = 1 , On_state = 0 , Off_state = 0;
int HighHumidThresh =70 , LowHumidThresh = 50 , h_old =0;
DHT dht (DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
dht.begin();
pinMode(Relaypin, OUTPUT);
digitalWrite(Relaypin, HIGH); // Dehumidifier set to OFF by default
lcd.setCursor(12,0); lcd.print("OFF"); // Show default setting on screen
delay(500);
}
void loop() {
int h = dht.readHumidity();
int t = dht.readTemperature();
if (isnan(t) || isnan(h)) { /* ERROR - Do nothing */ }
else {
char key = keypad.getKey();
if (key != NO_KEY){
/////Low SP set
if (key=='#') {
LowSPset = 1; LowSPcounter =0; HighSPset = 0; HighSPcounter =0;
lcd.setCursor(13,1); //Go to Low SP position on LCD
lcd.print(" "); //delete old SP
}
/////High SP set
else if (key=='*') {
HighSPset = 1; HighSPcounter =0; LowSPset = 0; LowSPcounter =0;
lcd.setCursor(5,1); //Go to High SP position on LCD
lcd.print(" "); //delete High SP
}
else if (key!='#' && LowSPset ==1) {
if (LowSPcounter==0) { SPinput[0]= key; lcd.setCursor(13,1); lcd.print(key); LowSPcounter++; }
else if (LowSPcounter==1) { SPinput[1]= key; lcd.setCursor(14,1); lcd.print(key); LowSPcounter++;}
if (LowSPcounter==2) {LowSPcounter =0; LowSPset=0; LowHumidThresh=(int(SPinput[0])-48)*10+int(SPinput[1])-48;}
}
else if (key!='*' && HighSPset ==1) {
if (HighSPcounter==0) { SPinput[0]= key; lcd.setCursor(5,1); lcd.print(key); HighSPcounter++; }
else if (HighSPcounter==1) { SPinput[1]= key; lcd.setCursor(6,1); lcd.print(key); HighSPcounter++;}
if (HighSPcounter==2) {HighSPcounter =0; HighSPset=0; HighHumidThresh=(int(SPinput[0])-48)*10+int(SPinput[1])-48;}
}
}
if (LowSPset==0 && HighSPset==0) {
lcd.setCursor(0,1);
lcd.print("(Hsp="); lcd.print(HighHumidThresh); lcd.print(" Lsp="); lcd.print(LowHumidThresh); lcd.print(")");
Serial.println(HighHumidThresh);}
if (h >= HighHumidThresh) {Wait_state = 0; On_state = 1; Off_state = 0;}
else if (h <= LowHumidThresh) {Wait_state = 0; On_state = 0; Off_state = 1;}
else if (h > LowHumidThresh && h < HighHumidThresh) {Wait_state = 1; On_state = 0; Off_state = 0;}
if (On_state ==1 && HighHumid_B ==0) {HighHumid_B =1; LowHumid_B = 0; Timer = millis();}
else if (Off_state ==1 && LowHumid_B ==0) {LowHumid_B =1; HighHumid_B = 0; Timer = millis();}
else if (Wait_state ==1) {LowHumid_B =0; HighHumid_B = 0;}
lcd.setCursor(0,0);
lcd.print("T="); lcd.print(t); lcd.print("C "); lcd.print(h); lcd.print("% ");
//lcd.print("H"); lcd.print(HighHumid_B); lcd.print("L"); lcd.print(LowHumid_B); lcd.print(" "); lcd.print((millis() - Timer)/1000);
if ((millis() - Timer)> 2000 && HighHumid_B == 1) {digitalWrite(Relaypin, LOW); lcd.setCursor(12,0); lcd.print("ON ");} //Turn Dehumidifier ON
else if ((millis() - Timer)> 2000 && LowHumid_B == 1) {digitalWrite(Relaypin, HIGH); lcd.setCursor(12,0); lcd.print("OFF");} //Turn Dehumidifier OFF
delay(500);
h_old = h;
}
}
#define DHT11_PIN 0 // pin A0
byte read_dht11_dat()
{
byte i = 0;
byte result = 0;
for (i = 0; i < 8; i++) {
while (!(PINF & _BV(DHT11_PIN))); // wait for 50us
delayMicroseconds(30);
if (PINF & _BV(DHT11_PIN))
result |= (1 << (7 - i));
while ((PINF & _BV(DHT11_PIN))); // wait '1' finish
}
return result;
}
void setup()
{
DDRF |= _BV(DHT11_PIN);
PORTF |= _BV(DHT11_PIN);
Serial.begin(19200);
Serial.println("Ready");
}
#if 0
void loop()
{
PORTF &= ~_BV(DHT11_PIN); //pull-down i/o pin from 18ms
delay(18);
PORTF |= _BV(DHT11_PIN);
delay(40);
}
#endif
#if 1
void loop()
{
byte dht11_dat[5];
byte dht11_in;
byte i;
// start condition
// 1. pull-down i/o pin from 18ms
PORTF &= ~_BV(DHT11_PIN); // pull-down i/o pin from 18ms
delay(18);
PORTF |= _BV(DHT11_PIN);
delayMicroseconds(40);
DDRF &= ~_BV(DHT11_PIN); //Set to input
delayMicroseconds(40);
dht11_in = PINF & _BV(DHT11_PIN); //Read data line is high voltage
if (dht11_in) {
Serial.println("dht11 start condition 1 not met");
return;
}
delayMicroseconds(80);
dht11_in = PINF & _BV(DHT11_PIN);
if (!dht11_in) {
Serial.println("dht11 start condition 2 not met");
return;
}
delayMicroseconds(80);
// now ready for data reception
for (i = 0; i < 5; i++)
dht11_dat[i] = read_dht11_dat();
DDRF |= _BV(DHT11_PIN);
PORTF |= _BV(DHT11_PIN);
byte dht11_check_sum = dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3];
// check check_sum
if (dht11_dat[4] != dht11_check_sum)
{
Serial.println("DHT11 checksum error");
}
Serial.print("Current humdity = ");
Serial.print(dht11_dat[0], DEC);
Serial.print(".");
Serial.print(dht11_dat[1], DEC);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(dht11_dat[2], DEC);
Serial.print(".");
Serial.print(dht11_dat[3], DEC);
Serial.println("C ");
delay(2000);
}
#endif
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
[/code]
Hi I am new to using arduino and am having a few issues with this code for a dht11 sensor. I continue to get an error message : expected constructor, destructor or type conversion before '(' token. highlighting this line DHT dht (DHTPIN, DHTTYPE);
I uploaded the DHT.h library, before i did that I had a different error message saying " expected primary expression before '.' token. highlighting this line : int t = dht.readTemperature();
Any and all suggestions are welcome!
thank you!!