loading

Hello Everyone!

This is my first Instructable so please bare with me. Any comments and suggestions will be greatly appreciated! I wanted to share my project in the hopes it can simplify your research, planning, design and execution. Like with any project, it's always a good idea to research anything and everything about the subject matter in order to grasp the different technologies available and challenges you might face. There are many solutions to each idea, and some work better or worse depending on your skill and knowledge level. I hope I can share in this instructable something that's helpful to you, and wish you luck on your build!

If you are reading this, you are probably planning on adding some "flair" to your staircase. I was in your shoes and it may be overwhelming with the different options people use to add lights to stairs. My design uses an Arduino micro-controller, motion sensors, which serve as the brains of the build, WS2812B LED strips to light up the stairs and a 5V 60A switching power supply to provide the juice for the system.

There are different types of micro-controllers that can be used, Raspberry Pi or Arduino to name the two most common. I decided to go with Arduino since it already has the Neopixel library, which makes coding significantly easier. Coding level/experience should be considered in this step. Arduino is very easy to pick up since it is just a modified version of C and there is a huge community available to assist you with any coding questions or issues you may run into. There is a lot of support from the Adafruit community as well. Throughout this instructable I will post links to websites that may be helpful during this build. There are many different lighting options that can be used, for example, an LED light strip, LED lights, Neopixels (which is just fancy for WS2812B LEDS) and many others. I decided to go with WS2812B LED strips because I wanted the flexibility of controlling each individual pixel. This makes the design more versatile in the long run. I planned on making various sequences for different holidays and using WS2812B I can make any LED any color I want, which I thought is pretty cool! So the first step is to decide which type of lighting solution to use and exactly what you want your stair lights to do!

The power supply was sized according to a few simple calculations required by the load of the LED pixels. It is always a good idea to slightly oversize your components and use the worst case scenario in your calculations, to ensure that you don't starve or over stress components - which could lead to failures and premature wear of your electronic components. In addition, incorrect component sizing can lead to excessive heat, which can melt wires and cause a fire. Don't be afraid to ask questions before implementation if you are unsure of anything at all. Improper design can result in injury and/or waste of resources. In the end, a DIY solution is ultimately a way to have cool and unique things without having to pay a fortune for it, but it's got to be done right and safely.

*CAUTION: There is always a risk of personal injury and equipment damage when handling and dealing with electronics. You are expected to follow all usage instructions for tools and equipment required for this build. I am not responsible or liable for any injury or damage as a result of following this instructable. Please proceed at your own risk. Never work with live wires. Always remember to disconnect power from the source when connecting/soldering wires. (Remember: just because a power supply is turned off that it can still malfunction and run current through the wires, which can kill you!) Good Luck!

This sums up the overall idea of the project and covers some of the major components used in this build. I will try my best to outline the design and build process step by step and with as much detail possible. However, I'm sure I might miss something - and that's what the comments section is for. If you find this instructable useful, please share, rate and/or comment. I will greatly appreciate the support and will do my best to answer questions you may have, if I have the answer. If not, others on this website, more knowledgeable than me, are welcome to assist as well.

This is a video of ,my build in action!

Step 1: Materials

Below are a few expectations and goals I set going into this project, which also factored into my parts selection:

  1. Low budget
  2. Impressive yet functional final product
  3. Power efficient
  4. Minimal modification to stairs (to protect structural integrity of the staircase)

Below is a list of the major parts used in this project. They are fairly inexpensive and, with a simple google search and some shopping around, you can find them without investing a fortune. If you're a frequent DIYer you may have some of these components laying around.

  1. 1x Arduino Uno (e-bay)
  2. 2x PIR motion sensors (e-bay)
  3. 10M of WS2812B LED Light strip (length depends on how you want to space it out. Every staircase is different!) (e-bay)
  4. 5V 60A Switching power supply (e-bay)
  5. 100ft of 18AWG data wire (green) (e-bay)
  6. 100ft of 18AWG power wire (red, black) (e-bay)
  7. Extension cable or a standard power cord for a computer (old parts)
  8. Soldering iron + solder wire, etc. (previously bought)
  9. Shrink wrap (e-bay)
  10. Mounting tape (big box store)
  11. Clear silicone (big box store)

I may be missing a few materials but it's things like jumper wires for testing, electrical tape, etc.

Hint: E-bay has a great selection of electronic parts and most of the parts for this build were ordered from e-bay. Some argue that e-bay sells junk stuff and china stuff is garbage. But the truth of it is, it depends on what you are looking for. All this stuff is made in China anyway and shipped to the US and marked up like crazy. So if you have the time to wait for shipping (usually 2-3 weeks), I would highly suggest going that route to save you a decent amount of money!

Step 2: Design and Testing

I started designing my build by determining the number of pixels I wanted and how I wanted it to look. I had some standard LED RGB strips laying around so I experimented with those and determined I wanted 35 pixels on each step. Testing showed me the amount of light dispersion I liked. The number of pixels will be different for each setup. The width of my stairs is a little shy of the standard 3'.

Once I determined the number of pixels, I ordered the light strips. This was by far the most expensive part of the entire build. WS2812B is a fairly new technology; if you wish, you can go with the cheaper alternative of one-color LED strip or an RGB strip. However, with a simple RGB strip, the entire strip will be of the same color. Also, if you use a different strip, your code will need to be modified and will not work with my code. In addition to the color options, using a WS2812B LED strip had the benefit of having only 1 output on the arduino.

