Thursday, October 7, 2010

Arduino based serial servo controller

introArduino based serial servo controller

This is a simple serial controller for multiple servos based on the Arduino. (my first instructable too :) )

Most of the work in this came from getting the software to talk with the arduino and making a protocol for the data to be passed over. As for the hardware aspect all that I used was two servos (Parallax standard servo here .) A SparkfunArduino ProtoShield and an Arduino Duemilanove with ATMEGA328, but most of these parts can be substituted with similar items.

I thought up this project as part of a RC system, but setting up the communication took a lot of time. If anyone has any improvements, ideas, or bugs please feel free to comment.
EDIT: I wrote this awhile ago, just got to publishing it recently.

step 1Things you may need...

Some things you will need to build this.
1. Arduino board (you choose)
2. two (or one) servos
3. jumper wires
4. Visual Studio 2008 Express -- link (optional)
5. Arduino IDE -- link

Sorry Linux and Apple fans, my program only runs on windows for now, but you can still manually send serial commands to the arduino without changing the code.

step 2Connect the hardware.

Nothing very complex to this step.
Just connect one servo to pin 9 and the other to pin 10.
Connect the hardware.

step 3Program the arduino

now you can upload the sketch onto the arduino.

Here is a simple breakdown to the code:


Servo myservo; // create servo object to control a servo
Servo myservo1;

int incomingByte = 0, datacount = 0, counter = 0, ready = 0; // for incoming serial data
char data[10];
const char verify[8] = "ma11hew";
char command[3];

void setup() {
Serial.begin(38400); // opens serial port, sets data rate
Serial.println("Hi Arduino Here!"); // added to help identify the serial port

This just sets up the serial port and servos.

int i;
for(i = 0; i<180;i++) i =" 0;" ready =" 0;" counter =" 0;" 1="=" counter ="=" ready =" 1;" ready ="=">

step 4Install software

I have two ways to install this...
nsis installer:
Download the self extracting installer below and run it.
You will have the option to install sources during the install.
the installer binary package installs core c++ dlls so it can be run on a computer without visual c++ installed already.
Once the installer finishes you can run it from the desktop or start menu.

zip way (unverified):
Download and run, it should work. maybe.
(The zip archive has the same folder structure created by the installer, without sources. I don't have a machine without visual studio to test it on so it may not work.)


step 5Use the interface program

To use the program first select the baud rate defined in the arduino sketch.
The unmodified sketch defaults to 38400 baud but can be changed to suit your needs for things like a slower radio link.note: baud rates higher than 38400 have not been very stable, I think this is because the uart fills up before the data can be processed.
Next, select the COM port to use. the program defaults to COM4 be sure to change it or the program will crash.
Finally, click open. If all went well the program will open the selected serial port at selected baud rate.
If not the program will probably crash with an unhandled exception. make sure the port is correct and try again.
Use the textboxes to submit direct commands to the arduino. The "map(command[1], 32, 126, 2, 180)" scales all the 94 possible commands, *space* through ~, readable by the arduino in ASCII to 2 through 180 for the servo. any byte less than ASCII 32 (space) or above 126 (~) defaults to 63 (?)

The track bars provide an eaiser interface for direct commands. each step sends a serial command to the arduino incrementally.

step 6Get creative!

Think of cool things to make with this. Some ideas:
1. Remote throttle for a car.
2. 3D camera mount
3. underwater rover

Have fun!!
Related Posts Plugin for WordPress, Blogger...
Disclaimer: All the information in this blog is just gathered from different sites in the web and placed here and I am not the owner for these content

Popular Projects


My Blog List

Give Support

Give Support
Encourage me Through Comments & by Following