I´ve tried both codes below but didn’t work(delay and pulse). Could you kindly help me to fix the code.
I want my relay to be active for 10 seconds once pushed. Them it goes back to LOW.
========================================================================
CAYENNE_IN(V11)
{
// get value sent from dashboard
int currentValue = getValue.asInt(); // 0 to 1
// assuming you wire your relay as normally open
if (currentValue == 0) {
t.pulse(RELAY_DIGITAL_PIN6, 10000, 1); //pin, time(milliseconds), initial state
} else {
digitalWrite(RELAY_DIGITAL_PIN6, LOW);
}
so basically the first time that I push the button nothing happens. Them if I hit it the second time it turns on. Them click again and it turns off. But them after some seconds it turns on again automatically. This is the behaviour looking/hearing the relay.
In the web/Android it behaves as a normal button. ON/OFF. Nothing happens after the delay/pulse.
Ooh, I think what it’s happening is that you put if (currentValue == 0) then… try changing that 0 to 1, when a button is not pressed it’s 0 when it’s pressed it’s 1 .
I think that this is the general problem. We want our relay to work for 10 seconds only, but it works only when there is “1”, so we can check if it is “1” and then make a delay and then turn it off. We don’t have to check if it is “0” because if it is “0” it simply does not work. We also have to update the value of the dashboard.