The Snap-O-Lantern is a robotic mini-pumpkin. Normally, it just sits there, in disguise as a boring old pumpkin. But, every twenty seconds he comes to life. His LED eyes turn on, his jaw slowly opens, and then SNAPS shut– and he goes back into stealth mode.
What’s inside? A small hobby servo motor, driven by an AVR microcontroller. This is a minimal microcontroller project, and is very straightforward if you happen to already have a setup for programming one. We’ll walk through the carving, setup, programming, and electronics. This is an open-source project, one of the world’s first “gpl-o-lanterns”; source code is provided.
The first task is to carve the pumpkin. It needs to have big pointy teeth in the front, and a hinge in the back. We’ll use a simple friction hinge, and the big pointy teeth help to realign the pumpkin’s mouth when it snaps shut.
Start with a large-ish mini-pumpkin. Pick a side to be the face and draw some big pointy teeth on it using a fine-point sharpie. The ink can be removed later, if necessary, with rubbing alcohol.
Away from the teeth, simplify the pattern to a simple cut, and on the side exactly opposite the center of teeth, mark a shape like so. This notch, an inch or two wide, will form the basis of a hinge.
Using a very sharp knife, carefully cut along the pattern that you have made. This should completely separate the top and bottom halves of the pumpkin.
Using a spoon or other appropriate tool (like the melon baller shown here) scoop out the seeds and loose pulp from the inside of the pumpkin.
The proto-hinge at the back of the pumpkin presently consists of a wide tongue that sticks out below the top half of the pumpkin, and a matching slot in the bottom half. We want to be able to tip the lid back on that slot easily. To make this possible, we need to angle the top inside surface of the slot.
Make a guide mark below the top of the slot, and cut the surface of the notch at an angle such that the lid can tip back easily, virtually hinged at the point where the two pumpkin halves meet. Look carefully at the photos to make sure that you see where the cut needs to be added; you can always click on the photos to get a closer view.
Now it’s time to turn that proto-hinge into a real pivot hinge. (There are several other good ways to make the hinge work– if you have another way that you like, go right ahead.)
The basic idea is that we add two toothpicks to the back of the lower half of the pumpkin. The tongue and slot prevent side-to-side motion while the toothpicks prevent the lid from sliding backwards and provide friction against sliding upwards. Then, when we push up on the upper front teeth, the jaw tends to open neatly, and fall back into place when released. Insert the toothpicks as shown in the photo (you may want them a little more vertical than this) and trim them so that only about 1/2″ of each toothpick is visible.
Now that we have a working hinge, we come to the electronic portion of the project. Here is the list of parts:
- 4.5 V – 5 V power source. Suggested: a 3xAA battery pack with alkaline batteries.
- RC hobby servo motor. Suggested: medium-small model such as Hitec HS-81
- Two LEDs, red, orange or yellow.
- Two 1 k resistors
- ATtiny2313 microcontroller and programming setup
- 20-pin DIP socket for ATtiny2313 (optional)
- 2×3 DIP header
- Hookup wire
- Pad-per-hole circuit board or similar protoboard
Download the firmware for the project here (12 kB .zip file). If you already have a working setup for programming AVR microcontrollers, you probably already know what to do. Unzip the file, customize the header of the makefile to reflect the programmer that you use and which port it is on, and run (in a terminal) “make all”, “make program” to compile and flash it. If you have a more specialized programming environment, you can use that instead without any worries– just make sure to copy over the fuse settings from the makefile.
If you are new to programming AVR microcontrollers, or to microcontrollers in general, start here for a great overview. (See also our list of AVR resources.) You will need a to set up a tool chain of (free, open-source) software and some programming hardware.
The rest of the parts are set up as shown in this diagram:
Wire up the battery pack, positive side to pin 20 of the ATtiny2313, negative (“ground”) side to pin 10. Use the 2×3 DIP header as a pair of standard servo connectors, where the signal sides come from pins 12 and 13 of the chip, the middle pins go to the positive end of the battery, and the other two end pins go to the negative end of the battery. Finally, two LEDs with 1k series load resistors go between pins 8 and 9 and ground. Instead of wiring the LEDs directly on the board, put them on the end of long wires so that they can be placed as eyes for the pumpkin.
Set up the servo motor with a single long arm. If you don’t have one, you can superglue a piece of plastic to a shorter servo output wheel or horn. Connect the servo motor to one of the two servo outputs of your circuit, paying attention to the polarity. (Typically, the black wire goes towards the side that’s connected to ground.) Every 20 seconds, the LED eyes should turn on, and the servo should begin to ramp between two positions and then snap back to the original location. The two different servo outputs give two different ranges that should accommodate some variation in pumpkin size and servo throw. Set up the servo so that it can fit inside the pumpkin when it is in the “off” position and then opens up as the servo arm moves. You will need to hold the servo motor in place. Toothpicks work well for this purpose.
Next, attach the LED eyes. For very small pumpkins like these it can be hard to wire the LEDs inside the pumpkin itself. A good compromise is to attach them directly to the top, anchoring the wires by hand inserting staples. If you do use a larger pumpkin (perhaps pie-pumpkin sized) , you may well be able to fit the microcontroller, LEDs, and battery all inside the pumpkin itself. On the other hand, the servo will have to work much harder to lift the additional weight.