Edit: I've noticed a lot of people are hating on the excessive control used in this project so I just wanted to clarify a few things:
1. This instructable was also meant to be a lite introduction to actual AVR programming for those people who are used to only Arduino programming. I had a bit of trouble finding useful information when I was learning so I figured it would be nice to help out some others. That is why I posted the basic tutorials along with my AVR code.
2. Yes I'm aware I could have simply used a reed switch to switch the LEDs when the door opened and closed. I wanted to leave room open for myself to add different light modes, maybe using more wires and pins to create nice fading effects, possibly a remote control sensor, and maybe even an auto-shutoff routine.
Step 1: Gather Materials
The usual tools:
1. Soldering Iron/Solder
2. Electrical tape
1. Hall Effect Sensor-(one used can be found here: http://www.sparkfun.com/commerce/product_info.php?products_id=9312
2. Attiny85-(any micro can be used, mainly just for quick and easy digital input readings)
3. Led's of any color
4. Cases for the lights,
5. Wire and Wall wart
6. Resistors (1k and 3x33Ohm used in mine)
Note: A microcontroller isn't necessary for this to work. If you can get the sensor to successfully switch a transistor to saturation, you should be able to skip the whole controller and coding part.
Step 2: Prepare the LED Housings
Note that the pattern seen below is just an example, I used a simple triangle pattern for the lights in this project.
Step 3: Solder in the LEDs
The only reason I used three separate 33 ohm resistors in each case, rather than one 10 ohm resistor is because I soldered together the first light with a 33 ohm resistor and didn't feel like desoldering anything :) .
Step 4: Arduino Test
What's cool about this sensor is that the output is latched. For those of you who don't know what a latch is, it's one of the most basic memory elements in all computing. This particular latch will remember a digital High reading at the output of the sensor until an opposing magnetic field is sensed, at which point it will drop to digital Low and stay there until it is triggered again.
What this means for our code is that we only need to scan the inputs and turn the lights on or off based on what the sensor's memory holds. If you wanted to make this project really energy efficient, you could set up an interrupt to wait for a sensor trigger but since I'll be running this from a wall wart, it doesn't really matter that much to me weather the microcontroller uses 10milliamps or 50.
Step 5: Moving From Arduino to AVR
The fuses are set to an 8Mhz internal RC timer since timing isn't critical. Once done with the code, go right ahead and solder the circuit together.
Below is the code I used for the AVR. If you aren't familiar with AVR programming, most of what you need can be found here:http://iamsuhasm.wordpress.com/tutsproj/avr-gcc-tutorial/ and the tutorials here: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewforum&f=11&sid=f899212b86e2e0de2b660c0999f95fd7
#define lights PB0
#define magSense PB1
volatile uint16_t val; // variable for reading the pin status
//volatile uint16_t lightMode = 0; // variable to keep the light's state
val = bit_is_set(PINB, magSense); // read input value and store it in val
if (val) // make sure we got a 1
PORTB |= (1 << lights);
PORTB &= ~(1 << lights);
PORTB = 0b000010; // enable pull up on sensor pin
DDRB = 0b000001; // set PB0 as output and rest as input
Step 6: Put Everything Togtether
Here's a video of the top unit working with the sensor:
And here is the completed unit: