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:



    • Arduino Contest 2019

      Arduino Contest 2019
    • Tape Contest

      Tape Contest
    • Trash to Treasure

      Trash to Treasure

    27 Discussions


    7 years ago on Introduction

    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.


    8 years ago on Introduction

     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


    9 years ago on Introduction

    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.

    3 replies

    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...


    9 years ago on Step 6

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


    9 years ago on Step 6

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


    9 years ago on Introduction

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

    2 replies
    Lance Mt.ktalex

    Reply 9 years ago on Introduction

    Pfft, and? Wheres the fun in that? Altough i would take that 99c device and rig up a serious annoy-o-ma tron and slide em around Lets say a 99c sensor + a 99c smoke alarm (more or less its alarm) and rig it up


    9 years ago on Introduction

    oh, and i also wanted to ask if a 555 timer would work. never used an "Attiny85" before so i dont know??

    3 replies

    Reply 9 years ago on Introduction

    I'm not sure how well the 555 timer would handle the input from the sensor since it can't be programmed, let me know if you get it to work somehow though! An Attiny85 is just the name of an AVR microcontroller; if you've ever used an Arduino, its the same type except they make the programming part much easier. The only reason I even used it was because I was having trouble getting the sensor to switch a transistor on its own. I think the source or sinking capabilities of the sensor are very low so I used the microcontroller to handle the transistor and just read the value of the sensor to not put it under much stress. If you don't have much experience with micros, you could try creating some sort of buffer stage for the sensor output so that it can drive a transistor to turn on the leds. If you're familiar with digital logic gates, maybe you could use a logical AND gate with the sensor at one of the inputs and +5v at the other with the output connected to the transistor's base.


    Reply 9 years ago on Introduction

    Thanks for all that info. I don’t have any knowledge of programming microcontrollers but do have knowledge with transistors and the such. I have a fairly good schematic which is Brocken up into two sections, an input and an output. they are separated by a relay so that the "week" input can trigger a very small reed relay which will then trigger the output which includes a transistor to keep the LED's for example "on" even when the input disappears. I might give it a try with your concept. It’s confusing but it works, I built a Laser beam alarm system with it and it turned out great, I even posted an instructable on it. Check it out if you are interested. CHEERS!!


    Reply 9 years ago on Introduction

    I don't see why a halleffekt sensor wouldn't work with a 555 in astable, the switching is fairly on/off.


    9 years ago on Introduction

    If I was going to do this I would make it so that it turns on when the sensor goes off (say you walk into a room) then it turns off when you pass it again, pretty cool 'ible though


    9 years ago on Introduction

    Just wanted to say this could be done very easily with a reed switch instead of a hall cell and would use no power when the door is closed. Just put a reed switch instead of the hall cell and have it switch the power line to the LED's. No microcontroller necessary and reed switches are pretty cheap.

    1 reply

    Reply 9 years ago on Introduction

    Funny you should say that, the reason I even thought to do this was because I found a reed switch in an old window alarm. Only problem I had was that I had no way of telling its current handling capabilities and because I tend to prefer solid state devices rather than those with moving, and therefore breakable, parts.