Instructables

Arduino Controlled Servo Exerciser

Picture of Arduino Controlled Servo Exerciser
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.
 
Remove these adsRemove these ads by Signing Up

Step 1: THE OPERATOR DISPLAY

Picture of THE OPERATOR DISPLAY
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 "String"? That confused the heck out of me.

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

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

I know my comments have nothing to do with microcontrollers but still I'd like to help
kayakdiver (author)  frank260801153 years ago
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 "\n\r" ot "\r\n" 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.

Thanks for the suggestions!
GeoffN3 years ago
Hi,
Do I copy and paste the code into a sketch in the IDE, if so I get errors when compiling.
Thanks
Geoff
kayakdiver (author)  GeoffN3 years ago
Somehow I got a space character between a few of the logic OR statements making them look like "| |" instead of "||". I fixed those and verified that C&P into the Dev Sys compiles without error.

Thanks!
why didnt u use the 5v and ground pins from the rails instead
kayakdiver (author)  hightekrednek23963 years ago
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.

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.