I've been interested in robotics for a while now, but the need for proper parts, designs, and materials have made simple experimentation too expensive for my taste. That's where this project comes in. It provides an easy way to hook K'nex motors up to electronic circuits, turning K'nex into a useful robotic building medium.
This project pairs well with my K'nex Rail Cart, allowing you to build a semi-controllable robot with only one motor.
Notes: This project requires basic soldering skills and techniques. Soldering can result in burns, so be careful and use common sense. I assume no responsibility for any injuries incurred during soldering.
In this Instructable, I will refer to the complete motor assembly as a "K'nex motor", and refer to the internal motor as simply a "motor".
Step 1: Materials and Tools
To perform this hack you will need the following materials.
- 1x K'nex motor, any color (keep in mind that, because each color has a different speed, the insides may differ from those of this motor)
- 1x Arduino (or any other microcontroller)
- 1x battery for Arduino
- 1x computer
- 1x programming cable for Arduino
- 2x AA batteries for motor
- 1x breadboard (doesn't have to be very big)
- 1x L293D dual H-bridge IC
- Some wire (color-coded is best, I used red, black, green, and yellow wire)
To perform this hack you will also need the following tools.
- 1x X-Acto knife, or other craft knife
- 1x Phillips head screwdriver
- 1x pair of pliers
- 1x pair of tweezers
- 1x wire stripper
- 1x multimeter
- Soldering equipment (iron, solder, desoldering wick, sponge, etc.)
Step 2: Open the Motor
Take the K'nex motor and look at all its sides. You should see six screws, five on the right side, and one on the back. Unscrew them all, and remove any batteries from inside the K'nex motor.
Next, take your X-Acto or other craft knife and carefully cut the "K'nex" sticker straight down the middle, the long way. Using a thinner knife will result in a less noticeable cut, which is why I used an X-Acto knife. Rotate the K'nex motor so the side with the screw holes is facing up, then grab both halves of the K'nex motor and pull them apart.
Step 3: Remove the Mechanisms
The next step is to remove almost everything from the K'nex motor, to make our job easier. Remove the gears first, taking note of which gears go on what axle, and in what order. Then, carefully remove the motor, switch assembly, and battery contact plates. You can now set aside the K'nex motor body and gears, as this next part will not require them.
Step 4: Modify the Electronics
Now that we've removed the electronics, it's time to modify them to be Arduino-compatible. Before doing this, however, take note of where the green and white wires connect on the motor. I found that giving the white wire power made the motor go forward, and vice-versa for the green wire. By remembering which wire goes where, you can make it easier on yourself later. Also note that the large battery contact plate is connected to positive, while the small one is negative. We will be desoldering the existing wires, and replacing them with longer, breadboard-friendly wires, so warm up your soldering iron.
Desolder the existing wires from the motor, and from both battery contact plates. Set the switch assembly aside, then solder longish (around 6 in.) wires to the motor and battery contact plates. Check your soldering job, and if all looks good, you can unplug your iron and move on to the next step.
Step 5: Reassemble the Motor
Now it's time to put the K'nex motor back together. Put the two battery contact plates in, positive first, then negative. Remember that the positive plate is larger than the negative, so the two plates should only fit in one way.
Next replace the motor. The wires should fit tightly next to the motor, so you may need to use some force to get them in. If your soldering job is good, you shouldn't have to worry too much about damaging the wires. Then replace the gears, making sure you have them in the correct order. If, for some reason, you didn't note the correct order, you can check the list below.
I replaced the gears for my green K'nex motor in the following order.
- Yellow gear with cylindrical attachment, with the cylinder facing down. This gear goes on the right axle.
- Yellow gear with small inner gear. This gear goes on the left axle.
- Yellow gear with medium inner gear. This gear goes on the right axle.
- Shaft assembly. This slides in last, and meshes with the top gear.
Next, run all four of the wires out the hole where the switch used to be, and snap the two K'nex motor halves together. You may need to use a bit of force to get the two halves together, because of the new wires.
The final reassembly step is to replace the batteries, then screw the battery cover back on.
Step 6: Test Your Wiring
Now that our motor is reassembled, it's time to check and see how the connections work. First, grab your multimeter, and test the power leads, connecting positive to positive, and negative to negative. The meter should read around +3 volts, which means that the batteries are good, and have the correct polarity.
Next, connect the power leads to the motor drive wires. Since my wires were color-coded, I attached black to green, and red to yellow (or white). This setup should make the motor go forward.
Thus, from this short test we find:
- Red is +3V
- Black is 0V (or GND)
- Green is motor negative (or backward wire)
- Yellow/white is motor positive (or forward wire)
Now that we've established which wire does what, it's time to make our motor driver circuit.
Step 7: Breadboard the L293D
The L293D is a robust chip that makes driving motors very easy. It also allows use of a dedicated motor power source, which is why we're using it, instead of driving the motor directly from the Arduino (which is a very bad idea).
I've included a Fritzing image of my circuit, which shouldn't be hard to follow. If you'd like to see documentation for the L293D, you can check this website for a datasheet, and this website if you just need the pinout.
Check your circuit once it's complete, to make sure there aren't any mistakes, then move on to the software.
Step 8: Programming the Arduino
I've written a simple "back-and forth" program for the Arduino, which will act as the "hello world" program for this project. It's attached to this step; simply download it, place it in a folder with the same name, then place that folder in your sketch folder. Finally, open it with the Arduino IDE, and upload it to your board. Congratulations! You've turned an ordinary K'nex motor into a "smart" Arduino-controlled motor!
If you've been following this guide exactly, then digital pin 5 will be your forward pin, and digital pin 7 will be your backward pin. To drive the motor forward or backward, set these pins HIGH or LOW in the following manners:
- Forward pin HIGH, backward pin LOW: Motor goes FORWARD
- Forward pin LOW, backward pin HIGH: Motor goes BACKWARD
- Forward pin HIGH, backward pin HIGH: Motor does not move
- Forward pin LOW, backward pin LOW: Motor does not move
To write your own custom movements, simply set the proper pins HIGH or LOW, then use a delay() function to wait the proper number of milliseconds. Also keep in mind that, because the K'nex motors are DC motors, they will be very imprecise, making precision movements or K'nex CNC machines impossible.
Step 9: Going Further...
As I said at the beginning of this Instructable, this Arduino motor goes well with my K'nex Rail Cart. If you want an extra challenge, you might try combining the two projects. Or, maybe you could use two Arduino motors and create a steerable K'nex robot. Who knows what you might create?
If you do create something cool using this idea, I'd love it if you'd post a link in the comments, so I can see what you've made! If you happen to have a question, just post a comment or send me a message and I'll see what I can do.