Originally, I planned to use the regular strips, which would have required me to use 16 outputs on the arduino (1 for each step) since I wanted the lights to light up step by step up or down depending on which motion sensor was tripped. However, on the arduino UNO, there are only 6 PWM outputs and the arduino MEGA has only 14 PWM outputs. So this was one of the major limiting factors of why I chose the WS2812B LED strips instead of the traditional RGB light strip. The other limiting factor was if I wanted to utilize all 3 colors on each of the 16 strips, that would mean 16*3 = 48 channels/outputs would be needed. Keep this in mind while designing your build. There are other controllers available which support this many channels, but in the end, it would cost more than just going with the WS2812B LED strip.

Learning NeoPixel

You should have done all the research about WS2812B LEDs if you intend to use them. But while you wait for your parts to ship, it's a good idea to touch up on using these LED strips. I will use NeoPixel interchangeably with WS2812B LEDs since they are the same thing.

Since I've never used WS2812B LEDs before, I needed to get familiar with the NeoPixel library. You will need to download the library for Adafruit and import it into the Arduino coding software. Below are two useful links to get you started with using NeoPixels. (I will assume you are somewhat familiar with Arduino and know how to import libraries and make sketches. If not, please reference other instructables or youtube videos on this process).

NeoPixel Library

Learn about NeoPixel Library

The above links contain very thorough description of how to use, code and power NeoPixels. They also include a test sequences, which I initially used to test the strand of LED to ensure there are no bad pixels. This is highly recommended so you can exchange the product if there are some bad pixels. Or you can simply cut them out and re-solder to required length.

There are also numerous projects people have done with NeoPixels in the past which are interesting to reference.

Attached program, named "test2," is a test program that just runs through same different loops. I used it to learn the different capabilities of the LED strip and familiarize myself with some of the coding. I believe this program was downloaded from the Adafruit website. I do not take credit for the code.

Once I was familiar with how NeoPixels worked, I found an instructable that was very helpful and similar to a build I was planning. I will link his instructable because I think it is also a good reference to use while you plan your build. The author goes a bit more in-depth, and I would like to thank him for taking the time to post it. I found it very helpful, and was able to adapt his code.

I assume you have some knowledge of arduinos and wiring so to keep this shorter, I skip some of the obvious details. Also, as I mentioned before, each build is unique so it's not as straightforward as just copying this instructable. It also depends on what type of parts you use, so I expect you do some research into what components you are using.

Instructable Link. His name is Simon Jowett.

Small Scale Testing

Okay, let's get to small scale bench testing. Once I received the light strips, I cut them into 35 pixel lengths. Another benefit of WS2812B LED light strips is that they can be cut every pixel and still function properly instead of every 3 LEDs with the traditional LED strips. I used one of the 35 pixel lengths to test some different kinds of effects and scaled down the entire design to utilize only 35 pixels. So in theory, I had 6 stairs with 5 pixels on each step.

So I wanted the individual strips of light on each step to light up in the order tin which he motion detector is tripped. Review the schematic attached in this step to see the set-up of the overall build. I'm using two PIR sensors that detect if the person is walking up or down the stairs. An LDR is a Light-Dependent Resistor, also known as a photoresistor. This resistor changes values based on how much light is exposed over the resistor. Currently, the sensor is not attached, but I plan on adding it soon to save on operation cost. Currently, the setup is working 24/7. (Side-note: I've made some basic calculations and while it works 24/7 it costs around $11 annually). You can learn more about how to add an LDR to the arduino using other instructables or follow this example. In short, you connect the LDR to an analog port on the arduino so you can use "analogRead()" command in your code to see the value of the resistor.

I'll briefly explain why I chose the loop back method when connecting the lights instead of just daisy chaining them. (you might understand better when you see the code further in this report and I will also elaborate on this topic) Daisy chaining the LEDs will result in a ZIG-ZAG LED matrix.

So if I want to run a basic for loop to power up all the LEDs from start to finish, the code will look something like this:

for(uint16_t n = 0; n < strip.numPixels(); n++)

{

strip.setPixelColor(n , strip.Color(255,255,255));

}

So this code basically sets the color of each LED starting at LED 0 to the color full brightness white (255,255,255) and it continues doing this while increasing the counter until it reaches the last LED (n < strip.numPixels() ).

Note, to apply this code in the daisy chain situation, the LED strip will first light up from right to left, then at then next step left to right and so on until it reaches the last LED. So if you can picture this in your head, it will not light up the LEDs starting from the same side on each step. The LEDs light up in a Zig-Zag motion. This is why I highly recommend using a little extra wire to wire up the strips according to my diagram. This will simplify coding significantly!

Step 3: The Code

I used and modified the code written by Simon Jowett.

There are some functions in the code that are not used, but I left them in case I would like to use them later. When I have more time, I will be adding to this code to run different light sequences for different holidays. Ultimately, I would like to write an app so I could change the sequence from my phone without having to upload new code every time I want to run a different sequence. This is why it is important to think of the flexibility in the design phase so you can be prepared for whatever you want to do without having to rebuild and change your LED strips.

If you have any questions about the code, feel free to leave a comment below and I will do my best to answer since I didn't do the best job at commenting it.

Step 4: The Build

The build will be unique with every staircase. I had to remove the drywall covering the underside of the stairs to route the wires. I drilled a small hole on either side of the staircase on each stair. This allowed me to route the power and data cables so they are hidden. While wiring, be sure to test each stair and your progress to limit the amount of debugging/troubleshooting if a problem is identified after completion. I used heat shrink on all the strips to give it a clean and professional look. Reference the previous step for the wiring diagram to see how I wired each strip. There are a total of 15 strips and each strip has 35 LEDs.

