Hi,
This is my code:
const int relayPin = 5;
int state;
int flag;
void setup()
{
pinMode(relayPin, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if(Serial.available() > 0){
state = Serial.read();
}
if (state == 'W') {
if (flag==0){
digitalWrite(relayPin, HIGH);
flag=1;
}
else if (flag==1){
digitalWrite(relayPin, LOW);
flag=0;
}
state='n';
}
delay(200);
}
When i add this one:
if (Serial.available()) {
byte c = Serial.read ();
delay(3);
// If a measurement is required, measure data and send it back
if (c == 't'){
int t = (int)dht.readTemperature();
Serial.println(String(t) + "c");
}
if (c == 'h'){
int h = (int)dht.readHumidity();
Serial.println(String(h) + "%");
the first code line (fan commend)work fine without the sec code. after i add the sec code is didn't work at all (uploded to my arduino, but don't work).
I newbie, and because that - don't know how to combine the both codes lines to work together.
i think the problem is: to store the data from serial - conflict?!