Hi I’m trying to use the spark to control a relay based on the value of my sensor and turn it on for 20 seconds then off again. However, the relay doesn’t seem to be able to stay on longer than 6 seconds. Not sure if it is my code or due to power issues but I’m new to coding so would appreciate some help. Thanks. Here is part of my code.
bool relay = HIGH;
bool iswateron = LOW;
unsigned long water_timer;
if (sensorValue >= 301)
{
}
else if (sensorValue <= 300)
{
relay = !relay;
digitalWrite(D5,relay);
iswateron = HIGH;
}
if (iswateron == HIGH)
{
water_timer = millis();
if (water_timer >= 20000)
{
relay = !relay;
digitalWrite(D5,relay);
iswateron = LOW;
water_timer = 0;
}
}
I’ve edited your post to properly format the code. Please check out this post, so you know how to do this yourself in the future. Thanks in advance! ~Jordy