Suggestions:

  1. Plan out your build before you start to drill anything!!! This includes wiring/mounting, etc.
  2. Test each strip as you go.
  3. Practice soldering.
  4. You may pre-solder wires on each strip. (I just cut and soldered wires as I went up the stairs.)
  5. Secure wires so they are not pinched or cut when installing the drywall. (regardless of the stairs, clean wiring will be helpful in debugging later on).

As mentioned, each build will be different so it's up to you how you want to proceed. I included pictures of my build in this step.

Watch the build video below:

Step 5: Final Solution

Once I mounted all the strips, I tested the lights to make sure they all work. I will attach molding in front of the LED strips to completely hide them. I decided to wait on this step to make sure everything is functioning before I attach the molding.

Make sure you fully test the final project before covering everything in case there are problems and you need to troubleshoot the circuit and or connections.

Below is a video of the almost fully completed and function LED lighting. Notice the "breathe" standby mode and then the light turning on when the bottom sensor was tripped.

Step 6: Lessons Learned and Future Improvements

  1. Mounting tape is not the best mounting solution for the LED strips. Over time, some strips began to sag. I will be re-securing the strips with liquid nail or other heavy duty epoxy/glue.
  2. I need to add extra power injection into the circuit. Current power solution does not allow me to use full brightness. Although, I am quite happy with the current setting because at full brightness it's hard on the eyes. However, I do not want to be limited later on if I want to write code using full brightness for the holidays.
  3. Need to find better mounting solution for the PIR sensors because the range is too wide.
  4. I would like to add wifi so I can upload code without having to connect a USB. Eventually, I would like to add website functionality so I could select different codes (Christmas colors, fourth of July, etc.)

These are just the major improvements that come to mind, I may add more later.

I would greatly appreciate if you can leave a comment on how well/poorly this instructable is written and what would have been more helpful to know. Any feedback will be helpful in writing further instructables. Also, if you've done a similar build and would like to share it, I would enjoy reading about it! I will be starting a new instructable on a 32 channel christmas light controller I built from scratch for the holidays.

I hope you enjoyed reading this instructable! Good luck on your LED stair lighting. You'll see, once you do it at home, you will never want to use a staircase without LED lights!

Useful links and resources:

Arduino adafruit NeoPixel Overview (Read the "Best Practices" and "Powering NeoPixels" tab)

Jowett "how to bling up a boring staircase" instructable

PIR Sensors How To

