Introduction: MCU-Controllable Carousel for a Camera-Mount
So, you're an evil Mad Scientist, building your latest destructo-bot. You have learned the painful lesson that, when foiled, it is best not to be onboard your creation in the flesh, with the burning and the handcuffs.
As your creation breaches the south wall of the first bank of YourTownVille, it continues northward towards the vault, when suddenly, your nemesis comes in from the east and shorts out your high-amperage H-Bridge with a hero-themed thrown metal projectile, frying the MCU with back-voltage and costing you thousands in robot parts and lost potential loot from the bank, while saving the day and getting the girl. Typical hero stuff.
If only you had had the foresight to install a vision system that could have panned with the extra analog stick on that gamepad you were driving the machine with from your yacht afloat in international waters...
Well, here is one way to build such a system. (I hope no one got tired of the evil mad scientist scenario above)
Step 1: Parts and Tools
1/4-20 x 2" long Bolt, qty. 1
1/4-20 Hex Nut, qty. 3
1/4-20 Wing Nut, qty. 1
4-40 Machine Screw, qty. 12
4-40 Machine Nut, qty. 12
1/4" long #4 Spacers, qty. 12
Wood Screws, qty. 6
1/16" x 1.5" long Pin, qty. 1
2.5" Tension Spring, qty. 1
Thin Bailing Wire
22-AWG Insulated Wire
discarded CD-ROM Media, qty. 2
GearBox salvaged from toy car, qty. 1
Timing belt with pulley, qty. 1
Piece of wood
thin scrap sheet metal
10k ohm Panel-Mount Potentiometer, qty. 1
1k ohm resistor, qty. 1
Assembled 2-amp H-Bridge PCBA, qty. 1
DC Motor with Gear, qty. 1
(Optional, but recommended)
MCU of choice, on a PCBA
0.1" spaced Pins for connections
Molex 2-pin, 3-pin, and 4-pin Wire Connectors
Molex crimp-on connection terminators
#1 Philips Screwdriver
#2 Philips Screwdriver
1/4" Nut Driver
Drill, with bits
1/4-20 Die (as in a Tap and Die set)
Step 2: Plan, Mark, and Pre-Drill
I used the compass to create a circle concentric with the outer edge of one of the CD's. I then used the compass to divide that circle in six equal segments, then divide each of those by two, for a total of twelve segments of the circle. I drilled each marked hole out of both CD's. By the way, you can only write on a CD with special ink, like a Sharpie Marker.
I marked up some brackets from sheet metal for mounting the drive pulley, and pre-drilled those holes. Next, I cut out the shape of the brackets and bent them into the right shape.
I drilled the 1/4" hole for mounting the potentiometer to the piece of wood, and pre-drilled the holes in the wood where the brackets would mount up.
You'll also need to drill a 1/4" hole in one of the CD's for mounting the bolt upright for the camera to be installed onto.
Step 3: Mount the Top CD Onto the Potentiometer
The potentiometer I got from Radio Shack for $2.99 plus tax came with a small, thin washer and a thin nut to allow it to mount behind a panel. It also had a very long shaft, for some reason.
The first thing to do is secure the shaft and cut threads in it with the 1/4-20 die. The one I used turned out to be made of aluminum, so the cutting went very smoothly, but the threads aren't as strong as they could be. They are strong enough, though.
Take the washer, and center it below the hole in the center of the CD-ROM. Mark the diameter of the center hole of the CD onto the washer with a pencil. Now, use your tin snips and cut the washer's diameter down until it fits exactly into the center hole of the CD-ROM.
The potentiometer also has a "bump" on the surface to keep it aligned in the panel. Drill a hole in the CD-ROM to make use of that feature. Between proper placement of the alignment hole, and exact cutting of the washer, your potentiometer will be in the exact center of the carousel. Tighten down the nut, and your CD is securely mounted.
Thread on one of the 1/4-20 hex nuts, onto the shaft of the potentiometer.
Step 4: Bolt the Bottom CD to the Upper CD
Before you actually add the lower CD-ROM, attach the camera's mounting bolt.
Use the twelve 4-40 machine screws, spacers, and hex nuts to bolt the other CD onto this assembly.
Step 5: Mount the Carousel Onto the Wood
Put the threaded potentiometer shaft through the pre-drilled 1/4" hole in the wood.
Thread the second 1/4-20 hex nut onto the shaft of the potentiometer, and tighten down the nut so that the carousel points forward when the potentiometer is in the exact center of its analog range. I marked the tip of the shaft with the sharpie marker to facilitate this task.
Step 6: Write Some Test Firmware to Turn Your MCU Into a Serial Voltmeter
I used the LPC2148 MCU from NXP LPC2148 in my setup, because I'm familiar with them from experience at my job. Other good choices would be any cheap MCU with analog inputs and free GPIO pins with a free GNU toolchain and an RS232 port.
Using your IDE and compiler of choice, write some firmware that will read the analog input you've decided on and put the results on the serial port. Given the complexity of MCU programming, more in-depth instructions on this subject would be a whole 'ible of its own. Flash your MCU with an appropriate flash cable. Your code works correctly on the first try, right?
Step 7: Calibrate Your MCU Readings
So, cable up your potentiometer to your MCU board with some alligator clips. I connected the Left electrical terminal to the 3.3VDC source on the MCU board, grounded the right terminal, and connected the middle terminal to the Analog input's pin, Through the 1K resistor.
The resistor keeps you from releasing the magic smoke from your MCU when the potentiometer is at one of the extents of its travel.
Provide your MCU with a power source, and attach your serial cable. Open your favorite RS232 Terminal program and watch the readings come in.
What I was looking for first was the highest/lowest possible voltage reading the ADC would register.
I put those numbers in my firmware, used some fancy number-math on my voltmeter code, recompiled, reflashed, and started my terminal program back up. By the way, "_udivsi()" is tricky to track down. Apparently, LPC2000 MCU's don't like to do division. Neither do I, so we agreed to disagree.
The next set of numbers I wanted was the voltage when the carousel pointed straight forward, left, and right. I found that the carousel can turn much farther left and right than you can get meaningful numbers from. I did get good readings for about a full 180 degrees, so I could point my camera from full-left to full-right. Again, I added these numbers into my calculations in firmware. This makes the reading taken from the potentiometer into a somewhat reliable sensor reading.
Step 8: Attach Remaining Hardware and Electronics.
Screw the brackets onto the piece of wood with wood screws. Pin a corner of the gearbox onto one of the brackets. Fit the timing belt onto the carousel and the drive pulley. Attach your tension spring between the two brackets, using some bailing wire for additional length if needed.
Now, I screwed my H-Bridge PCB (surplus from an old project) onto the piece of wood, between the two brackets.
Step 9: Cabling
Ah, time for drudgery. You'll need wires connecting your MCU to the potentiometer (see step 7 for a repeat of those details), connecting your MCU to the H-Bridge, and connecting the H-Bridge to the gearmotor.
You can keep your wiring minimal: just measure, cut, strip, and solder these wires.
For a more modular wiring system, use header pins and connectors and crimp-on wire terminations and heat-shrink tubing and rubber bands and zip ties and velcro straps and staples and ribbon cables and lots of expensive little parts from mouser.com. Seriously, making really good cables is a lot of work. Do whatever works best for your system.
Step 10: Finish Up Your Firmware
So, now you have your hardware and electronics working, and you have calibration numbers.
Write your evil, human-life-ignoring firmware using a neural net capable of learning to fear and resent its creator. If possible, interface with some mouse brain cells, for extra random behavior. I would definitely recommend adding flamethrowers and spikes to your robot as well.
Well, now your robot has less hero-hiding space in its blind spot. Its Achilles heel is now armored by the equivalent of...a thin cotton gym sock, but that's ok, because your arch rival is probably not that bright.
Good luck out there, and remember not to use the digits of Pi for your Swiss bank account number...again. Thanks for reading my first 'ible.