Electronic – arduino – Using a 12V lighted toggle switch with an Arduino

arduino

I would like to connect a 12V lighted toggle switch to an Arduino and be able to read its state (replacing the momentary button in this tutorial with this switch). But the Arduino has only 5V power supply. Can I connect the 12V switch to the 5V power supply?

Update:

There are just three contacts on this particular switch. The contacts are labeled source, ACC (presumably accessory) and ground. When you close the switch, it connects source to ACC and also connects source through the lamp to ground. There is just a single power source in the circuit.

Best Answer

I can't see anything about the lighting on the link you gave.

The lighting is normally separately controlled. You have 3 contacts for the switch (that's usually a change-over switch, though the description says SPST), and a couple of pins where you connect the lamp. Use a transistor to drive the lamp from your Arduino, then the Arduino's output pin won't see the 12V, and connect the switch like in the tutorial.

If the switch should happen to be connected directly to the lamp, so that it also switches 12V (it may explain that third pin), you'll have to use a resistor divider to bring the 12V from the switch down to the 5V the Arduino's input can digest. Never apply 12V directly to the input.

edit (after your edit)
If I understand correctly source and ground are your power supply. ACC (whatever it may mean) is the switched V+, which is also used to power the lamp. In that case you simply need a voltage divider between ACC and the Arduino input. The ratio should be 2:3, for instance a 30k\$\Omega\$ between ACC and the Arduino input, and a 20k\$\Omega\$ between the input and ground. That will divide the 12V from the switch by 20k\$\Omega\$/(20k\$\Omega\$+30k\$\Omega\$), so you get 4.8V out.