I am measuring light, temperature and humidity on a arduino uno, and have programmed the loop to run every minute. Monitoring the values on the serial monitor.
However, what i would like is the code to run once to get the values, then wait, or pause, until one of the values change, and then output this on the serial monitor.
I want to get informed of changes in the sensors immediately, not wait for a minute for the loop to run. Is there a way to do this?
Thanks.
So I would need to add an if/else function to the following code?
int lightPin = A5;
int lightok = 9;
int lighthigh = 10;
void setup()
{
Serial.begin(9600);
pinMode(lightok,OUTPUT);
pinMode(lighthigh,OUTPUT);
}
void loop()
{
delay(600000);
int lightlevel = analogRead(lightPin);
lightlevel = map(lightlevel, 0, 1023, 0, 255);
lightlevel = constrain(lightlevel, 0, 255);
Serial.print("Lightlevel: ");
Serial.println(lightlevel);
//led control for light levels
if (lightlevel < 15 || lightlevel > 125) {
digitalWrite(lighthigh, HIGH);
digitalWrite(lightok, LOW);
} else {
digitalWrite(lighthigh, LOW);
digitalWrite(lightok, HIGH);
}
}