Toggle switches to turn on led's

Hello,

I am completely new to arduino boards and electronics in general. I am trying to learn as much as I can so I can eventually use arduinos to build a flight sim.

My question for today is: can I use a 120v 20amp toggle switch to turn an led on and off? I am using an arduino uno and the leds have their own resistors wired in. If I cant use those switches, what specs can I use safely? Thanks for your help.

Switches:

LEDs:

Yes, a switch is a switch, unless you still have it wired to 120V as well, in which case, POOF!
I assume you just don't have a more appropriate switch available.

Just make sure it isn't a more unusual 120V switch, like one with a built-in illumination.

pls pictures of this switch and LED

Nope, nothing special about these. I also want power to run straight from the board so I dont blow anything up. Lol. Thanks!

Edited the post so they are on there:

Switches:

LEDs:

Thank you.

Just what I need another thing to spend money on.

But I want a set…

a7

They are awesome! If I can figure out how to wire them to the board ill be happy.

Most switches have specifications just like most quality LEDs have specifications. Here is a snippet from your LED link.

  • Details: **ITEM Size (mm): 5mm; ** Wire Length: 21MM; **Forward Voltage (V): 12VDC; **Forward Current (mA): 20mA; **White Color MCD: 16000-20000 MCD

FWD Voltage 12 VDC
FWD Current 20 mADC

Not much so about any switch will work just fine. However out of the box your LEDs you linked to are designed around 12 VDC operation based on their series resistors. So what's the plan for driving your 12 volt LEDs?

Ron

arduino uno; needs 22 ga wires poked into the female pin locations. Wire that wire to the screw terminal. Other screw terminal gets a common wire for all switches. That common comes back to Arduino ground. Use "INPUT_PULLUP" when configuring the inputs. Current is negligible. The three-terminal switches, you'll want a wire from top and bottom to separate inputs, and run the common across the center terminals, again to GND.

In your code, the inputs will all show as LOW, or 0, when the switch is closed/pressed.
HTH

Your LEDs are more problematic, as Arduinos cannot drive 12V LEDs.

do you build a space shuttle? or may be a car? why you want to use 12V LED ?
if you want just game controller it goes easier:

https://www.simhubdash.com/
etc

I did it! kinda. For some reason when my switch is in the ON position, the LED will turn off, and with the switch in the OFF position, the LED will turn on. I tried reversing my button state in my code, but all that does is dim the light instead of turning it all the way off when the switch is in the OFF position. Any ideas?

code:

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 7; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == LOW
) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW
);
}
}

Nope. Please follow posting guidelines for code. And, I presume then you've wired your 12V LEDs to the Arduino outputs, but are only powering the LEDs with 5V? Or connecting them from output to ground? A schematic would be really useful at this point.


Ahh, so simple LED and resistor now, no 12 V devices.
Your LED is on when the output is high, but your input is wired so that when the switch is closed, your signal is LOW. So, of course, when your switch is closed the LED is off. Simple. Invert the button reading.

See, I tried that. I changed by buttonstate to HIGH and then changed it to LOW. When its in LOW, it works, but the LED doesnt turn all the way off, it just dims. Or am I understanding you wrong?

Then I want to see your code, because it should be on, or off. I have suspicions.

1 Like

Post the code that does that and the circuit if it isn't already clear.

You really only have to change the sense of the switch immediately you read it, wherever you read it, viz:

buttonState = !digitalRead(buttonPin);

Note the use of the logical "not" operator '!', in the above line of code.

a7

With this code, LED comes on with switch in OFF position.
If I swap line 47 with LOW and line 48 with HIGH, the led comes on with switch in ON position, but in the OFF position, it dims rather than going all of the way off. Same if i just try to change the button state.

OK, maybe you've got something going on that is subtle.

Please learn how to post code. I have squinted at your screen shot as much as I can tolerate, and I am not going to type in that sketch to test it myself.

Use the IDE Autoformat tool to fix up you formatting.

Next use the IDE Copy for Forum tool on the sketch.

Then come here and post it in your next contribution to this thread.

At which point maybe I'll look harder.

Am I too lazy to figure how you've wired this, or have you posted a schematic showing?

a7