Controlling an RC Servo Motor With an Arduino and Two Momentary Switches





Introduction: Controlling an RC Servo Motor With an Arduino and Two Momentary Switches

The name says it all. Controlling an RC car servo motor with an Arduino and some resistors, jumper wires, and two tactile switches. I made this the second day I got my Arduino, so I'm pretty proud of myself.

Step 1: Parts List

Okay, your going to need the following:

Arduino-$30-35 USD
Find out where to buy those here.

Jumper Wires-$8.50 USD
I got mine from Amazon

Resistors- Pennies a piece
Get em from Radio Shack, Digi-Key, Mouser, Jameco, etc.
Your goin to need two around 100 ohms (brown black brown) and two around 10k ohms(brown black orange). These don't have to be exact.

Servo Motor- $10 USD
Yes, I know this isn't the cheapest one on the internet. Tower Hobbies

Breadboard- $9-$30 USD, Depending on the size.

Tactile Switch- $0.20 USD
Only 6,427 left on Digi-Key I just salvaged mine...

Step 2: The Circuit

The circuit is fairly simple. You should be able to throw it on a breadboard in five minutes like I did. Make sure it makes no sense to your less geeky family, and looks like a wad of something you pulled off a drain snake. Yum.

Step 3: The Program/Sketch

Here's my code that I used. I might explain it later, I'm kind of lazy. Thats what this and this are for.

#include <Servo.h>

Servo myservo;
int button7=0;
int button6=0;
int pos=90;

void setup()
pinMode(7, INPUT);
pinMode(6, INPUT);

void loop()




if(button7==1 && button6==0)

if(button7==0 && button6==1)

Any bugs, glitches? I don't notice any...

Step 4: It Works(or Doesn't)! And, Coming Soon.....

It hopefully works for you, if it doesn't post a comment. We of the instructable community are usualy good at helping people. Hoping to add a video sometime soon. Might just post a video of an Arduino controlling a servo in another project, since I've moved on to bigger and better things. So have fun with this, modify it, heck go out and make money off of it and then tell me! That would just make my day.



    • Microcontroller Contest

      Microcontroller Contest
    • Science of Cooking

      Science of Cooking
    • Pocket-Sized Contest

      Pocket-Sized Contest

    We have a be nice policy.
    Please be positive and constructive.




    Hi can anyone help me use this with a NRF24L01? any help would be greatful

    Hello Geeklord - was wondering just off hand if you could possibly help me to utilize 2 joysticks with x, y, and z axis to control 2 servos. Each servo will work off one ps2 style joystick. Servos will be set to pan and tilt. Any thoughts or assistance would be much much appreciated.

    how do you keep it going in one direction ?

    The Constrain should either be directly before the write, or after the if.

    A jumper kit is nice, but you can also salvage them from different kabels. 

    Looks cool!

    I got an Duemilanove in my XMas stocking with a Servo Shield and have tried my darndest to load a rudimentary motor sketch, to no avail.

    I've gotten error after error with the #include <Servo.h> and am wondering if you could shed some light?

    I have several instances of the arduino folder (thinking that I might have a path issue). One on the root (c:/), one in my documents, and one wherever the unzipper defaults it to. I have tried different paths, and only get different errors, and none of them are very helpful. I see that you just have a plain "#include <Servo.h>", just like the instructions on the Arduino site said, but that not working for me. Any help would be appreciated.
    I'm going to give myself an epileptic seziure if all I can do on my new toy is change the blink rate on an LED (which is all I've done).  : ( 


    Hang in there... I'm not sure what you mean by Servo shield, do you mean the adafruit motor shield? Anyway, I don't know if you can type in the #include for the servo library, it seems like you should be able to, but what I did is Sketch>Import Library>Servo in the IDE. Also, have you looked the Servo library documentation? It explains a couple of the quirks with Arduino 0017 (but they make it better over all). when I made this I had the servo signal attached to pin 9, but they've changed the library since then, so now you can attach a servo on any pin. Here's the link -> .

    sorry for the late reply...

    I actually figured this out a couple of days ago. You are right, I can't just type in the #include. It has to be imported from the sketch library as you mention. Crazy huh? Maybe that can be fixed on the next software upgrade. I think I'll put in a suggestion on their site.

    I program for a living, and this just wasn't intuitive to me. All other programming languages I've used would have picked up on the special characters when doing an include, and would have "included" it on the fly.

    Either way, thanks for your insight and response. It was spot on.

     Huh, I never knew you couldn't just type in the #include. Well, problem solved.

    Man, i was about to read through this instructable...but allsteps is gone, its too frustrating...