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

asked Mar 22, 2018 at 9:37
2
  • 1
    connect the switch like a button arduino.cc/en/Tutorial/InputPullupSerial Commented 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. Commented 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).

answered Mar 22, 2018 at 9:44
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.