Door Activated LED Lighting Using Hall Effect Sensors





Introduction: Door Activated LED Lighting Using Hall Effect Sensors

I've been meaning to make something cool for my dorm room this coming semester and decided that some custom closet lights would look great. In this Instructable, I'll show you how to make some nice-looking LED lights that will turn on automatically using a hall effect sensor and a magnet.

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

Stuff needed:

The usual tools:
1. Soldering Iron/Solder
2. Electrical tape
3. Protoboard

1. Hall Effect Sensor-(one used can be found here:
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)
7. Magnet

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

The cases I used for this project are Icebreakers mint containers because they're very easy to Dremel through and can fit small circuit boards pretty well. All you need to do here is pick a pattern you like and drill the holes, but be sure to make the holes just big enough for the LEDs to fit through.

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 next step is to place the LEDs in their holes and solder them together. I found that bending the positive leads in until they touch makes soldering alot easier. I attached a wire to the positive leads, taped over them with electrical tape, and did the same for the negative leads. It also saves space if you solder one leg of a resistor to either the positive or negative leads so it doesn't have to be done on your protoboard. To connect the LED units, i drilled two holes into the side of each case, ran the casing down the wire, stripped the wire and tied together the main lines to the LED wires.

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

I usually test out my AVR projects on an Arduino simply because of the ease of debugging. Below is the code I used to test the output of the Hall Effect sensor. I'm not going to go into the deep workings of the Hall Effect here but if you're interested, wikipedia has a bunch of good info.

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.

int sensor=2;
int val=0;
int ledPin=12;

void setup(){

void loop(){

Step 5: Moving From Arduino to AVR

The next step is to take our circuit and code from an arduino and transfer them to a standalone AVR chip. The reason I'm using an Attiny85 is because its the smallest AVR I have and I only needed 2 pins.
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: and the tutorials here:

#include <avr/io.h>
#include <util/delay.h>
#include <avr/sfr_defs.h>
#define lights PB0
#define magSense PB1

void initPorts();

int main(void)
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);
return 0;

void initPorts(){
PORTB = 0b000010; // enable pull up on sensor pin
DDRB = 0b000001; // set PB0 as output and rest as input

Step 6: Put Everything Togtether

Finally, all you should have to do is connect the wires from the control unit to the power source, in my case a 5v wall wart, and from the LEDs to the transistor and power. Then place the sensor somewhere where a magnet attached to your closet door will set it off.

Here's a video of the top unit working with the sensor:

And here is the completed unit:



  • Epilog Challenge 9

    Epilog Challenge 9
  • First Time Author Contest 2018

    First Time Author Contest 2018
  • Sew Warm Contest 2018

    Sew Warm Contest 2018

We have a be nice policy.
Please be positive and constructive.




Is there a way to modify this circuit to make it when my door is open for 15 seconds, a servo is activated to close it? If so please contact me.

 This would look amazing in those Ikea Hopen wardrobes, the ones with the frosted glass door. But maybe on a timer so that it's turned on from a certain time at night until early morning, a very big nightlight. lol

One thing that could be an issue:  Since LEDs can have some variance in their forward voltage, it's usually not the best idea to have multiple parallel strings of LEDs (or in this case, parallel single LEDs) that share a single current source or resistor.  Unless the LEDs were specifically binned with identical Vf, the current distribution between the LEDs could be quite uneven, resulting in uneven LED brightness and potentially damage to any LEDs that have significantly lower Vf than the others.

from your pictures, it looks like its more for show. I say this because it doesnt look like its really brightening up the closet enough. I may be picky, but thats my opinion.

Ive never seen tis before, i have to admit and it would be extremely helpful.

I actually did make something comparable with a reed switch, and trust me it's bright enough.  Unless you actually enjoy the overhead lighting in a "normal" office of course...

is there any video?

oh wow, I think I'll try with a movement detector. Thanks for posting

nice one thx for sharing there is really a lot that can be done for upgrade but its really useful thx again

instead of eating so many icebreakers u could have bought the led thing already made at the 99c store i saw them last week.