Introduction: How to Dynamically Control a Servo or Motor Through Your Computer

Picture of How to Dynamically Control a Servo or Motor Through Your Computer

I have been working on creating the robot I detail in this instructable. To build this the need arises to be able to dynamically control a servo or motor from the computer.

This is my entry for the National Robotics Week Robot Challenge. I am in the 13 to 18 year old category.

Step 1: Materials

Picture of Materials

For this project you will need:
A motor or servo (if you choose to use a motor, you will need the L293D Motor driver)
Picaxe 28X1 board and chip (this can be done with other microcontrollers, but I am using this one)
A computer (Mac or PC, doesn't matter since the code will be on the board itself)
AXEPad (Programming software for Picaxe, can be found for Mac OSX, Windows, and Linux)

NOTE: you will need a soldering iron and solder for this.

Step 2: Hooking Up the Servo/motor

Picture of Hooking Up the Servo/motor

If you wish to use a servo, you will need to solder one pin onto the board, the servo then plugs right in.

If you wish to use a motor, you solder a wire into each of the holes for motor A or motor B, then you solder them to your motor.
You also need to install the motor driver as outlined in the photo

Step 3: Programming

Picture of Programming

Once you have your servo or motor connected, plug in the battery case, put three double A's into it, then plug the USB cable into the board and the computer. After that open up AXEPad. You are now ready to program it.

#Picaxe 28X1
#Terminal 4800
Do
SerRxd b0
SerTxd( "You typed ", b0, CR, LF )
if b0 = "o" then 'the o can be changed to whatever letter you want (in this case o≠O, so you have twice as many options)
servo 0,75 'this should be replaced by the motor command if you use a motor instead, It is high 4, low 5, or high 5, low 4 for one of them, or high 6, low 7, or high 7, low 6 for the other.
wait 2 'this command is specifically for the servo, otherwise it will not turn all the way
end if
if b0="i" then 'again, this can be changed to suit your preferences and i≠I
servo 0,225 'If you use a motor, switch the high and low values
wait 2 'again, you don't need this if you are using a motor
end if
if b0 = "p" then
servo 0, 150 'this centers the servo, put all values on low to stop the motor
wait 2
end if
Loop

Press f4, or go to PICAXE>check syntax to make sure everything is entered correctly, then press f5, or go to PICAXE>program to download the program to the board

Step 4: Dynamic Control

Picture of Dynamic Control

A terminal port will open after the program is downloaded.
type o then press send and the servo/motor will spin in one direction
type i then press send and the servo/motor will spin in the other direction
type p then press send and the servo/motor will stop

Comments

265lutab (author)2014-01-18

how is the board connected to the computer? does it plug into USB or is it connected another way?

bro12345 (author)2012-04-21

Thanks this helped a lot (I used the windows programming editor and it is the same)

About This Instructable

20,252views

19favorites

License:

Bio: I am an Apple Developer in College ultimately pursuing a masters in robotics. If you would like to take a look at my apps, all ... More »
More by A-Nony-Mus:How to use the camera in your iOS programCreating your first iOS appRat-trap powered vehicle
Add instructable to: