I have a SPST switch and I just want to sense whether it's on or not. I will then turn on/off a relay depending on the state of this switch.

The two options I'm considering are: create a digital out on a pin going to one side of the switch, and read the digital in on another pin off the other side of the switch. Or put 5v from my voltage regulator to the switch, and read a digital in off the other side of the switch.

Would a resistor be necessary for the digital in pin with either of these options?

  • Why don't you just connect the relay to the switch - no Arduino required?
    – Milliways
    Commented May 3, 2018 at 23:40

2 Answers 2


It is wasting of IO pins to use the digital output pin just to get +5V rail. But both options will work. Don't forget to use pull/up or pull/down resistor, or activate internal pull/up resistor on the sensing pin. When the switch will be open, the input pin is not connected anywhere and will act as antenna, so it might pick up some noise.

  • I am choosing this as the correct answer because it uses less current when the switch is open.
    – Owen
    Commented May 5, 2018 at 11:26

You could configure one of the digital pins as INPUT_PULLUP and connect one end of the switch to it. The other end of the switch goes to ground. LOW = switch ON, HIGH = switch OFF.

const byte pinNumber = 3;

void setup(){
  pinMode(pinNumber, INPUT_PULLUP);

void loop(){
  • Does the pullup resistor draw current continually while the switch is open?
    – Owen
    Commented May 3, 2018 at 21:16
  • 1
    Yes. Approximately 0.1 to 0.25 mA.
    – VE7JRO
    Commented May 3, 2018 at 22:15

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.