I designed this as a craft project for the younger kids at a family reunion. The kids were given an assembled and tested board, and allowed to decorate it with foam, pipe cleaners, and feathers using hot glue. It was a big hit, and the creations that ensued were fascinating.
The real fun is getting two Buggies together. They emit and detect IR and so can "talk" with each other.
There is plenty of memory left on the chip, and several unused inputs, and given my programming ability, lots of room for improvement. I hope others find this intriguing enough to try and improve on.
Hats off to Alex Weber's programmable LED instructable (http://www.instructables.com/id/Programmable-LED/) which sparked my imagination!
<SHAMELESS PLUG>If you like this idea, give it a rating on the right, and vote for it at the top! I'll give you a free Instructables membership! Thanks</SHAMELESS PLUG>
Step 1: Devil in the details . . .
The Atmel Attiny44v AVR is a 14-pin microcontroller with 4K bytes of flash RAM and 256 bytes of SDRAM. The chip has an internal 1 MHz oscillator, 8 and 16 bit counters, and analog to digital converters. It will run with as little as 1.8V. I used the DIP package and a socket so it can be removed for reprogramming. There are several unused ports available for hackery.
The LED eyes are connected to two ports (PA4/PA5) instead of a port and ground. This allows sending juice either way so we can light up bi-colored LEDs (see schematic).
For both sensors, power is supplied via PA1 only when a reading is needed to save juice. ADC readings are taken on PA0 (IR) and PA2 (visible), each with its own voltage divider resistor (R1 & R2).
An IR LED and current limiting resistor are connected on PA3 so it can be lit separate from the eyes.
Sound is generated on PA6 using pulse width modulation from the 16-bit counter and a piezo-electric speaker.
Power is from a CR2032 lithium coin cell which is the cheapest, easiest to find 3V source I could find. From Digikey they are about $0.28. Why they sell them in the store at $4 is beyond me. I included a 0.1uF capacitor to remove noise. It is optional.
A normally open push-button switch is connected to PA7 and used as a pin change interrupt to change modes or power down.
Nothing too terribly tricky or clever. Remember, I’m a beginner. This is my first design. Let’s see if we can build one . . .
Step 2: Got to have some skills . . . and tools.
Disclaimer: I've built more than a dozen of these so far. They worked, to the amazement of my friends and family, but I'm an amateur. I can't guarantee it will work for you. I can't guarantee how long they work. Look at the project name, "Buggy"! I'll make a reasonable effort to help you get yours working. I'll keep updating design as you figure out my mistakes and how to make it better.
Skills you'll need to buy, beg, borrow, or just learn:
- PCB board making: I'm not going to teach you. It's on the web. I made mine in my garage. They are single-sided. I used the toner-transfer method with about a 50% percent success rate (just scrub it clean and try again). I used muric acid with peroxide to etch. Careful, careful, careful! I'll provide you with a bitmap to print or my CadSoft Eagle files to tweak. If you are interested enough to get some manufactured, put me down for a couple!
- AVR programming: The chip needs to be programmed. I'll provide you my "firmware", but getting it onto the chip is a trick. I used LadaAda's USBtinyISP kit (http://www.ladyada.net/make/usbtinyisp/). She has a pretty good tutorial on her website (no affiliation, but she knows her stuff). If it is just microcontrollers you are interested in, try LadyAda's boArduino kit (http://www.ladyada.net/make/boarduino/). That will keep you busy for a while.
- Soldering: I found soldering on homemade boards to be a bit harder than on manufactured boards. Flux helps. If your skill needs brushing up like mine did, try LadaAda's Game of Life kit (http://www.ladyada.net/make/conway/).
- Patience: In my homemade experience, nothing works the first time. There is always a reason. Sometimes it takes time to find the reason. The harder it is to find, the more I learn. I learned quite a bit doing this. I'm learning more as we speak.
Tools you'll need to buy, beg, or do without:
- A high-speed rotary tool (pronounce "Dremel"). Dremel has a drill bit kit with 1/32" and 3/64" bits (and on up to 1/8"). The 1/16" bit that came with your drill is going to rip the pads off of the board. That will make soldering tough. I only used it for holes that the pipe cleaners were going through.
- A good work light is a big help when you are looking for solder shorts!
- Soldering Iron.
- Side-cut pliers.
- And the rest of the stuff you hopefully already own.
Step 3: Piece by piece . . .
Part Digikey Number
(1) Attiny44v MCU P/N ATTINY44V-10PU-ND
(1) IC Socket P/N 3M5474-ND
(1) Switch P/N SW400-ND
(1) Speaker P/N 102-1616-ND
(1) Battery, 225 mAh P/N P189-ND
(1) Battery holder P/N BS-3-ND
(1) IR emitter P/N 160-1028-ND
(1) IR detector P/N 160-1030-ND
(2) Red/Green LED P/N 160-1037-ND
(1) 0.1 uf cap P/N BC1160CT-ND
(1) RadioShack CdS cell (comes in 5/pack)
(1 ea.) 1000, 330, and 150 ohm resistors
(1) Single-sided 1oz copper PCB at least 1" x 2"
Heatshrink tubing (optional)
Step 4: Buggy Boarding . . .
If at first you don't succeed, try, try, again. It took me several tries before I got a usable transfer. You can do some touch up with a Sharpie marker, or just scrub it clean and try again. I'm getting better at it. The deadline for the project was too close, or I would have looked into having them manufactured. If you go to that trouble, put me down for a couple.
Drilling the board was a bit of a trick as well. Dremel has a drill bit kit that has 1/32", 3/64", and 1/16" bits. I made a diagram (below) to show what pad is drilled to which size. Wear a mask. Breathing fiber glass dust is not recommended. The hole for the speaker is ½” . There is pad there to act as a pilot hole.
Step 5: Chip Socket Chipping
Once you have it trimmed, insert it into the board with the trimmed section in the correct orientation (see photo 2). Make sure you don’t fold a contact over (done that). You should be able to see the four holes for the resistors in the middle of the holder. Solder it in.
Step 6: Resistance is futile!
Now put in R2, which is 1000 ohm. When you get it in, make sure the legs of R1 and R2 don’t touch in the middle (see picture 3).
Step 7: Front End Work
Now for another sub-optimal trick. Insert the CdS cell as shown. One of the legs shares a hole with the detector (picture 3). If the don’t both fit, drill it out a bit. Try to leave some pad on the backside, but it is not critical. The leads just need to be solder together.
Resistor R3 (150 ohm) also shares a hole with the emitter (see picture 4).
Double check you’ve got the emitted and detector in the right places (I’ve switched them more than once), and solder away. See if you can do a better job than I am in picture 5!
Step 8: Light em up
Just make sure you have the long legs of the LEDs to the outside (see picture 1). I put heatshrink on the legs and leave them long so they can be moved around latter. To get them equal, hold them together and put a 90 degree bend in all the legs at the same time with pliers (picture 2). Drop them in the correct holes (long leg on the outside).
Step 9: Home stretch . . .
Now for the speaker. The red wire goes next to the switch (picture 2). Polarity does matter. Don't use the battery holder hole in the middle. Solder the leads in place.
The battery holder needs a tweak. One of the legs is in the way of where we want the speaker to be. Trim it off with a knife (picture 3).
Push the speaker through the opening and put the battery holder in place (picture 4). Solder it in place.
The speaker is loud, even using just three volts. I put a small square of double-stick tape over the opening, and then tape the opening to the bottom of the battery holder. That leaves it flush with the bottom of the board (picture 5).
You can use an old toothbrush and alcohol to remove the flux if you are as sloppy as me.
What are the odd that it works? Time to find out . . .
Step 10: Finishing Up
When putting the chip in, the #1 pin goes to the side of the chip socket that was trimmed away (opposite to the side the button is on).
Hopefully you figured out how to program a chip. If not, head on over to LadyAda's place (http://www.ladyada.net/make/usbtinyisp/).
I wrote a test program to verify Buggy's operation (Buggy44Test.hex in the zip file below). It will flash the LEDs briefly (both colors if bi-colored), make a chirp on the speaker, and then flash codes out to indicate the sensor readings. Count the green flashes (or high tones) for each digit. A zero is a red flash or low tone. There is a pause between each digit. There is a longer pause between the readings. Visible light is first, followed by IR. It then repeats. If you have single colored LEDs, the tones are all you have (single color LEDs flashes same as red, so you probably wont see much)!
For the sensors readings, you are looking for a number between 0 and 255. Visible room light should put you mid-range, say 70 - 120. Dark is about 30. Bright direct light will likely get you a blinding 255!
As for IR in ambient room light, you are looking for something on the low end, say < 30. If you hold it up to an incandescent or the sun, you should get higher. If you get zero with an incandescent, something is wrong. For me it usually means I switched the emitter or detector or put the detector in backwards (no, say it isn' so).
These values are all fairly arbitrary, and depend greatly on the sensors and resistors you use. Every one I have built has had a different response. I tried to optimize the design for room light, but then again, I am an amateur. Hack at will and let me know what you come up with.
When you are satisfied, load the real program and give it a test. Use Buggy44biColor.hex if you have bi-colored LEDs. Use Buggy44oneColor.hex if you have a single colored LED. Getting the chip out is a bit of trick (see picture 2). Always take the battery out first to avoid shorts or damage to the chip.
Step 11: A Craft Project, did you say?
Kids will probably need help getting pipe cleaners legs on in a safe and secure manner. I feed the cleaner through one hole, bent a j-hook, and pulled the end back through the other hole before bending it over (picture 2). Remember, the center of most pipe cleaners contain a magical electrical conductor called a "metal wire". Watch for shorts, especially with the holes near the eye LEDs. The foam base mentioned above might help there as well.
Let me know what you come up with. I've started a blog over at http://www.projectbuggy.blogspot.com/. You can learn some background on the project, see the kids at work, and see what kind of Buggies have evolved. You can pay me back for all this by SENDING ME A PICTURE of your creation. I will post it on the blog.
What is next for Buggy . . .
Step 12: Next stop . . .
Here are some thoughts I had on where to go next:
- Personalities? Alter the programming so each bug has a distinct behavior. Angry, happy, sleepy.
- Temperature dependent behavior? The chip has an on board temperature sensor.
- Jar of Fireflies? Buggy's platform would work for any number of LED projects. You could use the unused ports, or multiplex an LED array using the IR and VIS sensor ports.
- Hijack a RadioShack 'HexBug'? Replace the electronics and you could program in some cool behaviors like hunter / prey with the IR. The chip will source 40 mA on the ports, which might be enough to run the motor directly.
- Songs? I've only got an octave programmed in Buggy. It wouldn't be hard to double that and have it play some melodies like ring tones.
- Practical joke? Program the board to chirp randomly and tape it under someone's desk. Have it go off at a random time every other day. It would drive them nuts!
- TV-B-Gone? Use the IR to turn off TVs at random times!
- Motion sensor. I put one on a shelf facing a lit window, and it would go off if you walked by. It drove my wife crazy!
- There must be a million others. Let me know what you think.
Good luck, and have fun.