Friday, August 19, 2011

Halloween Spooky Eyes



With Halloween approaching and a little bit of free time on my hands the other day, I decided to make a decoration to put in the bushes this Halloween.  They are large 10mm diameter LED's glued to popsicle sticks.  They are spaced apart to look like Halloween creature eyes hiding in the bushes stalking their prey.  Are they after the bags of candy or the trick-or-treaters themselves?  I hooked them up to a microcontroller to animate them by "blinking", not to be confused with flashing of course.  You certainly could do a re-design and use 555 timers etc, but it seems more and more these days I have more microcontrollers in stock than I do 555 timers and the like.

I drew vertically elongated pupils with a sharpie on the LED's to add to the creature like effect.  They are a bit hard to see in the video but they look good in person.




These LED's came from some discount store I don't remember when and as such I didn't have any specs on them.  To find the forward voltage drop I applied 5v via a 1k0 resistor and measured the voltage across the LED leads.  I measured ~1.7v on all of them.  Here is a construction photo showing the current limiting resistors for the LED's.




I connected the LED pairs to an ATtiny2313 microcontroller via some comms wire and some 2n3904 transistors for each pair.  You can see how spartan the circuit is in the picture below.  If you would like a schematic of the spooky Halloween eyes you can download it here.




Hot glue offers some protection in the form of electrical insulation and mechanical fastening.




I have yet to install these eyes in the bushes, but initial bench testing suggests they are incredibly realistic creature eyes.  I walked by the room where I was testing them and I was overcome with fear and froze in my tracks.  The terror subsided when I remembered that the eyes are just a Halloween decoration; LED's and C code at that.

Since humans blink at about 3-4 blinks per minute when concentrating I figured that would be a good blink frequency to use for my creature eyes.  The creatures could in fact have once been human before turning, we just don't know.  Blink duration is 350mS.  Here is the code to run 3 eyes.  Feel free to modify it for your own use.

/* 
Title:		Spooky Eyes v1.0
Filename:	spooky_eyes_1_0_main.c
Author:		Pete Mills
Website:	http://petemills.blogspot.com
Date:		2011.08.17
uC:			ATtiny2313 @ 8 MHz internal oscilator, no prescale
*/

/*
Program description:

This program blinks LED "eyes".  The led's are mounted on popsicle sticks about the distance apart as 
human eyes are.  Hide the LED's in the bushes and they look like halloween creatures stalking you.
The blink frequency is that of a concentrating human at 3-4 blinks per minute. Blink duration is 350ms.
These timings are non critical and as such timing is derived from the ATtiny's internal RC oscillator.

Circuit Description:

The uC is an ATtiny2313 running on its internal oscillator @ 8MHz with no internal prescale.
The 10mm diameter led's are connected to PB0::2 via a 2N3904 transistor for each pair.  The led's are 
on the high side.  Each LED has a 120 ohm current limiting resistor.  

A schematic is available at https://sites.google.com/site/pemills2011/file/Spooky_Eyes_Schematic.pdf?attredirects=0&d=1

*/


#include <avr/io.h>			// defines things like "PORTB" and "TCCR0" etc
#include <util/delay.h>		// delay functions
#include <avr/interrupt.h>

#define EYE_PORT PORTB		// hardware port for spooky eyes
#define RED_EYE PB0			// red eyes
#define YEL_EYE PB1			// yellow eyes
#define GRN_EYE PB2			// green eyes

// global variables

volatile uint16_t red_ctr = 0;
volatile uint16_t yel_ctr = 0;
volatile uint16_t grn_ctr = 0;


// function prototypes

void setup(void);
void blink_eye(int eye);


int main(void)
{

setup();

uint16_t red_delay = 0;
uint16_t yel_delay = 0;
uint16_t grn_delay = 0;
uint16_t min_time = 15000; 	// minimum amount of time between blinks


	while(1)
	{
		
		if( red_ctr >= red_delay )
		{
			blink_eye(RED_EYE);
			// random time from ~0-5 sec plus min_time = ~15-20 sec between blinks
			red_delay = ( ( (uint8_t) rand() ) * 20 ) + min_time;	
			red_ctr = 0;
		}
		
		if( yel_ctr >= yel_delay )
		{
			blink_eye(YEL_EYE);
			yel_delay = ( ( (uint8_t) rand() ) * 20 ) + min_time;	
			yel_ctr = 0;
		}
		
		if( grn_ctr >= grn_delay )
		{
			blink_eye(GRN_EYE);
			grn_delay = ( ( (uint8_t) rand() ) * 20 ) + min_time;	
			grn_ctr = 0;
		}

	}

}


