Introduction: SpookyEyes Skull
Here is a simple modification I made to a plastic Halloween skull. I drilled the eye sockets and added a couple of red LEDs. The LEDs are connected to a microcontroller for special effects (fade in/out, blink, that sort of thing). There are some additional features of this design:
- Battery powered
- Optimized for long life (I figure 200 hours or more on a set of 3 Alkaline AA batteries.
- Turns on at dusk.
- Runs for N hours (settable by the programmer), then turns off.
- Stays off during the day.
If you are an Arduino enthusiast and all you've ever worked with are the chips that come preinstalled on an Arduino board, then this might be a good project for you to expand your horizons a little bit. There's such a broad range of ATmega chips of various sizes that staying locked to the 2 or 3 devices that are provided by the usual Arduino offerings is rather limiting. For one thing, this project would be done a lot differently if I had to use Uno Rev. 3. That board itself is $22; I'm getting the job done here for only $1.50! Plus, since it's much slower (though plenty fast enough to light LEDs), it uses less power. This means it's better suited for a battery-powered project.
Step 1: Goals
Here they be:
- Create spooky red eyes in the eye sockets of an otherwise humdrum cheap plastic Halloween skull.
- To power it by batteries.
- To have it run for a good 2 weeks or so on said batteries.
- To have an expiration date. I live in an area where cool things left out in front have a tendency to walk away. (Scary right? I mean, a Halloween skull just suddenly ups and walks away. I've never seen it, but I know it happens and the idea fills me with dread.) Therefore:
- I don't want some knucklehead to enjoy the fruits of my labor. If they get my skull, it will soon become useless to them! MWAH-hah-hah-HAH-HAH-HAH-HAAAHHHH!!!
This skull will only light up for X number of days before it gives up the ghost, so to speak.
- Minimal parts (see point number 2, above).
- To gain knowledge in other AVR microcontrollers, besides the ATmega328p in the Arduino Uno and others.
- To learn how to use the USBASP device. See https://www.fischl.de/usbasp/ . As Thomas says, "USBasp is a USB in-circuit programmer for Atmel AVR controllers... The programmer uses a firmware-only USB driver, no special USB controller is needed."
As you may know, the Arduino Uno, Leonardo, and other AVR-based boards come with a bunch of additional components, such as an FT232RL USB-to-serial chip, a power regulator, a crystal oscillator, various connectors and lights, headers for wiring, etc. And after the chip is programmed over the USB interface, the additional IC is just a power drain. Furthermore, if you're supplying power from batteries, the voltage regulator is at best useless and at worst more of a drain on your supply. If you want to only control a couple of LEDs, pretty much everything besides the processor is superfluous for most of your project's life.
Additionally, most if not all of the AVR chips come with a clock oscillator built-in. It's not as speedy or as accurate as the crystal, but for a simple use case, what does it matter?
By using a processor from the appropriately-named "ATtiny" line, you get an amazingly capable little processor that draws little power, provides all the outputs you need, has more than enough speed, is really cheap, and keeps your part count low, to boot.
The tradeoff is that you need to bring your own programming device. Luckily, there's one out there called the "USBASP". Think of it as like the Arduino's builtin USB-to-serial chip but separate and removable. You can use it for all of your projects. Even better, it eliminates the need for a bootloader. You get that memory back, if you need it.
And don't be afraid- the USBASP is really easy to use. Many pioneers before you have been utilizing it, so it's quite familiar and well supported for the task. In this tutorial we'll be using it and, as a simple project for getting your feet wet in the world of ATtiny processors, this may be a good time for you to get familiar.
8. Final goal: I hope you enjoy this Instructable!
Step 2: Ingredients
- 3x AA batteries (Walgreens)
- Battery holder for 3 AA batteries (eBay)
- 9V battery clip (eBay)
- Breadboard for testing (eBay)
- PC board (solderable breadboard)
- 0.1" (0.254 mm) female headers (for your ATtiny84a. If you're confident, just solder the ATtiny to the PC board). (eBay)
- 2x 5mm Red LEDs (eBay)
- 100 uF electrolytic capacitor (eBay)
- 0.1 uF ceramic capacitor (eBay)
- 2.2 megohm resistor (eBay)
- light-sensitive resistor (eBay)
- 2x 82 ohm resistors (eBay)
- ATtiny84a microcontroller chip (eBay)
- 24 gauge solid hookup wire (eBay)
- soldering iron (Amazon or Radio Shack)
- solder (Amazon or Radio Shack. Lead-free is best.)
- plastic Halloween skull, not too small, hollow (Walmart, Dollar Store, etc.)
- usbasp programmer (eBay)
Tips and tricks for purchasing electronics for those in the USA:
For any of your basics (resistors, transistors, capacitors, LEDs, etc.), go to eBay. Your electronics projects will generally take standard sizes (as is the case here); this is a great time to stock up. Search around and find packs with 20, 40, 100 pieces in them. Buy those; you can generally find them for under 10 bucks and free shipping. This is much cheaper than Mouser/Digi-Key/Newark. There, you'll get reasonable prices on the parts but then they whack you 9 bucks for shipping; those low prices evaporate in a hurry! You can certainly find the specialized parts and the selection is great at the specialty stores, but you're hurt by that shipping. On the other hand, I found a pack of 5 ATtiny84a's for $7.50 on eBay, with free shipping. 5 MCUs for less than the price of shipping 1 from Mouser! Yowser! And eBay has all the component variety packs you could need, and you know that if you need one resistor, you'll need a dozen!
Step 3: The USBasp
Before we begin, let's talk a little bit about the USBasp. They're easy to find on eBay, so go get one. Don't worry, I'll wait...
You got it? Good! Did you buy it from China? No wonder it took so long. :-) Ok, well it was cheaper that way I'm sure. Free shipping, too.
If you're a Linux aficionado like me the USBasp works out-of-the-box. For Windows 10, it's a little more complicated. So let's go through it:
- The USBasp website at https://www.fischl.de/usbasp/ points us to the "Zadig" driver installation tool at https://www.fischl.de/usbasp/
- Download it. I downloaded version 2.4.
- Windows 10 will ask you if you want it to make changes to your device. Yes. Yes, you do.
- Decide if you want Zadig to check for application updates. I said yes.
- Now I followed the instructions from https://rayshobby.net/dead-simple-driver-installa... . That is,
- Plug in the USBasp device. Probably you will see a red LED light up on it.
- In Zadig, in the box just to the right of the big green arrow, click the little up or down arrows until you see libusbK (v184.108.40.206). This is for Windows 10.
- Click the big Install Driver button.
- Wait. In a few seconds, you'll see the "The driver was installed successfully." dialog box. Close it.
Your USBasp device is now ready!
Step 4: Arduino Support for the ATtiny
The Arduino IDE does not support the ATtiny series of chips out of the box. You need to add it to the IDE using the boards manager. See http://highlowtech.org/?p=1695
Assuming you have already downloaded the Arduino software, I'll recreate the steps from the URL above. Simply
- Open the Arduino software (I'm using 1.8.7 as of this writing).
- Open the menu: File -> Preferences. Find the box "Additional Boards Manager URLs" near the bottom.
- Copy and paste the following:
- Thats https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
- Click OK
- Open the menu: Tools -> Board: "" -> Boards Manager (at the top of the list)
- Scroll to the bottom. You should find "attiny by David A. Mellis".
- Click the Install button.
- Scroll to the bottom of the list. You should see "INSTALLED" now.
- Open the menu: Tools -> Board: ""
- You should see the ATtiny at the bottom of the list.Click on "ATtiny24/44/84".
- Open the menu: Tools -> Processor: "". Choose the ATtiny84.
- Under the Tools menu you should see a Clock entry. The default is fine. This is how the ATtiny processors ship, with a 1 MHz internal clock.
- Under the Tools menu choose the Port. You want "COM1".
Step 5: Testing, Testing: Breadboard Your Circuit
If you're not familiar with breadboards... well, get one. This is the only way to test your circuits and make sure they do what you want. I recommend it even if you're building a known circuit like this, which has been tested and works. You'll make yourself familiar with the arrangement of things so that if and when something fails to perform properly, you'll have an easier time troubleshooting.
Attached is a possible breadboard layout, and a schematic of this little circuit as well. Wire your circuit as shown.
When inserting the LEDs and the electrolytic capacitor, remember that direction counts: you need to put the negative side towards the battery negative, and the positive side towards the more positive side of things. In the case of the LEDs, they will be on when the ATTiny84a's pin turns positive (or, "HIGH"). So the positive side of the LEDs should connect to the appropriate pin on the ATTiny84a.
There are many websites which discuss LED polarity; one such tutorial can be found here: https://learn.sparkfun.com/tutorials/polarity/diod... . Ultimately, the best way I have found to test polarity is to plug a 120 ohm resistor into the battery negative, plug one pin of an LED into the other end of that resistor, then connect the other end of the LED to the battery positive (also known as VCC). If the LED lights up, you know which pin is which.
For the 100 microfarad capacitor, this is an electrolytic type capacitor. Basically that means that its orientation is important as well. The negative pin should be labelled. By process of elimination, you can figure out which is the positive pin :-) . Connect it correctly.
Resistors, the photocell, and the little circular ceramic capacitor do not have polarity. Connect them in whatever direction you want. Make sure you connect the little ceramic capacitor very close to the VCC and GND pins of the ATTiny84a. Its job is to smooth out any rapid spikes in power draw from the ATtiny microcontroller. It is filled with a tiny charge from the power source (batteries), which is available very quickly should the microcontroller need it in microsecond time. It prevents the supply voltage to the chip from dropping too low due to transient rapid current draws.
The 100 microfarad electrolytic capacitor does the same thing, but at larger intervals. Due to the fact that it's a winding of thin metal sheets, it contains some internal resistance and so its charge is not as readily available. It can be rapid, it's true, but not at the rate provided by the ceramic disk capacitor.
Both capacitors react more quickly to transient power current draws than the batteries, which is why they're included. It has been the case that my circuits have behaved strangely if they're missing. It can be very mysterious, so they are important.
Not shown here, but necessary, is a 10K ohm resistor from pin 4 to Vcc. You would do well to install one. However, I did not and the circuit worked fine. Without it, though, you risk spurious resets to your chip.
Step 6: Load the Sketch
Now it comes time to load the sketch. Let's make those blinkenlights!
You'll find the source code for the sketch at https://github.com/GreyGnome/SpookyEyes
- Grab it, and load it into the Arduino software.
- NOTE: There's a section in the code that looks like this:
// --- DEBUG DEBUG DEBUG DEBUG D--vvvv--UG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG<br>// --- DEBUG DEBUG DEBUG DEBUG D--vvvv--UG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG #undef DEBUG // --- DEBUG DEBUG DEBUG DEBUG D--vvvv--UG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG // --- DEBUG DEBUG DEBUG DEBUG D--vvvv--UG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG
I recommend changing the
as the loop timings are shortened greatly. You should change it back and re-upload when you're ready to display the SpookyEyes for real.
- Go ahead and do that now. The rest of this page assumes you have done so.
- Make sure you've followed the steps under Step 4: Arduino Support for the ATtiny
- Now plug in the usbasp's Arduino side to your board. You want to connect it as follows:
- GND to your battery negative
- MOSI to pin 7 of the ATtiny
- MISO to pin 0 of the ATtiny
- SCK to pin 9 of the ATtiny
- RST to pin 4 of the ATtiny
How the Sketch Works
Make sure you are in a somewhat bright room, or direct the light from a flashlight to the little light-sensitive resistor. Power the circuit, and observe the eye LEDs. This is "daylight" mode. Now that the sketch is running, you should see the following. Note that the areas in the code that are described here are marked with "BooKmarks", not line numbers, so you can follow along. These have the form: #BK.descriptive_string ("Pound B K Period" then some sort of descriptive string). For example, the first bookmark is called "#BK.Hello" and can be found in the code where the LEDs go on for a second, then blank for a second:
- Both LEDS will go on for a second, then blank for a second. #BK.Hello
- They both blink slowly 3 times. This indicates that the ATtiny is set to 1MHz speed. #BK.check_time * See NOTE A below.
- Pause for a second.
- They then blink quickly two times.
- Pause for a second.
- Now you are in the loop() #BK.loop. Remember, an hour is only 10 seconds now.
The "latch" is off. And an HOUR_millis (== 1 hour, in regular mode) amount of time has not yet passed. So, we skip past everything until we get to #BK.indicate_duration. So far we're in the zero'eth hour, so we flash the eyes 0 times.
- This continues until we reach HOUR_millis seconds (10 seconds, in DEBUG mode).
- Then blink quickly three times. #BK.time_management
- Add another "hour" by incrementing the latch_time_off variable
- Then jump all the way down to #BK.indicate_duration. There, we flash the number of "hours" we've been running. This number is stored in the EEPROM, so it's available even if power is removed from the chip.
- Our first hour in the light has been completed. So we flash once, briefly.
- Then pause 2 seconds.
- Every iteration through the loop now, we check to see if HOURS_milli time has passed. For the first several iterations (in DEBUG), it hasn't. So we don't flash 3 times.
- We skip down to #BK.indicate_duration, and we flash rapidly a count of the number of hours that we've been in the light, which again is stored in EEPROM location 0.
- This continues for a long time.
- Note that once the number in EEPROM location 0 is big enough, the loop simply becomes:
- Flash 3 times at a reasonable pace,
- Flash rapidly the number of HOURS_millis that's we've been in the light,
- Wait 2 seconds,
Now put your finger on top of the light sensitive resistor. Or just turn out the lights. The loop now becomes:
- Our latch_time_off has been over an hour, and it's dark, So at #BK.check_the_light, we find that it is indeed dark.
- We turn the latch on. This starts the spooky stuff every loop. See HERE'S THE SPOOKY STUFF. The code should be fairly descriptive.
- Once the latch has been on long enough, we'll turn it off. See #BK.turn_spookiness_off.
- Now we go back to #BK.time_management, as per "blink quickly three times", above.
Run For Real
Don't forget to change the sketch to #undef DEBUG.
* NOTE A: Code is included to set it to 8 MHz. See the CLKPR = 0x00; commented code. If you want to do this (and there's no reason to do so for this circuit), make sure you change the Arduino IDE, in the Tools->Clock menu item.
Step 7: From Breadboard to Soldered Circuit
Now it's time to make the circuit Production! Get a little solderable perfboard; I like the Radio Shack Catalog #: 2760159, seen here: https://www.radioshack.com/collections/prototyping... . There's plenty of holes for transferring your PC board components to the perfboard.
Don't forget to include little socket pieces for inserting the USBasp wires (for programming)! You'll need 5 of them.
Prepare the Skull
Orient your skull as to how it will sit on the ground. You'll need to drill a hole for the photoresistor, such that it actually gets light :-) . ...Important step! Also, using your favorite cutting tool, cut open the bottom of the skull so as to make room for the circuit board and batteries. Cut it on 3 sides only so as to make a door.
Drill the hole to that the photoresistor will be a press fit. Obviously, you can test the size from the outside of the skull to get it right. Always start small with your drills, and don't drill too quickly so as not to create a lot of flash around the hole that you'll need to shave off with a knife.
Drill holes in the eyes for the LEDs. Size them carefully, so the LEDs will be a press fit. I put my LEDs in from the inside, and since there was not a lot of clearance to work inside, I just dripped a little hot melt glue on the back of the LEDs as a little extra insurance to hold them.
I was also careful to sheath one of the wires to each LED in heat-shrinkable tubing.
Put the Circuit In
Since the skull just sits there, I was not very careful about mounting the circuit board. I made sure that the battery pack went on the bottom and there would be no short-circuits. Once wired up, inserted, and powered, I closed ipt up and put a blob of hot melt glue on the bottom flap.
Make sure you make the wires to the LEDs and photoresistor long so as to be able to pull the circuit board out for reprogramming.
Step 8: Spoooooky Eyes!!!! Oooooooo!!!!
Ok, now that's it. Your Spooky Eyes will turn on at dusk, display for the trick-or-treaters for 4 hours, then shut off to preserve batteries. It will stay off until the next evening. It will do this for TOTAL_RUN_HOURS hours, so prepare that value in the sketch carefully. Since I have a 4 hour default MAX_RUNTIME, 40 hours for TOTAL_RUN_HOURS means it will run for 10 days.
If someone decides that it's too delicious for you to have, and takes it home, SpookyEyes will finish out its run and then go silent, and forever haunt their souls. Suffice it to say, thieves would do well to avoid taking your SpookyEyes skull!
Put your SpookyEyes away for the season. Next year, simply upload the sketch again and SpookyEyes comes to life! How spooky is that? Ooooooo!!!!
I probably should have made the ATtiny go to sleep during the day. Powered down, it draws very little current.
I should have put a 10K ohm resistor on pin 4. This keeps the circuit from mysteriously resetting. I did not have any problems, however. But it should be done to be correct.
I love the ATtiny84. It's a great little chip for a low-powered circuit. Sure, it doesn't have the Serial.print() capabilities of the Arduino ATmega328p and its ilk, but you can have lights blink in certain ways to tell you what's going on inside your circuit, for debugging. It's not hard to work with.
I hope you found this Instructable... instructable!