Yes, I know what you're thinking, this does seem a little overkill but first of all, you'll never have to worry about stubbing your toe again and second, it makes walking up and down your stairs so much fun, i found myself going upstairs for no reason just to watch the lights follow me. I mean it isn't the most practical project but its a fun build and it gives us a chance to learn about the different ways to activate lights with an Arduino. So with that being said, let's get started with the build!
Step 1: How It Works
So whats happening is as you walk up the stairs the step you're on, the step in front of you and the step behind you are lit up which allows you to see exactly where you're walking no matter which direction you're walking in, not to mention the cool effect it gives.
The way it works is each step has a laser and light sensor which makes a trip wire, when the laser beam is broken the Arduino triggers a MOSFET which turns on the corresponding LED strip. Now this definitely isn't the only way or even the easiest way to do this but the alternatives didn't work for me for a bunch of different reasons. The most obvious alternative was to mount an ultrasonic sensor at the base of the stairs and then turn on lights based on how far you are from the ultrasonic sensor, this didn't work for me because I have too many stairs! (14) which caused it to lose accuracy and turn on the wrong lights which made the whole process of walking up and down the stairs very disorientating. Of course, there was the option of just turn on your room lights but again that's just no fun.
Step 2: Parts List
Okay so the amount of parts you need is really dependent on the number of steps you have on your staircase, so if you see "dependent" it means you need to figure out how much you need for your stairs.
- An Arduino Mega (Here)
- Light sensors Dependent (Here)
- lasers Dependent (Here)
- Buck Converter (Here)
- 12 Volt Power Supply (Here)
- Mosfet Dependent (Here)
- LED Strip (Here)
- Looooots of wire
Now, I have 14 steps so I will be getting 15 MOSFETs, 15 light sensors, and 14 lasers. Make sure to always get an extra light sensor and MOSFET because we are going to use them for something else later.
Step 3: Wiring Everything Up
Since I have so many steps I'm going to have to wire things up one at a time to makes things a little easier, so let's start by wiring up our light sensors. Now you'll see on the light sensor that it has 3 pins, two of these are power (5 volts and ground) and the other is the source pin which gets plugged into the Arduino. The way to do this is we connect all the sensors power pins together in parallel and then into the Arduino's 5 Volt and Ground input, this will supply power to all the sensors. Then we are going to connect each signal pin to the Arduino's analog pins with the first light sensor getting connected to A0, second to A1, third to A2 all the way to the last which gets connected to A14.
Next, we are going to connect up the lasers, this parts pretty easy as all we have to do is connect them all in parallel just like we did with the power pins of the light sensors. Then we are going to want to connect the positive and negative output of these lasers to the positive and negative output of our buck converter which will be stepping down 12 volts to 5 volts for use by our lasers. Now the positive input of the buck converter gets connected to the positive output of our power supply, leave the negative connections unconnected for now as we are going to use our MOSFETs for that later.
Now we need to get our LED strip ready, the first thing to do is cut it into individual strips, then every strip will have its positive input soldered together and then connected to the positive output of the power supply then each LED strips negative input needs to get soldered to its own MOSFET but we will talk more about this in the next step.
lastly, we are going to want to connect the positive output of our power supply to the VIN pin on our Arduino and the ground output to ground on the Arduino.
Step 4: MOSwhat?
So when we think about turning on and off an LED using a microcontroller it seems pretty basic, all we do is making the pin its plugged into HIGH or LOW but things get a little more complicated when we want to power a bigger load like a 12 volt LED strip and so to achieve this we need the help of a MOSFET.
A MOSFET is really just a switch that can be turned on and off by a computer, you'll see that it has 3 pins, the first one is Gate, second is Drain and third is Source. When gate is made HIGH by a microcontroller it connects drain and source allowing the current to flow however when gate is LOW it breaks this connection stopping the flow of current, this allows our microcontroller to control these high power components without having to supply power to them.
So let's get to the wiring, we are going to need 15 N-channel MOSFETs (your stairs may need a different amount), 14 for the step lights and one to turn off the lasers when its daytime (this is also why we have an extra light sensor). We are then going to solder the ground connection of each LED strip to the middle pin (drain) of a MOSFET when this is done you should have the same amount of MOSFETs as you do steps, in my case, it's 14. Now we need to solder the negative input from the buck converter to the middle pin of the last MOSFET.
Now we need to solder the source pin on all the MOSFETs together, this creates a common ground which we can then connect to the ground output of our power supply and then lastly we need to connect gate on the MOSFET to the digital pin on our microcontroller, the MOSFET of the first light gets connected to pin 32, the second to pin 33, third 34 all the way to the last light MOSFET which gets connected to pin 45 and then the MOSFET controlling the lasers gets connected to pin 46, all of this will become more clear when we talk about the code in the next step.
Step 5: Code
The code can be found below but let's just take a second to see how it works so that you can adapt it to work with the number of steps you have.
So the first thing we see is the void setup, we are just stating that pins 32 to 47 will act out outputs turning the MOSFETs on an off, now if you have more steps be sure to add more outputs and if you have less remove some just make sure to keep the laser's output so we can turn them off during the day.
Next, you'll see the void loop which is where the beef of the code is, the first thing we see is that analog pins A0 to A14 are reading data from the light sensors, like before if you have more steps you need to copy and paste some of this or if you have less you're going to need to delete some.
Which brings us to our most important part of the code, the if statements. The first if statement states that if the value sent back from our light sensor in charge of checking if its night or day is below 220 to turn on the laser or if not to turn off the lasers. Then the second one (which is almost the same as all the following ones) states that if the light sensor from that step AND the day and night sensor both send back a low-value indicating that the light has been broken to turn on the MOSFET controlling the light for the step you're on, the step in front of you and the step behind you. Now if you have more steps you need to copy and paste these if statements and add the correct pins to it and if you have fewer steps you can just delete the if statements of the steps you don't need.
This does get a little complicated so if you have any issues what so every ill be happy to answer them in the comments or in private messages.
Step 6: Mounting Everything
Okay so at this point everything is almost done and ready to go all we need to do now is mount all the components to our stairs and make a case around our Mega! This is very easy to do with some cardboard and hot glue.
So let's start mounting everything, the lasers, light sensors and LED strips can all get mounted on each step making sure that the laser beam hits the light sensor right in the middle of the photoresistor, this can be accomplished with hot glue or any kind of adhesive that dries quick. Now we can give everything a final test before we secure all the wires in place with electrical tape to make it look a little neater. Now we need to mount our day and night sensor in a play that will get a good bit of sunshine during the day which will allow it to turn off the lasers.
Then a box can be built around the Arduino and MOSFETs to keep them safe and everything is just about done! If you have any issues getting this working or have any questions ill be available to answer them in the comments or in private messages!