So I'm working with a DHT11 Therm/Humidity sensor. I've got it all to work, I'm just trying to mitigate the output if there is no change. Prior to adding this line, there was no issue. If you can show me my error rather than telling me a better way to do it, it would be most appreciated. This is merely for my education to know what went wrong.
if!(f > priorT + 2 && f < priorT -2 && i = 1) //in a non-repetitive fashion dictated by the counter, if there isnt a large change, do not output.
The entire error message and code is available below.
Code:
#include <dht.h>
#define dht_apin A0 // Analog Pin sensor is connected to
dht DHT;
int BLED=9;
int GLED=10;
int RLED=11;
void setup(){
Serial.begin(9600);
delay(1000);//Delay to let system boot
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(500);//Wait before accessing Sensor
// initializing output to RGB LED
pinMode (BLED, OUTPUT);
pinMode (GLED, OUTPUT);
pinMode (RLED, OUTPUT);
digitalWrite(RLED, 127); //show that initialization is complete
digitalWrite(GLED, 0);
digitalWrite(BLED, 0);
delay(200);
digitalWrite(RLED, 0);
}//end "setup()"
void loop(){
double f, priorT, currentT; //variables for conversion and temperature change determination.
int i = 0; //counter
DHT.read11(dht_apin);
f = DHT.temperature * 1.8 + 32; //fahrenheit conversion from DHT.Temperature
priorT = currentT;
currentT = f;
if!(f > priorT + 2 && f < priorT -2 && i = 1) //in a non-repetitive fashion dictated by the counter, if there isnt a large change, do not output.
{
Serial.print("Awaiting status change.");
i++;
}
else if(f > priorT + 2 && f < priorT -2) //if there is a temperature change, output the change
{
Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.print("C ");
Serial.print(f);
Serial.println(" F");
i = 0;
}
if(f < 70 && f > 40)
{
digitalWrite(BLED, 90);
digitalWrite(RLED, 0);
digitalWrite(GLED, 0);
}
else if(f > 70 && f < 90)
{
digitalWrite(BLED, 0);
digitalWrite(RLED, 0);
digitalWrite(GLED, 127);
}
else if(f < 40)
{
digitalWrite(BLED, 127);
digitalWrite(RLED, 0);
digitalWrite(GLED, 0);
}
else if(f > 90)
{
digitalWrite(RLED, 127);
digitalWrite(GLED, 0);
digitalWrite(BLED, LOW);
}
delay(5000);//Wait 5 seconds before accessing sensor again.
i++;
}
Error msgs:
Arduino: 1.6.7 (Windows 7), Board: "Arduino/Genuino Uno"
C:\Users\Xxwitherpoon\Documents\Arduino\Sensors\DHT11andRGBLED\DHT11andRGBLED.ino: In function 'void loop()':
DHT11andRGBLED:52: error: expected '(' before '!' token
if!(f > priorT + 2 && f < priorT -2 && i = 1) //in a non-repetitive fashion dictated by the counter, if there isnt a large change, do not output.
^
DHT11andRGBLED:58: error: 'else' without a previous 'if'
else if(f > priorT + 2 && f < priorT -2) //if there is a temperature change, output the change
^
exit status 1
expected '(' before '!' token
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.