Hi,
I am trying to run a while loop inside the void loop().
But I am getting a WDT reset.
WDT rest.
cause: 2 error(3,6)
and as soon as i remove the while loop, it runs fine.
here is the code
int abc == 0;
void loop()
{
if (!mqttClient.connected()) {
reconnect();
}
mqttClient.loop();
while (abc == 0){
if(digitalRead(pirPin) == HIGH){
digitalWrite(ledPin, HIGH);
if(lockLow){
lockLow = false;
Serial.println("motion detected ");
digitalWrite(14, HIGH);
mqttClient.publish("XYZ/MotionSensor","Motion Detected");
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW){
digitalWrite(ledPin, LOW);
if(takeLowTime){
lowIn = millis();
takeLowTime = false;
}
if(!lockLow && millis() - lowIn > pause){
lockLow = true;
Serial.println("motion ended");
digitalWrite(14, LOW);
abc == 1;
mqttClient.publish("XYZ/MotionSensor","Motion Ended");
}
}
}
}
Basically, I receive a command using internet to start the sensor. The sensor starts. And I need it to run in the loop TILL the time motion is detected. And then fall out of the while loop and wait for command from internet again.
But why is the device getting s WDT reset?
Cause: 2 refers to the reset pin. But my reset pin is untouched.