3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Controlling an RC Servo motor with an Arduino and two Momentary Switches

Controlling an RC Servo motor with an Arduino and two Momentary Switches
«
  • DSC00374.JPG
  • DSC00375.JPG
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.
 
Remove these adsRemove these ads by Signing Up
 

Step 1Parts List

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.
Amazon

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

« Previous StepDownload PDFView All StepsNext Step »
23 comments
Jul 31, 2011. 6:23 PMledfreak101 says:
how do you keep it going in one direction ?
Jul 10, 2010. 9:27 PMMichael_oz says:
The Constrain should either be directly before the write, or after the if.
Mar 16, 2010. 2:50 PMmigeria says:
A jumper kit is nice, but you can also salvage them from different kabels. 
Jan 11, 2010. 9:50 AMCementTruck says:
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).  : ( 

Thanks!
Jan 25, 2010. 3:26 AMCementTruck says:
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.
Oct 9, 2009. 7:13 PMReCreate says:
Man, i was about to read through this instructable...but allsteps is gone, its too frustrating...
Jun 26, 2009. 11:12 AMReCreate says:
So i suppose you got it to upload the code now ;)
Also, I found the best deal, From the arduino website so it is legit, its 28 Dollars, you save like 3-5 Dollars!
http://store.gravitech.us/ardu.html
That is where i am buying mine, Good i'ble Rated ;)
Feb 23, 2009. 2:57 PMclark says:
i just bought an arduino Duemilanove and two servos, sooo pumped to try this!
Feb 24, 2009. 7:33 AMclark says:
oh i know, i'm working on a project and i needed two
Feb 19, 2009. 12:42 PMamando96 says:
does each servo go the opposite direction as the other one? like when one is goin left the other is goin right?
Feb 19, 2009. 2:41 PMamando96 says:
ohhh... then How to i make what i explaned? :P
Feb 20, 2009. 8:45 AMamando96 says:
wrote one, it's getting closer to what i want

// Sweep
// by BARRAGAN <http://barraganstudio.com>

#include <Servo.h>

Servo myservo; // create servo object to control a servo
Servo myservo2; // a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
myservo2.attach(10);
}

void loop()
{
for(pos = 0; pos < 180; pos += 10) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(20); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=10) // goes from 180 degrees to 0 degrees
{
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(20); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos < 0; pos += 10) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(20); // waits 15ms for the servo to reach the position
}
for(pos = 1; pos>=180; pos-=10) // goes from 180 degrees to 0 degrees
{
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(20); // waits 15ms for the servo to reach the position
}
}

Lol try it, and then tell me(i understand your english :P) How to make one start going right while the other one is in neutral... =/

thanks
Feb 20, 2009. 8:27 AMamando96 says:
lol i'm gonna try to write the code, but it's my second day writing codes... xD so if you dont mind, write the code too plz :)
Feb 18, 2009. 11:18 PMNoodle93 says:
Awesome! Looking forward to the video. Arduino is definately fun.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
4
Followers
2
Author:geeklord