0

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?

ARDUINO CODE

2
  • 1
    connect the switch like a button arduino.cc/en/Tutorial/InputPullupSerial
    – Juraj
    Mar 22, 2018 at 15:02
  • 2
    please 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 G
    Mar 22, 2018 at 15:23

1 Answer 1

1

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).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.