// functions

void setup(void)
{

// port config

DDRB |= ( ( 1 << 0 ) | ( 1 << 1 ) | ( 1 << 2 ) );		// set portB bits 0::2 to 1 for output
PORTB &= ~( ( 1 << 0 ) | ( 1 << 1 ) | ( 1 << 2 ) );	// set the outputs low


// timer config

OCR1AH = 0;							// interrupt @ 1khz
OCR1AL = 124;						// decimal 124, one less than 125000/1000 because 0 and TOP are counted
TCCR1B |= ( ( 1 << WGM12 ) | ( 1 << CS10 ) | ( 1 << CS11 ) );		// CTC mode, ck/div by 64 for 125000 Hz
TIMSK |= ( 1 << OCIE1A );											// enable OCR1A match interrupt
sei();
}


void blink_eye(int eye)
{
	EYE_PORT &= ~( 1 << eye );	// turn off eye
	_delay_ms(350);
	EYE_PORT |= ( 1 << eye );  // turn eyes back on
}


ISR(TIMER1_COMPA_vect)
{
	red_ctr++;
	yel_ctr++;
	grn_ctr++;
}







// 


Here are a couple videos of the eyes in action.




In this video you can see some of the randomness in the trio of creature eyes.  There is a minimum of 15 seconds between each set of eyes blinks then a random amount of time from ~0-5 seconds.




This was a fun afternoon project and I think it will be a fun decoration too.  I hope the trick-or-treaters don't get too frightened and stay away...

9 comments:

Raven's Hollow Cemetary said...

Hi Pete :) Love the design, and I'm in progress of making one of my own for my haunt. I do have one question for you though. I have several LM7805's lying around, but I've never seen a 7805TV as you indicate in the schematic.

My question is (since I can't find a data sheet on the "TV" variant): Can any other LM7805 be subbed in place of? If so, which is the closest match in specs?

Thanks for the schematic & posting this tutorial. Much appreciated! :D

Pete said...

Hi Raven's Hollow Cemetary,

I took a look at the schematic and must admit I am not sure where the " TV " part of the 7805 designation came from.

The 0.33uF and 0.1uF capacitors on the input and output respectively, of the 7805 are pretty standard so I will say yes, you can almost certainly substitute any 7805 5v regulator that you have.

From the datasheet, the ATTiny2313, running at 8MHz will operate from 2.7v - 5.5v. If you were to change the operating voltage of the system for some reason, don't forget to recalculate new current limiting resistors for the LED " eyes ".

Raven's Hollow Cemetary said...

Great! Thanks for the response & advice good sir. :)

Oh, and sub'd btw. :D

Forrest said...

Would you be interested in making up some of these for a boy scout haunted Halloween?

Pete said...

Hi Forrest,

Send me an email and I may be able to help.

-Pete

Forrest said...

Pete, I lost your email. could you send me another reply.
The scouts would be interested in buying the packaged components from you if you could assemble one for our sample.
Thanks,

Anonymous said...

Very cool! Please forgive dumb question. How how does the 7805 connect to the rest of the circuit? I'm not clear from the schematic.

Pete said...

Hi Anonymous,

I'm glad you like the project. Looking at 7805 on the schematic you will see symbols labeled "GND" and "VCC". You will also see these symbols elsewhere on the schematic such as on pins 10 and 20 on the ATTiny2313. Anywhere you see these symbols, they should be connected together electrically. Often, we draw schematics this way to avoid having excessive lines drawn and we assume they are to be tied together.

-Pete

Richard Doucette said...

Hi Pete, Love this and am planning to make one up myself. Had a thought about making the eyes go dark for a few seconds with sound. Any thoughts on hardware and code?
Thanks,
Rich