[wpvideo 7Mw3BY6c]

This is a trivial little project to create the appearance of something carnivorous… lurking in the dark… with intent. Half a dozen of these in the bushes or windows gives some creepy background ambiance.make_halloweenbadgeV2 (1)

A very basic Atmel microprocessor, the ATTiny45, is programmed to make two LEDs slowly dim, brighten, and occasionally “blink” by turning the LEDs off and on. The blinking interval is pseudo random, controlled by an eight-bit linear feedback shift register (LFSR — see the Wikipedia article describing them. There’s a minimum blink time, so that the LEDs don’t turn off more often than every three seconds or so.

Brightness is controlled using the Pulse Width Modulation (PWM) facility of the ATTiny45. An interrupt is generated by an internal timer overflow about eight times a second. The interrupt handler sets a tick_flag and checks to see if it’s time to blink. If it is, it sets a blink_flag as well.

The main loop checks the flags, increases or decreases brightness on each tick by modifying a comparator register, and blinks each time the blink_flag is set. See the code file BE-45.c for details. BE-45.c and a Makefile are in the Girhub repository here:  https://github.com/BradBrand/BlinkingEyes

Blinking Eyes schematic
The Blinking Eyes schematic with an optional on-off switch.

The circuit is trivial. In addition to the programmed ATTiny45, there are two LEDs with their attendant resistors and a capacitor to smooth the power provided by a 2032 coin battery.

The links in the parts list are for examples only.  There are many cheaper options available, particularly on eBay.

To show the simplicity of the circuit, I wired up an example on a breadboard. It’s just the microprocessor, two resistors, two LEDs, and the capacitor (see the picture below). The resistors are connected to pins 5 and 6 on one side and to the positive (longer) leg of the LEDs on the other. The negative (shorter) leg of the LEDs is attached to ground.

Power is provided by a 2023 battery wired up throwie style; a capacitor connected to power and ground keeps the power clean. Two wires for power (pin 8) and ground (pin 4) supply the microprocessor, and assuming that it’s already programmed, this is all that’s needed.

The board is actually the most expensive component. Since I didn’t want custom-made boards in quantity, I decide to use the Evil Mad Scientist ATMegaXX8 target board. It’s relatively cheap in quantity, and there’s a good blog article about adapting various breakout boards for alternate processors.

Screen Shot 2013-10-17 at 3.32.52 PM
A breadboard version shows the simplicity of the circuit.

The board also makes adding a six-pin programming header very convenient which let me use my Adafruit USBTinyISP to program the microprocessor. Three wires are all that’s needed to turn it into the perfect ATTiny45 development board.

Below are the step-by-step instructions for creating a more permanent version that will better stand up to being cable-tied to the bushes.

Project Steps

Gather up the parts and solder in the socket and LEDs.

There are only eleven components in this project, and three of them are optional.

The 3v, 2032 battery-based, throwie-wired power supply is on the left, and the breakout board is on the bottom.

The rest are

Top row: Two red LEDs, with forward voltage of 1.9-2.0 at 20 mA.

Middle row: Two 68 ohm resistors (56 ohm would be better) and the optional push-button switch.

Bottom Row: The ATTiny45, an optional socket, an optional 6-pin programming header, and a 100nF (0.1uF) capacitor.

Solder the 8-pin socket in first. This will serve as a reference for wiring everything else up.

Pins 5, 6, and 7 (the right three upper pins) align with SCK, MISO, and MOSI, and that takes care of three of the four ISP logic connections. Pin 1 (reset) is the fourth; we’ll fix that later.

Pin 8 (upper left) is power. Pin 4 (lower right) is ground.

Pins 5 and 6 (upper right) are also the Output Compare pins (OC0A and OC0B. These are part of the Pulse Width Modulation facility. The output is controlled by software writing to the control registers OCR0A and OCR0B.

Next, wire up the LEDs. Pins 5 and 6 are wired to the third column in. Each resistor bridges the third column in with the second column in.

The long leg of each LED is soldered to the second column in, and the short leg is in the outermost column. Finally, the outermost column is wired to ground.

The LED could be soldered directly to ground, but it doesn’t sit as well that way.

Solder up the power wiring.

The power for the microprocessor is run from Vcc at the top, through the push button switch, to pin 8 of the microprocessor.

The switch is six-pin, and closing the switch connects the middle pin on each side to the outer pins.

Connect GND (ground) at the top to pin 4 of the microprocessor.

Solder the 100 nF capacitor into the C3 holes in the upper right. This bridges the power supply wires and keeps the voltage stable.

Solder in the wires for the battery and finish the power supply with a little electrical tape.

Finish with the programming logic.

There are two pieces to the programming circuitry. The first is the gray wire (toward the bottom) connecting the RESET pin on the microprocessor to the RESET column on the ATMegaXX8 pin-out.

The second is the 6-pin programming header in the upper right corner.

I use the CrossPack-AVR tool chain on a Mac and a USBTinyISP to compile and load the code.

The final board. Eliminating the switch and the programming header also eliminates two wires. The microprocessor can be soldered directly to the board, but either the socket or the programming header need to be used to reprogram the microprocessor.