Can you tell why I've been excited for this project? Do you know how seriously cool this is?
"No, Jay," I can hear you say, sighing as you fortify yourself for another excited explanation. "Why don't you explain it to us?"
Okay, let me back up and calm down a bit.
I've had the idea for this project banging around in my head for the better part of a year now, and I've been actively working on it since August. All the I'bles I've been posting recently, Metal Wheels, ExternalInterrupts, as well as my two Debouncingtutorials, have been research I've been doing in preparation for this project!
In addition to that, as luck should have it, a couple of competitions have opened up that would fit this project perfectly! So not only is this the fruition of several months of working, it's also my very first competition submission! So if you like this tutorial, or if you're a fan of the For Cheap Robots series in general, please consider voting for me!
Of course all of this is nowhere near as cool as the project itself! Shaft encoders and speed controllers are complicated things, and building one from scratch (not to mention out of craft supplies) is no simple task, but I promise you, we can make it easy!
Let's get started!
For more Instructables on building cheap robots, please check out the For Cheap Robots collection!
For more things that I've done, you can check out my profile page!
For more info from Digilent or the Digilent Makerspace, check out the Digilent blog!
Step 1: What Are Shaft Encoders?
Simple answer is that they're a type of sensor you can use to tell how fast your robot's wheels are spinning.
As your motor or wheel spins, the encoder will send pulses of high and low signal to your robot. These pulses get faster or slower, depending on how fast your motor is spinning. By timing the pulses, your robot knows exactly how fast the motor is spinning, and doesn't have to guess!
This is super important if you want to make very precise movements, and they're used all over the place. In fact, most of the motors in your printer at home will have a shaft encoder.
Problem is, they're not cheap!
In order to make such precise measurements, shaft encoders usually have to be very precisely manufactured. Even cheap shaft encoders from robot kits usually rely on specialized magnets and Hall effect sensors. You can build your own for cheap, using infra-red lights, and there are some pretty neat ways you can salvage optical encoders from old hardware, but I wanted to make mine even more accessible than that.
Step 2: But... Can We Actually Build One From Craft Supplies?
Here's what you'll need!
- Thumb tack, or thin nail (I'm using a finishing nail)
- Phillips screw driver you can abuse a bit
- Sand paper or wire brush. I use a nail file because they're common and work really well!
- Scrap wood or a cutting board you can hammer into
- A gearmotor
- A pair of pliers, to hold the thumb tack or nail
These supplies are for the Metal Wheels tutorial, which this tutorial uses.
You're also going to need the following:
- Scissors or an x-acto knife
- Electrical tape. Other tape will work, but electrical tape is the best.
- Wire cutter
- Wire stripper
- Four lengths of wire (preferably colored)
- Header pins (optional)
- Soldering Iron
- Hot glue gun (as always)
- A small, thin spring. You can find these inside retractable ball-point pens.
That's everything for the shaft encoder itself! I'm going to cover wiring in the next tutorial, when I explain how to actually use this thing.
Step 3: Make Your Wheel
Before you get started on the Metal Wheels tutorial, you're going to want to sand their rims. This is actually a very important step, and can take a while to get right.
Even bottle caps like the Snapple caps I'm using have a thin layer of clear paint on them to prevent rusting. Check out the second picture in this step. Can you see how the area I sanded is a little darker? You're going to want to sand until the entire rim is nicely sanded like this. I recommend pulling up a video on YouTube and spending some time carefully sanding.
After that, use my Metal Wheels for Cheap Robots tutorial to complete your wheels! For this tutorial, don't worry about gluing the completed wheel onto your motor shaft, as we'll be doing some more modifications to the wheel before we're done.
Step 4: Cut Some Tape Pieces
There are two ways to cut tape for this step.
My preferred method is to lay a short strip of tape out on my cutting board, and use an x-acto knife to cut pieces.
If you're not comfortable with that (or if your parent's won't let you use a knife) you can just cut the pieces with a pair of scissors.
Each piece of tape should only be about 1/4 of an inch long (or 6 millimeters if you're using a more sensible unit system). Cut three or four of them. I prefer four, but it's a little harder to fit them all on my wheel that way.
For this step, the length of each piece isn't as important as the width, which should just be the width of whatever tape you're using. This is good, because this means that the width of each piece of tape should be exactly the same.
Step 5: Stick the Tape on Your Wheel
Once you have your tape pieces, carefully stick them to the rim of your wheel. Try to space them evenly, but this isn't very important, so you can just eyeball it.
What is important is to make sure there's a nice, large section of bare metal between each strip of tape. This will make sure that our encoder sensor makes contact with the conductive wheel in between strips of tape.
It's also important to make sure your strips of tape are fairly straight. That's because our encoder will be measuring the width of each strip. (This is also why it was important that they all be the same width.)
Step 6: Sizing the Contact Spring
This is probably the most fiddly step in this whole process. If you're very young, you may want to get an adult to do it for you, because it takes some very fine manual dexterity. If you do want to do it yourself, take your time and be careful to do it right. I know I've gone through several springs myself trying to get this step right.
Slip your wheel onto your motor, and use this to get an idea of how high your contact spring will have to reach (like in the first picture).
(I'd like to point out that in the first picture in this step, I'm not actually compressing the spring with my finger. I'm only holding it so you can get a good view of the spring in relation to the wheel.)
Check out the second picture in this step. See how my spring has a slightly acute angle? My goal is to make sure the spring bends down slightly to touch the rim of the wheel. Furthermore, I make sure to bend my spring slightly too far, that way the tip will press gently against the edge of the wheel. This means that the spring will always be in contact with the wheel (even if the hole I punched previously is slightly off-center).
Once you have a good idea of where to bend your spring, use your pliers to make a sharp bend there. You may want to use two pliers to get a really precise bend for this part.
Step 7: Soldering Wire Connectors
Take one end of one of your wires, and slip it into the base of your contact spring. To do this, slip the wire in between two coils of the spring and rotate until it's pinched between the flat coils at the end. If you do it right, the spring itself will hold your wire while you solder it. I've found that a very hot solder works well here.
If you have them, you can also use this as a moment to solder header pins onto the other end of your wires. I needed to do this because I was using stranded wires that were too thick to fit neatly into my breadboard.
Finally, I glued the other of my two wires directly onto the metal case of my motor. This is important, because the motor case is electrically connected to the metal shaft, which will also be connected to our metal wheel! At the same time, the wheel, shaft, and case are electrically insulated from the motor's inner-workings. This means that our motor case gives us a fixed and constant connection to our metal wheel!
Step 8: Glue the Contact Spring Onto Your Motor
Start by putting a strip of insulating electrical tape over your motor case. We've just connected one wire directly to the case, so we want to insulate our contact spring from that circuit. That way, the connection is only completed when the spring touches one of the bare metal parts of the wheel. See how our encoder is going to work now?
Before we glue anything, we want to get a good idea where our spring is going to go. Slip the wheel back onto our motor, and just hold the contact spring in place. Notice how, in the second picture, the tip of the spring contacts the wheel in the middle of the strip of tape? Remember where the base of the contact spring is going to go, because you'll want to put it back there next step.
Remove the wheel, because this next step is going to happen very quickly and we don't want it getting in the way.
Put a generous amount of glue on the motor case (over the taped-up section). Then, using a pair of pliers to grip the wire connected to the base of the contact spring (as in picture 3) firmly place the contact spring into the glue blob. Hold it steady while it cools.
Once the glue cools, slip the wheel back on and check the spring contact point again. As you can see in picture 4, mine was a little too close to one edge of the tape for my comfort, so I made a small adjustment to the spring by stretching it out. (You can also use your pliers to bend the spring down slightly if the spring does not keep contact with the rim of the wheel.) Be very careful if you're doing this, because you don't want to ruin the spring and have to start over from scratch!
Once you're happy with how your spring contacts the wheel, try hooking your motor up to a battery. That way you can watch the wheel spinning beneath the spring. Keep an eye on the tip of the spring and make sure it always contacts the tape as it passes.
Step 9: And You're Done!
That's our completed shaft encoder!
As you've probably guessed, it acts essentially like a switch. As the wheel turns, the tape breaks the connection between our two wires, and that's what we'll be sensing. Because we know that each strip of tape is exactly the same length, we can measure how long each break lasts, and that tells us our motor speed!
But we're not quite finished! Up next I'll cover how to use a simple PID to control the speed of this motor. Because this is made with odds and ends you can find around the house, we can't just use it and expect it to work perfectly right away. There's a little bit of signal processing that we need to apply, similar to what I cover in my DebouncingInterrupt tutorials.
Once again, this is my first entrance into a competition, so I hope you'll consider voting for me! It's also part 1 of a pair of I'bles that complete this project, so please read my PID tutorial when that comes out!
Thank you very much and I hope you enjoyed this!