Give every day a colourful and useful start by displaying the outside temperature using coloured lights on your stairs, controlled by Raspberry Pi
When you wake up in the morning, wouldn’t you like to know whether you need to wear your woolly hat or your sundress? Now you can find out on your way to breakfast, thanks to Lorraine’s temperature controlled stairlights project.
The Raspberry Pi is hidden under the stairs. It connects to the web and checks the temperature. It then controls the strip of 240 lights running up the stairs. If it’s colder than 0 °C, the bottom 35 lights come on in white; under 5 °C, and the next 35 lights light up in blue; and so on up to 25 °C and red, although that probably won’t happen in Yorkshire, where it was built!
Firstly, work out which end is which on your RGB strip. We are looking for the Data In end. It should be labelled as Din. In this strip there are five cables coming from three connections: two from GND, one from DIN, and two coming out of 5V.
Connect the 5V wire to the ‘+’ block on the female jack connector plug by placing the bare wire under the terminal, then screwing the terminal down with a screwdriver. Connect the GND wire to the ‘–’ block in the same way. Pull gently on both wires to check that they’re connected.
Connect the Din and GND wires to the male ends of the jumper wires. Connect the female end to the Pi as follows: Din to GPIO pin 18; GND to any ground pin.
You could power the Pi through the other 5V wire, but this can be dangerous for the board; it is best to use a normal power supply.
Follow the steps at Adafruit to install the NeoPixel library, rpi_ws281x.
Plug the jack connector into your power supply. Plug in the power supply and test your strip using the scripts from the examples folder for some shiny lights!
You will need a developer account for a weather API to get the outside temperature for your area. We used forecast.io as it allows users to request 1,000 forecasts per day at no cost:
You could set up another Pi outside your house and get the real temperature for your neighbourhood. It depends on how much you want to spend on the project, and whether you trust the API’s accuracy.
Download stairlights.py from the box at the top of this page to the home/pi directory and change:
Line 6: enter your secret key.
Line 7: change longi and lati to your longitude and latitude coordinates. You can use Google Maps to find them: right-click on your location and select ‘What’s here?’
Set up a cron task to check the outside temperature every five minutes and update the lights.
In a Terminal window, type:
sudo –E crontab -e
At the end of the file, enter:
*/5 * * * * /usr/bin/python3.4 /home/pi/stairlights.py
@reboot /usr/bin/python3.4 /home/pi/stairlights.py
Save the changes.
If the examples from the NeoPixel library didn’t work, check all your connections. Make sure you have plugged the data wire into the correct GPIO pin on your Pi. Are you connected to Din or Dout? The lights will power on Dout, but nothing will happen.
If the lights are displaying strange colours, some people have reported the NeoPixel library not working with Pi’s setup for audio. See magpi.cc/2ovIQhy.
Make sure your script is running properly before adding it to cron. There’s nothing like sitting on your stairs waiting for five minutes for a cronjob that isn’t working to run!
We changed the cron tasks to stop the lights displaying through the night:
*/5 7-21 * * * /usr/bin/python3.4 /home/pi/stairlights.py
*/5 7-21 * * * /usr/bin/python3.4 /home/pi/nightynight.py
…where nightynight.py is a simple script that turns the lights off using the first 26 lines of stairlights.py and this line:
colorMe(strip, Color(0, 0, 0), 0, 239)
Now, with a strip of lights on your stairs, you could play all kinds of games!
Add some coloured arcade buttons for a quick reaction game.
Maybe when your phone connects to the Bluetooth on the Pi, your stairs could flash a welcoming hello dance. Experiment and have fun!