This is my code. What i want to do is activate the relay when switchInNcPin is activate. I am using a switch (micro switch). It has COM NC and NO pins. Can you tell me what is wrong with my code? PROBLEM: The relay keeps clicking ON and OFF even though it is meant to wait 5000ms, activate, wait 3000ms, deactivate only once. Can you look at my code and help me?
-
1connect the switch like a button arduino.cc/en/Tutorial/InputPullupSerial– Juraj ♦Mar 22, 2018 at 15:02
-
2please don't post pictures of code, copy the code into your question and use the proper format. This way people can copy all or part of your code, make changes and use that in their answer.– Chad GMar 22, 2018 at 15:23
1 Answer
Maybe it's not the only problem, but at least:
int val = ...
and
if (val == "FLUSH")
do not match.
I assume you mean a digit here (0 or 9 to flush)?
Also, you should put your circuit in your question. A reason because of the 'flipping' is that your switch is not pulled down, and it results in undefined behavior.
Another thing you could add is debouncing, when a switch is clicked, it results in multiple 0/1 and 1/0 transitions (although your delay might help too).