Swap push button for rocker switch

Hello All!

I hope all is going well!

Situation: I have a 2 channel relay to control powering on a 12v LED strip. I'll be using an Arduino Uno (that has been collecting way too much dust) with a rocker switch that I will test powering the led strip on and off.

Question:
I am following the tutorial Using Arduino push button to Push ON and Push OFF relay and AC bulb (toggle) by Robojax with the completed code here: Using Arduino push button to Push ON and Push OFF relay and AC bulb - Robojax

The code provided works perfectly and I understand it enough to follow along however, how can I change the code such that when I toggle the rocker switch that the led strip turns on and off?

What is happening currently:

  • The code has been compiled and uploaded.
  • The led strip only turns on via the relay when I toggle the switch twice (which is to be expected since the code is for a push button and not a rocker)

I would greatly appreciate any kind of help on this! I have been googling my eyes out over here attempting this. Forgot to add that I tested the ezbutton toggle library by itself with said rocker switch on its own but I am unsure of how make it such that this library works the way I want it. I am thinking maybe add code for the signal pin in this library so it knows that the relay is there and to switch it off when there is an on/off event?

Thank you for your time and explanation. I must concede that I am quite green at this. The most I've done is turning on an LED ring so I figured that what I had here wasn't the most efficient way to accomplish the task. I've spent so much time searching for a step by step similar to my setup to no avail. I compiled the code you provided however unfortunately, the relay/led does not power on. I used the pins as-is. One switch wire is connected to a ground with the other to the switchpin.

  • Changed: switchPIn to switchPin
  • Changed: if (digitalRead(switchPin == LOW){ to if (digitalRead(switchPin == LOW)){

I should have included that. Here is the setup basically.

That's it honestly. It has no other function than to power them on and off. The led strip is a single color positive and negative connection.

Ok, just wanted to be safe about it all. Since I had the Arduino laying around, I thought it might be an interesting project but If I can do that direct I'm all for simplicity too.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.