You got your Arduino and you got your Servo...

Here's a cool little program I wrote that will allow you to exercize that servo to your hearts' content. You may find some of the supporting code useful as well!

There's really no other Parts List, so we'll just jump right into the Set Up and then on to the Code.

In this example, I connected the Signal (Yellow) wire of the Servo to Pin 9 of the Arduino.

I picked +5VDC and Ground off the ICSP Connector: Pin 2: 5V and Pin 6: GND.

For my test purposes, I kept this Duemilinove connected to the USB Port of my computer. You can use a Wall-Wart or Battery Pack (for portability) to power your device as well.


The photo attached to this step depicts the Operator Display that the program will put up on the Monitor Screen in the Arduino Development System or in HyperTerminal. All you need to do is match the Terminal Speed to the Code; in this example it is 115200 BAUD.

Once the screen comes up, enter any key to begin. Note that in the Development System, you must click into the Output Field, type your output, and click on SEND. In HyperTerminal, you simply type away - in most cases the program responds to single key entries.

's' Reduces the Speed and 'S' Increases the Speed at which Sweeps Occur.
'i' and 'I' Control the Move Increment - How many uSecs the Servo is moved at each step.
'd' and 'D' Control the Delay between each Sweep.
'n' and 'N' Set the Minimum Sweep Position.
'm' and 'M' Set the Maximum Sweep Position.
<Space> Pauses Movement.
'?' Displays the Current Values of Min, Max, Speed, Increment, and Delay.
'C'  Sets whether to Pause as the Servo passes the Center Position.

'l', 'L', 'r', and 'R' Activate Manual Mode. Automatic Sweeping is Suspended.
     'l' and 'r' move the Servo Left and Right 1 uSec on each key-press.
     'L' and 'R' move the Servo Left and Right 10 uSecs on each key-press.

'X' Resets all Variables to their Default Values.
'Z' Stores the Current Values to be Recalled upon the next Initialization of theProgram.
'P' Allows a Position to be Entered Manually. Automatic Sweeping is Suspended.
Hey if you want to use STDIO.H functions like printf, why not just redirect the stream right into the serial port instead of into a string that is literally named &quot;String&quot;? That confused the heck out of me.<br><br>Also I'm fairly certain that new-line sequences are usually \r\n and not \n\r, I doubt it makes a difference in most cases but somethings might not recognize \n\r<br><br>Another point, using println instead of manually inserting \r\n might be a better idea as a habit, because the code is more platform independent that way (as in, Windows uses \r\n but Unix uses just \n, but using println means you don't have to care).<br><br>I know my comments have nothing to do with microcontrollers but still I'd like to help
As an old school C Programmer, I use sprintf to preformat strings before sending them out to the display. And, we didn't have println, so I use &quot;\n\r&quot; ot &quot;\r\n&quot; purely by habit. I do use println on occasion, but actually had some problems with it in one project talkiing over a marginal serial line. <br> <br>Thanks for the suggestions!
Hi,<br>Do I copy and paste the code into a sketch in the IDE, if so I get errors when compiling.<br>Thanks <br>Geoff
Somehow I got a space character between a few of the logic OR statements making them look like &quot;| |&quot; instead of &quot;||&quot;. I fixed those and verified that C&amp;P into the Dev Sys compiles without error. <br> <br>Thanks!
why didnt u use the 5v and ground pins from the rails instead
For my Test Porpoises ;~) I simply picked the most convenient place, and it has male pins that matched the female pins I pulled out of the servo connector. As far as I can tell, it's all the same after the 5V regulator. <br> <br>EVEN EASIER would have been to swap a couple of pins in the servo connector, or (better yet) make an adapter cable to do it, so that the pins were +5, Signal, and Ground, in that order. Then I could have simply plugged it onto pins 2, 4, and 6, all in a row, on the ICSP connector, and called Pin 11 my Signal line.

About This Instructable


45 favorites


More by kayakdiver: Arduino Controlled Servo Exerciser Arduino Controlled SIP & PUFF Switch ADAPTIVE SEAT FIXTURE FOR KAYAKING
Add instructable to: