Humidity and Temperature Controller

Im stuck, im making a humidity controller that will control a fan and 12v ball valves.
My code works fine until I wanted to add the ability to check the temperature and use the value to change which ball valves open.
Im using a DHT11 to measure.

#include <SimpleDHT.h>

//Declaring digital pin no 2 as the dht11 data pin

int pinDHT11 = 2;
int DHTpower = 3;
int ValveOpen = 4;
int ValveClosed = 5;
int Fan = 13; // relay, fan and solenoids
SimpleDHT11 dht11;

void setup() {
pinMode(Fan, OUTPUT);
pinMode (ValveOpen, OUTPUT);
pinMode (ValveClosed, OUTPUT);
pinMode(DHTpower, OUTPUT);
digitalWrite(DHTpower, LOW);
digitalWrite(ValveOpen, LOW);
digitalWrite(Fan, LOW);
digitalWrite(ValveClosed, HIGH);
Serial.begin(9600);
}

void loop() {
delay(1000);
RHcheck(); //check Humidity Level
delay(2000); //wait 15sec
}

void RHcheck() { //Check Humidity Level Function
digitalWrite(DHTpower, HIGH); //On Humidity Sensor
delay(5000);
Serial.println("============ Check Humidity ===============");
delay(1000);
Serial.println("DHT11 readings...");

byte temperature = 0;
byte humidity = 0;
int err = SimpleDHTErrSuccess;

//This bit will tell our Arduino what to do if there is some sort of an error at getting readings from our sensor
if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) {
Serial.print("No reading , err="); Serial.println(err);delay(1000);
return;
}
Serial.print("Readings: ");
Serial.print((int)temperature); Serial.print(" C, ");
Serial.print((int)humidity); Serial.println(" %");
delay(500);
if((int)humidity > 60){ // More than, fan off
digitalWrite(DHTpower, LOW);
delay(500);
Serial.println("Fan OFF");
delay(500);
digitalWrite(Fan, LOW);
delay(500);
digitalWrite(ValveClosed, HIGH);
delay(500);
digitalWrite(ValveOpen,LOW);
}else{
if ((int)humidity < 55){ // Less than
Serial.println("Humidity < 55%");
digitalWrite(DHTpower, LOW);
delay(500);
Serial.println("Fan ON @ full speed");
delay(500);
digitalWrite(ValveOpen, HIGH);
delay(500);
digitalWrite(ValveClosed, LOW);
delay(500);
digitalWrite(Fan, HIGH);
}else{
delay(500);
}
}
}

When I try to add anything the temperature to this line I get an error.

I changed this line
if((int)humidity > 60){ // More than, fan off

to

if ((int)humidity < 55) && ((int)temperature){ // Less than

and I keep getting, error: expected identifier before '(' token

my brain hurts :frowning:

have a read of how-to-get-the-best-out-of-this-forum
e.g.

  1. post your code using code tags - select < CODE/ > and paste text where it says “type or paste code here”
  2. when you run the program what does ir do? what should it do?
  3. how have you connected the sensors - upload a schematic?

This is outside the if() condition.

Hello matt82060
Why do you switch the DHT sensor on and off in the programme?

Sorry my bad, was very tired when i posted that.

The program turns on and off 12v relays that control fans and valves to keep a box the correct relative humidity.
The program works fine as it is just controlling the humidity. I'm trying to add a temperature control as well so i can make the box vent back to the intake if the temp gets too high.
The problem I have is trying to make two IF statements;

}else{
if ((int)humidity < 55){ // Less than

this line works fine, but when I try

}else{
if ((int)humidity < 55) && ((int)temperature > 16){ // Less than

I get

Compilation error: expected identifier before '(' token

Im very new to this and making it up as i go with bits of stolen code from tutorials.

you had missmatch ( and ), try

if (((int)humidity < 55) && ((int)temperature> 16)){ // Less than//

do you mean && (logic AND) or || (logical OR)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.