1 year ago

Temperature controlled stairlights: Raspberry Pi controlled home lighting system

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!

You’ll need
5V RGB strip
5V mains power supply
Female jack connector plug
Male-to-female jumper wires

STEP-01: Set up the temperature controlled stairlights

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.

>STEP-02: Set up the Pi

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!

STEP-03: Set up the weather API

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:

  1. Go to forecast.io
  2. Select Developer
  3. Select ‘Sign up’ to register an account
  4. Once you confirm your email address, you will get a secret key: you will need this key in Step 4

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.

STEP-04: Let there be light!

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:

At the end of the file, enter:

Save the changes.

STEP-05: Debugging your temperature controlled stairlights

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!

>STEP-06: What next for your temperature controlled stairlights?

We changed the cron tasks to stop the lights displaying through the night:

…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!

This tutorial was written by Lorraine Underwood (@LMcUnderwood). Lorraine runs the Kendal Pi Jam. She is an Irish maker living in Yorkshire with a background in web development.