I have made a drone/car quadruped robot thing and I need help with the code. I have found two codes to use to control each aspect of it but I need help to connect them. I have made a radio controller with a Xbee 3 Pro that has a spdt (two position switch) and I want to use it to switch the modes. I want the car to be LOW and the drone to be HIGH (If it helps the switch is on pin digital pin 9 of a Arduino Nano). I am a beginner at the coding aspect of the project and I would appreciate all the help I can get.



  • please add your code to the post
    – jsotola
    Commented Dec 18, 2020 at 16:45

1 Answer 1


There is no need for a SPDT switch. A SPST works just as well.

If you have a SPDT switch with 3 positions (pole 1 closed, open, pole 2 closed) you can use it to activate one pin or the other, or neither.

Let's pretend your switch is an SPST. Ignore one of the poles (pole 2, say.)

Connect a digital pin to pole 1. connect the common (center) pin to ground.

Set your digital pin to INPUT_PULLUP. Now, when the pin is LOW, the switch is closed (mode A). When the pin is HIGH, the switch is open (mode B).

  • Thank you I just checked back in and this is very helpful. Do I need a resistor like as if it were a pushbutton Commented Dec 19, 2020 at 1:07
  • If you use INPUT_PULLUP mode then the Arduino connects the pin to +5V through an internal restistor, so you don't need an external resistor. That is true for pushbuttons as well. (However, when you use INPUT_PULLUP, the pin reads HIGH when the switch is open, and goes LOW when the switch is closed.)
    – Duncan C
    Commented Dec 19, 2020 at 11:53

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.