Relay Control with Arduino


This is an amateur question but I can’t figure a way around it even after trying for so long.
So I want to control a relay. I’m using a three way toggle switch and a push button.
It should do the following.

1 = At toggle position “1” it should just turn on.
2 = At toggle position “2” it should turn on for the time according to the potentiometer.(I mapped it for 0 to
60 sec).
3 = The push button should just turn it on while its pressed.


“1” and “3” are simple don’t even need any circuit for that but I’m still using arduino. I’m having trouble with “2”.
Even when the switch is off the loop still keeps running ignoring the if command for switch.
I’ll attach my code.

sketch_apr03a.ino (1.26 KB)

You need to post your code as per the instructions on this forum using the code tags . also you need a circuit diagram before anyone could answer

Clarity required: do you mean in “2” that when the switch is moved to position 2 the relay should come on for the desired time, then go off until the switch is taken out of position 2 and back into 2? So a one-shot flash then nothing until the switch is re-toggled into 2?