Hello - I’m making a lamp with an UNO - which will be powered via a switching adapter using 9volts to a wall outlet.
I’d like to add a SPST Rocker Switch on the base of the lamp for easy on/off access.
I’ve read all sorts of different articles - some say to use a resistor on both terminal of the switch, some use none, and some use pull-up resistors in the code (still don’t quite understand those).
Should I have the power (9V) - coming from the wall - going into the rocker switch on one side, then out the other side and going to the barrel jack on the UNO? Or should I put the switch in the GRD? Should I use physical resistors? If so, what size?
Thanks much,
Rachel
Hi Rachel. Thanks for posting on the forum!
For just controlling power to a device and not switching a digital I/O pin, you don’t need any resistors and what you have drawn in your picture will work just fine.
The only time you need to worry about resistors is when you’re connecting a button or switch to a digital pin on an Arduino. (or other microcontroller) The reason for the resistor is to pull the digital pin to a known state when the button or switch is turned off. By not using a pull up resistor (either externally or by turning on the built in pullup resistor built into the Arduino) the digital pin will ‘float’ and be in an undefined state when the button isn’t pressed.
While floating, the Arduino doesn’t know if the pin is high or low and that ambiguity can cause the Arduino to think the button or switch is being turned on or off randomly. The resistor allows a small current to flow that forces the pin high and when you close the switch or press the button, a the pin is directly connected to ground and makes the pin read low.
The links below should help explain in more detail why and how to use pull-ups and the example shows how to put that in practice with an Arduino.
- [[Pullup resistor explanation](https://en.wikipedia.org/wiki/Pull-up_resistor)
- [[Arduino Button Example](https://www.arduino.cc/en/tutorial/button)
[/list]
Hope this helps!](https://www.arduino.cc/en/tutorial/button)](Pull-up resistor - Wikipedia)