<p>Hi there snikogos, first of all, thank you for sharing your projekt. I think is AWSOME!! I bin look for this for weeks!!!!. Is there a away we could be in touch for a few quetions becaus if you ancer here i will never find it again. LOL Maybe Email sicarius75 at gmx.de.</p><p>if it ok 1 quetion right away. Can i use a <a href="http://www.ebay.de/itm/201543170253?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT" rel="nofollow"> ESP8266 NodeMcu V3 Lua WIFI <br></a></p><p>that would solve you inprovment Nr. 4 :D</p>
<p>Dear Snikogos, Thank you very much for the great instructables! I'm not very fit in the arduino code, so please I hope you help me. Where is the line who can the time adjusted for the light on after is a motion detected. the light is to long on for my situation. and another question. do you have checked the solution with the PIR and the LDR inside(video from SimtechBen)? If so, what would I have to change the code that the stair lighting only when it is dark?</p><p>Nice greetings!!</p>
<p>Great work, Snikogos! I studied different possibilities for stair lighting available on the Web and your solution seems to be the most advanced. Also, your instructable is excellent! There are 1-2 other DIY solutions on the Web, but those are worse and contain some problem or a catch. This kind of lighting brings a feeling of exclusivity to the interior, even to us who cannot afford ridiculously expensive.commercial solutions. This is a great example of the DIY purpose and a motivation to step into the DIY world. Thank you!</p><p>I look forward to ordering the components and trying it. Although WS2812B LED Light strip is several times more expensive than a usual LED strip (where single LEDs are not controllable), it is still inexpensive (I found it at AliExpress at 11 $ per 5 meters of 30 LED/m string, while 60 LED/m version such as the one you used costs 14 $ for 5 m).<br></p><p>From your video it seems that in inactive state 2 outer LEDs on each stair remain continuously fading in and out (until the sensor is activated). I like this idea, I would just try to modify your program to leave those LEDs alway on (slow fade-in, remain lit, quick fade out when the sensor is activated and then start the animation). It would also be nice to add a button to the board that would change the color with each click (rotation of several preset colors), while a long press of that button (2-3 seconds long) would switch the set off/on (in and out of standby).</p>
<p>how pir sensors working in your project ? i cant understand... bcz i trying to make but have doubt that if one person goes up stairs then down stair sensor detects and activates after person reaches to upstairs sensor then it detects and what action it do ? plz suggest me i am try to make using pir sensors and lights system by using relays . if you have any code plz share me.. samee14326@rediffmail.com </p>
<p>Hi Snikogos,</p><p>very well made project. Im working on the same thing, and i have my prototype on my desk with your code. Its kind of working, but not fully. I have 14 steps and for now i have only 1 LED per step, so im trying to find in this code where i need to change to make it work. Can you help me with that? Im new to arduino thing and still learning. Thank you.</p>
<p>Hi Snikogos,<br></p><p>Very amazing instructable. Thanks. I also have a <br>working test setup with 150 leds. I devide this into 10 steps of 15 <br>pixels each. Now I am also trying to incorporate the fading effect. If <br>possible per step (15 pixels at a time) and not per pixel.</p><p>Also to<br> overcome the &quot;slowliness&quot; as you mention I would like to light-up the <br>first 5 steps as per your design (fast) and the other 5 with the fading <br>effect. Now you have provided some coding steps to achieve this, however<br> I am not able to get this going. Can you please share your complete <br>function (colorwipeup /colorwipedown) for the fading effect as you <br>tested? From there I will probably be able to resolve my issue. Thanks <br>again for this great instructable.</p><p>Marlon.</p>
<p>Hello and thanks for a sharing this amazing project. :)</p><p>I'm using your code in my test setup (will build the stairs later), so for now i only have a 2x1 meter ws2812b strip with totalt of 60 leds. I then use 6 leds for each step and 10 steps of total. Everythings is working as i should, PIR's are working and the blue breathing.</p><p>But, i have tried for a long time now to make the leds (for each steps) to slowly fade in (like a glow effect) instead of be turned on right away. And also the same way when the leds go out, that they will slowly fade out.</p><p>I really hope there is someone here who could lead me in the right way with the code (im new to coding, but learning everyday :) <br>I do understand its the colourWipeUp and ColourWipeDown who turn on and off the leds, but i really cant figure out how to turn them on / off with a fade function..</p><p>Thx in advanced..</p><p>Vidar..</p>
<p>Hellow Vidar,</p><p>To acheive a fading effect you have to write a for loop to loop through brightness values 0-255. And an algorithm to make each RGB value at each brightness. below is a code snippet of what I am talking about:</p><p> for(uint8_t b=0; b &lt;255; b++) { \\for every brightness from 0 to 255</p><p> for(uint8_t i=0; i &lt; strip.numPixels(); i++) { //turn on each pixel i until less than the strip length</p><p> strip.setPixelColor(i, red*b/255, green*b/255, blue*b/255); // this keeps the correct RBG color but controlls the brightness</p><p> }</p><p> strip.show();</p><p> delay(wait);</p><p> };</p><p>You would put this in the colorwipeup/colorwipedown functions.</p><p>I had tried fading myself when I was coding but found it impractical because it takes so long to light up each step. So do some testing. When i activated one of the sensors, I could be at the top of the stairs already and the arduino is still fading the steps. So a slow fade on is not practical. A fade out might look nice.</p><p>Hope that helps! Good luck!</p>
<p>Hey snikogos<br>Very good work, i am impressed!<br>I would like to build it.<br>But I like to realize with the Fade-Efect, but that is very difficult.<br>Can you please upload the complete code?<br><br>that would be nice</p>
<p>Thx for the reply snikogos :)</p><p>But ofcourse, after alooot of trying and compiling, no result for me :/<br>I have tried alot of different things, but no luck.. So, if you could tell me where to put your lines in (and which to delete if i need to), i would be really happy :)</p><p>Here is my part of the code, i even put in a little more than i need (i think), becuz im sure the lines you gave me is needed in the bottom part of the code i paste here:</p><p> void bottomup() {</p><p> Serial.println (&quot;detected bottom&quot;); // Helpful debug message</p><p> colourWipeUp(strip.Color(255, 255, 250), 400); // Warm White</p><p> for(int i=0; i&lt;3; i++) { // Helpful debug indication flashes led on Arduino board twice</p><p> digitalWrite(ledPin,HIGH);</p><p> delay(200);</p><p> digitalWrite(ledPin,LOW);</p><p> delay(200);</p><p> }</p><p> }</p><p> // Fade light each step strip</p><p> void colourWipeDown(uint32_t c, uint16_t wait) {</p><p> for (uint16_t j = 0; j &lt; 10; j++){</p><p> int start = strip.numPixels()/10 *j;</p><p> Serial.println(j); </p><p> for (uint16_t i = start; i &lt; start + 6; i++){</p><p> strip.setPixelColor(i, c);</p><p> }</p><p> strip.show(); </p><p> delay(wait);</p><p> }</p><p>It also said that red, green and blue was not defined, so i tried to put in in the void colourWipeDown line, and added &quot;uint8_t red&quot; and the same for green and blue, but no luck..<br>Im sorry, im not so good in using the c+ coding language :/</p><p>And when it come to what you said about it was to slow, i can imagine that. But i still want to try, and rather adjust the fading speed.</p><p>Thx again for helping me :)</p>
<p>thank for your advice ...its 21 steps and i have to make 3 - 4 relays only by every 5 steps one relay to turn on 5 steps at once . i am weak in coding ... i made some code from your coded file... plz try to solve . problem is its looping against one function which is selected first .. {if first selected up pir sensor then only up pir sensor working and down pir sensor not detecting... } </p><p>program :</p><p>unsigned long timeOut=6000; // timestamp to remember when the PIR was triggered. </p><p>int ledPin = 13; // choose the pin for the LED</p><p>int downUp = 0; // variable to rememer the direction of travel up or down the stairs</p><p>int alarmPinTop = 4; // PIR at the top of the stairs</p><p>int alarmPinBottom = 3; // PIR at the bottom of the stairs</p><p>int alarmValueTop = LOW; // Variable to hold the PIR status</p><p>int alarmValueBottom = LOW; // Variable to hold the PIR status</p><p>int pirState = LOW; // we start, assuming no motion detected</p><p>int val = 0; // variable for reading the pin status</p><p>void setup() {</p><p> Serial.begin(9600);</p><p> pinMode(ledPin, OUTPUT); // declare LED as output</p><p> pinMode(alarmPinTop, INPUT_PULLUP); // for PIR at top of stairs initialise the input pin and use the internal restistor</p><p> pinMode(alarmPinBottom, INPUT_PULLUP); // for PIR at bottom of stairs initialise the input pin and use the internal restistor</p><p> delay (200); // it takes the sensor 2 seconds to scan the area around it before it can </p><p> //detect infrared presence.</p><p>}</p><p>void loop(){</p><p> alarmValueTop = digitalRead(alarmPinTop); // Constantly poll the PIR at the top of the stairs</p><p> //Serial.println(alarmPinTop);</p><p> alarmValueBottom = digitalRead(alarmPinBottom); // Constantly poll the PIR at the bottom of the stairs</p><p> //Serial.println(alarmPinBottom);</p><p> if (alarmValueTop == HIGH &amp;&amp; downUp != 2) { // the 2nd term allows timeOut to be contantly reset if one lingers at the top of the stairs before decending but will not allow the bottom PIR to reset timeOut as you decend past it.</p><p> timeOut = millis(); // Timestamp when the PIR is triggered. The LED cycle wil then start.</p><p> downUp = 1;</p><p> Serial.println(&quot;downup=1&quot;);</p><p> //clearStrip();</p><p> topdown(); // lights up the strip from top down</p><p> }</p><p> if (alarmValueBottom == HIGH &amp;&amp; downUp != 1) { // the 2nd term allows timeOut to be contantly reset if one lingers at the bottom of the stairs before decending but will not allow the top PIR to reset timeOut as you decend past it.</p><p> timeOut = millis(); // Timestamp when the PIR is triggered. The LED cycle wil then start.</p><p> downUp = 2;</p><p> Serial.println(&quot;downup=2&quot;);</p><p> //clearStrip();</p><p> bottomup(); // lights up the strip from bottom up</p><p> }</p><p> }</p><p> void topdown() {</p><p> Serial.println (&quot;detected top&quot;); // Helpful debug message</p><p> //for(int i=0; i&lt;3; i++) { // Helpful debug indication flashes led on Arduino board twice</p><p> digitalWrite(ledPin,HIGH);</p><p> delay(5000);</p><p> digitalWrite(ledPin,LOW);</p><p> delay(50);</p><p> Serial.println (&quot;delay 50&quot;);</p><p> //}</p><p> }</p><p> void bottomup() {</p><p> Serial.println (&quot;detected bottom&quot;); // Helpful debug message</p><p> //for(int i=0; i&lt;3; i++) { // Helpful debug indication flashes led on Arduino board twice</p><p> digitalWrite(ledPin,HIGH);</p><p> delay(5000);</p><p> digitalWrite(ledPin,LOW);</p><p> delay(50);</p><p> //}</p><p> }</p>
<p>Arduinos and i believe any microcontroller does not support multithreading meaning, it cannot perform 2 tasks at once. For example, it cannot monitor the bottom sensor while the top has been activated. I dont understand why you need the bottom sensor polling if the top sensor has been activated. If the top sensor is activated, then the lights are on so there is no need to activate the bottom sensor.</p><p>If the issue is that it takes the person longer to go down the stairs and the light turn off, I would suggest increasing the delay time that the lights stay on for. Or using a PIR sensor and mount it up high to monitor the entire stair area and code in such a way that the light stay on when the sensor it triggered.</p><p>There are ways to make the arduino do 2 things at once through using millis and or coding. I do not have much experience coding in this way but you can search for &quot;arduino multithreading&quot; and research how this is done through coding. With using the &quot;delay&quot; function, you prohibit the arduino to do any other tasks, therefore while using millis. Also interrupts can help you acheive what you want. </p><p>https://www.arduino.cc/en/Reference/Interrupts</p><p>I hope that helps. </p>
<p>you told right . its not supporting multi threading. now i am facing a problem is i am using 4 relays to control 4 separate powered led strips of 5050 . i need output like if persons travels down stair to up stairs . down pri detected and relays to start like relay1 on and next relay 2 ,relay3 . ... after person reaches top pir . have to off in reverse mode like relay4,3,2,1. and same while top to bottom stairs . i am facing the problem is when bottom pir detects and person travels to up stairs then top pir sensor detect and reserving the process and after down stair process completed , the reserved process starts .. plz solve the problem... for testing i used 1 relay..</p><p>the code is :</p><p>unsigned long timeOut=6000; // timestamp to remember when the PIR was triggered. </p><p>int ledPin = 13; // choose the pin for the LED</p><p>int downUp = 0; // variable to rememer the direction of travel up or down the stairs</p><p>int alarmPinTop = 4; // PIR at the top of the stairs</p><p>int alarmPinBottom = 3; // PIR at the bottom of the stairs</p><p>int alarmValueTop = LOW; // Variable to hold the PIR status</p><p>int alarmValueBottom = LOW; // Variable to hold the PIR status</p><p>int pirState = LOW; // we start, assuming no motion detected</p><p>int val = 0; // variable for reading the pin status</p><p>#define RELAY1 12</p><p>void setup() {</p><p> Serial.begin(9600);</p><p> pinMode(ledPin, OUTPUT); // declare LED as output</p><p> pinMode(RELAY1, OUTPUT); // declare relay1 as output</p><p> pinMode(alarmPinTop, INPUT_PULLUP); // for PIR at top of stairs initialise the input pin and use the internal restistor</p><p> pinMode(alarmPinBottom, INPUT_PULLUP); // for PIR at bottom of stairs initialise the input pin and use the internal restistor</p><p> delay (200); // it takes the sensor 2 seconds to scan the area around it before it can </p><p> //detect infrared presence.</p><p>}</p><p>void loop(){</p><p> alarmValueTop = digitalRead(alarmPinTop); // Constantly poll the PIR at the top of the stairs</p><p> Serial.println(alarmPinTop);</p><p> alarmValueBottom = digitalRead(alarmPinBottom); // Constantly poll the PIR at the bottom of the stairs</p><p> Serial.println(alarmPinBottom);</p><p> if (alarmValueTop == HIGH &amp;&amp; downUp != 2) { // the 2nd term allows timeOut to be contantly reset if one lingers at the top of the stairs before decending but will not allow the bottom PIR to reset timeOut as you decend past it.</p><p> timeOut = millis(); // Timestamp when the PIR is triggered. The LED cycle wil then start.</p><p> downUp = 1;</p><p> Serial.println(&quot;downup=1&quot;);</p><p> //clearStrip();</p><p> topdown(); // lights up the strip from top down</p><p> }</p><p> if (alarmValueBottom == HIGH &amp;&amp; downUp != 1) { // the 2nd term allows timeOut to be contantly reset if one lingers at the bottom of the stairs before decending but will not allow the top PIR to reset timeOut as you decend past it.</p><p> timeOut = millis(); // Timestamp when the PIR is triggered. The LED cycle wil then start.</p><p> downUp = 2;</p><p> Serial.println(&quot;downup=2&quot;);</p><p> //clearStrip();</p><p> bottomup(); // lights up the strip from bottom up</p><p> }</p><p> }</p><p> void topdown() {</p><p> Serial.println (&quot;detected top&quot;); // Helpful debug message</p><p> //for(int i=0; i&lt;3; i++) { // Helpful debug indication flashes led on Arduino board twice</p><p> digitalWrite(ledPin,HIGH);</p><p> delay(8000);</p><p> digitalWrite(ledPin,LOW);</p><p> digitalWrite(RELAY1,HIGH);</p><p> delay(5000);</p><p> digitalWrite(RELAY1,LOW);</p><p> Serial.println (&quot;delay 50&quot;); </p><p> alarmValueBottom = LOW; </p><p> downUp = 0;</p><p> //} </p><p> }</p><p> void bottomup() {</p><p> Serial.println (&quot;detected bottom&quot;); // Helpful debug message</p><p> //for(int i=0; i&lt;3; i++) { // Helpful debug indication flashes led on Arduino board twice</p><p> digitalWrite(ledPin,HIGH);</p><p> delay(8000);</p><p> digitalWrite(ledPin,LOW);</p><p> delay(500);</p><p> downUp = 0;</p><p> //}</p><p> }</p>
<p>thank you for your information.. is there any function other than millis()</p><p> i wan't minutes to delay.. thank you.</p>
Millis is milliseconds.
<p>hi, i have doubt that if 3 persons passes from bottom pir sensor with between 10sec difference from one to another .. and also continue passes from top pri sensor with 10sec difference . what is the output of led lights ? </p><p>does it reserve detected 3 times and start cycle 3 times ?</p>
<p>Great tutorial!</p><p>Can you make a close-up photo of the connections. I connected according the scheme but the LED strip doesn't light up. </p>
<p>There are 3 connections if you're using a ws2812b LED strip. Data in (from an arduino pin), +5V DC power and Ground (GND).</p><p>Hope that helps.</p>
Thnx!
​great work and the details of your work are just amazing, i intend to replace the LED strips with rings, and would like to seek your help and advice. Mind to contact in email so not to flood the comments here? chowyen@hotmail.com.. cheers
<p>Contact me through here with your questions. I am not familiar with how the rings work, but if it is ws2812B then it should be similar addressing to activate the LEDs</p>
<p>plz give your email or contact me on my email address :samee14326@rediffmail.com</p>
<p>samee14326@rediffmail.com</p>
<p>thank you for your valuable response to my quires. WS2812B led strip is very expensive so i decided to make with normal 5050 rgb led strip with 24 key remote. i need your guidance i want to build with {Arduino, 2 pir motion sensors, 1 relay module, some meters 5050 led strip , power adapters} . the concept is same as like your but only thing is that there is normal 5050 rgb led strip ... i am expecting output that if a person travels from down stair then down pir motion sensor send signal to arduino and arduino hold off up-pir sensor and turn on the relay module through relay led strip gets on . for few minutes it release to normal . and if up-sensor detects first then down sensor put on hold.. like that plz .... also ldr continue active when no light... </p>
How many steps do you have? The below relay would allow you to control up to 16 channels/steps:<br>https://www.amazon.com/SainSmart-101-70-103-16-Channel-Relay-Module/dp/B0057OC66U<br>Arduino uno has 14 digital IOs but if you do a little research, i think you can use the analog outputs like a digital 1. <br><br>As for coding, search an instructable that shows you how to activate the relays. And you can add delay (waittime) between activating eacg step relay to get you desired look and functionality. See in comments below about adding an ldr to the pir sensor so it only activates in dark light. <br><br>Unfortunately i do not have time to straight up write a code for you but if i do find time, i can help you debugged/plan the code. <br><br>Let me know if you have any other questions. Wish you luck on your build!
<p>i want a program for it ... thanking you ... </p>
<p>Big clive has a video to show how to add the LDR to the PIR module so that you don't have to use a pin on the arduino. And then it doesn't need to be in the code either.</p><p><br><iframe allowfullscreen="" frameborder="0" height="281" src="http://www.youtube.com/embed/2dxhbXHYEG0" width="500"></iframe></p><p>Do your PIR modules have this capability?</p>
Awesome find SimtechBen. thank you for the share, i will definitely have to try this out and I will let update on how this works! <br><br>Have a great day!
<p>Hi, and thanks for sharing this wonderful Instructable. I have one question.</p><p>It's hard to see, but from the build video it appears that there may be exposed soldered circuitry under each step where the power wire joins each section of the LED strip. If this is the case, is there potential risk of a short and/or shock if someone reaches in and touches those junctions?</p><p>I am thinking of a similar build, but in my case the LED strip and power connections will be fully exposed against the side of the steps and therefore more accessible to users than yours. So I want to be sure I am not exposing anyone to shock.</p><p>Thank you. </p>
Thank you dallas Sommers. Take a look at all of step 4 images. there is a close up of how i terminate the led strips to protect all circuitry to prevent shocking anyone! I use a dot of silicone and i think it was 1/2&quot; heat strink to termimate each end where wires were soldered. <br>I would suggest doing this in a similar manner and never leaving circuits exposed especially is there are kids of animals around. <br><br>Although 5 volts and the low amperage wont kill anyone, it will prolong the life of your project meanwhile keeping everyone safe. <br><br>Wish you luck on your build and feel free to share pictures once youve completed it!<br><br>Let me know if you have any other questions.
That makes sense...thank you very much.
<p>You're very welcome! Good luck!</p>
<p>and also </p><p>6. how to set random color change at every single cycle... </p>
<p>See below post.</p>
<p>its amazing very very impressive . i have some doubts and quires . </p><p>1. how to control brightness of all led's</p><p>2. which led strip you used WS2812B is 150/meter or 300/meter/ 5050 led? and also is there any compatible led other than ws2812b . </p><p>3. is smps is mandatory or we can use laptop charger or any other charger which having same power output.</p><p>4. how to slow down lights at every step slowly glowing step by step ? and after walk away step by step slowly off like fade/smooth effect ! </p><p>5. how to add display and some new modes . </p><p>i am going to build it please .</p>
<p>Thank you for the positive feedback samee14326. Sorry for the late reply, see my feedback to your questions below. </p><p>1. colourWipeDown(strip.Color(50, 50, 30), 40); // Warm White</p><p>the brightness is controlled by 0-255 values for the RGB values. 0 is off and 255 is the brightest. In my case, 50,50,30 is a warm white at about 20% brightness.</p><p>2. I used 300/meter and have about 10 meters. My code currently works with WS2812b pixels.</p><p>Adafruit_NeoPixel strip = Adafruit_NeoPixel(525, PIN, NEO_GRB + NEO_KHZ800);</p><p>you can change NEO_KHZ800 to NEO_KHZ400 to work with WS2811 drivers.</p><p>3. As long as you do the power calculations for your application, you can use any power supply. However, a laptop charger usually outputs 18V so you would have to set it down to 5V which is required by the neopixels. You may also use a PSU for a desktop computer by that also would require a setdown to 5v. SMP power supplies are fairly cheap and they work well.</p><p>4. void colourWipeDown(uint32_t c, uint16_t wait) </p><p>this function calls the color (variable c) and the wait time between steps. So when you call the function: colourWipeDown(strip.Color(255, 255, 250), 25 ); // Warm White</p><p>25ms is the wait time between each step.</p><p>So you can increase this number to slow down each step. I played around with this value and found 25 to be the best.</p><p>5. Take a look at this instructable to add a display: <a href="https://www.instructables.com/id/Connecting-an-LCD-to-the-Arduino/" rel="nofollow"> https://www.instructables.com/id/Connecting-an-LCD...</a></p><p>As for modes, you can write new functions and add a button to cycle through the modes and it can display which mode is activated on the LCD display. This is too indepth to answer in a question and would require a moderate/expert programming skill.</p><p>6. You would need to create 3 variables for RGB values and a random number generator to generate values from 0 to 255.</p><p>Try this in a new sketch:</p><p>void setup() {</p><p> // put your setup code here, to run once:</p><p>Serial.begin(9600);</p><p>for (int n =0; n&lt;5; n++)</p><p>{</p><p> int R = random(0,255);</p><p> int G = random(0,255);</p><p> int B = random(0,255);</p><p> Serial.print(&quot;RGB: &quot;);</p><p> Serial.print(R);</p><p> Serial.print(&quot;,&quot;);</p><p> Serial.print(G);</p><p> Serial.print(&quot;,&quot;);</p><p> Serial.print(B);</p><p> Serial.println();</p><p>}</p><p>}</p><p>This will generate 5 random RGB values and show them in Serial</p><p>Let me know if you have any other questions! Good luck on your build!</p>
<p>Ab-so-damn-lute-ly O-mazing</p>
<p>Thank you for the positive feedback michail1!</p>
<p>very nice!</p>
<p>Thank you very much MichaelM for the positive feedback</p>
<p>Very nice!</p><p>Question, how would I go about doing this (wiring, and/or programming) if I have a stair way that has a single top but two paths to reach the bottom as in the attached file. I'd like to have 3 motion detectors so that any point could set off the lights. I'd want to synch the lights for the bottom 2 paths.</p><p>Thank you!</p>
<p>Hey quix,</p><p>Thank you for checking out my instructable. You can easily add another motion detector to put on both sides of the stair entrance on the bottom. </p><p>add the following lines to the set up variables part</p><p> int alarmPinBottom2 =12; // PIR at the bottom of the stairs</p><p> int alarmValueBottom2 = LOW; // Variable to hold the PIR status</p><p>If you're using neopixels, you would have modify the number of pixels you are using: (I am using 525 PIXELS)</p><p>Adafruit_NeoPixel strip = Adafruit_NeoPixel(525, PIN, NEO_GRB + NEO_KHZ800);</p><p>add this to the void setup:</p><p>pinMode(alarmPinBottom2, INPUT_PULLUP); // for PIR at bottom of stairs initialise the input pin and use the internal restistor</p><p>add this to void loop:</p><p> alarmValueBottom = digitalRead(alarmPinBottom2); // Constantly poll the PIR at the bottom of the stairs</p><p> //Serial.println(alarmPinBottom2);</p><p>Now to modify the algorithm to control which pixels turn on in which sequence is the tricky part. you have to make a pixel chart and determine which pixel range for each step. </p><p>The following code controls which pixels to turn on:</p><p> // Fade light each step strip</p><p> void colourWipeDown(uint32_t c, uint16_t wait) {</p><p> for (uint16_t j = 0; j &lt; 15; j++){</p><p> int start = strip.numPixels()/15 *j;</p><p> Serial.println(j);</p><p> for (uint16_t i = start; i &lt; start + 35; i++){</p><p> strip.setPixelColor(i, c);</p><p> }</p><p> strip.show(); </p><p> delay(wait);</p><p> }</p><p>// Fade light each step strip</p><p> void colourWipeUp(uint32_t c, uint16_t wait) {</p><p> for (uint16_t j = 15; j &gt; 0; j--){</p><p> int start = strip.numPixels()/15 *j;</p><p> Serial.println(j);</p><p> //start = start-1;</p><p> for (uint16_t i = start; i &gt; start - 35; i--){</p><p> strip.setPixelColor(i-1, c);</p><p> }</p><p> strip.show();</p><p> delay(wait);</p><p> } </p><p>You would have to play around with the code to get it so the bottom 2 stairs activate at the same time.</p><p>I think you can also do this by tricking the neo pixels to this that 2 LEDs are the same address. See attached image, the green would be the data wires. if you y-split at the location and have wire go to each side of the bottom stairs, the strip should have the same pixel address for the two sides of the stairs. So in the attached picture, both the pixels on each step will be the 100th, 101, 102, etc. number pixel. This is easier that figuring out the code if you are not good at coding, but you lose the ability to control each step independently in the future. </p><p>I have not tested this way so it would be a good idea to do a small scale test to see if you have 1 strip and branch 2 strips ensure that the 2 strips light up identically. (see my other picture for what i mean) strip 2 and strip 3 should have the same pixel number if this will work.</p><p>Let me know if that helps! Good luck and if you complete this project I would love to see it.</p>
<p>Great stuff snikogos. I've ordered all my items from eBay and everything should be arriving here (Canada) towards early October. In the meantime, I'll be planning out where to drill the holes, how to program the arduino, etc. I'll cut a small length of the neopixels out and just play around with them at first. Thanks for explaining the y-split for my two bottom stairway paths. I'm still debating what the end product will be. I like the idea of controlling all the lights with precision. Looking forward to this project!</p>
<p>Nice, good luck with the project. If you want precision, then you will need to do some testing with the code. It won't be impossible, but it will be tricky! Let me know how it turns out! </p>
<p>Hey! Thanks for the instructable! Sorry for being such a noob and I never leave questions before try everything but no matter what I do on the code I keep receiving the same response on the serial monitor: It keeps looping on &quot;detected top&quot; and counting from 0 to 14. I've tried everything, even with the arduino alone, no sensors hooked up and it still gives me this. Can anyone help me?</p>
<p>Hey, sorry for the late reply, what kind of motion sensors are you using? Some motion sensor will send a HIGH signal when motion detected and some send a LOW signal when motion is detected. </p><p>Do a search for the model of motion sensor you have to verify how it operates. Or simply try to change the code from LOW to HIGH and see if that fixes the issue.</p><p>In my case, my sensors send a HIGH signal when motion is detected, thus i initially set them to LOW then if a HIGH signal is sent when motion is detected, it initiates the light sequence.</p><p>Change the following to HIGH</p><p> int alarmValueTop = LOW; // Variable to hold the PIR status</p><p> int alarmValueBottom = LOW; // Variable to hold the PIR status</p><p>Change the following to LOW</p><p>if (alarmValueTop == HIGH &amp;&amp; downUp != 2)</p><p>if (alarmValueBottom == HIGH &amp;&amp; downUp != 1)</p><p>Hope that helps, let me know if you have any other questions</p>
<p>Just wondering how you powered your Uno? I saw a 9V battery in one of the picutres... Assumed that was temporary. What did you use for a long term power source?</p>
<p>Thanks for checking out the tutorial. I was temporarily using the 9V to test the system. Since it's powered on 24/7 I just wired a DC connector to the 5V power supply I'm using to power the lights. The current draw from the arduino is very minimal.</p><p>Hope that helps, let me know if you have any other questions!</p>
Great work! Really great instructable, too! I am loving the &quot;breathe&quot;
<p>Thank you for your comment! I've been planning on making different idle patterns but haven't gotten around to it.</p>

About This Instructable

22,541views

165favorites

License:

More by snikogos:LED NeoPixel Motion Sensor Stair Lighting 
Add instructable to: