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
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
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.
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.
Read more: Door Activated LED Lighting using Hall Effect Sensors using Attiny85 microcontroller