Make: Neopixel temperature stair lights

Idea

Over Christmas we had some lights hooked around the banisters running up our stairs. They were gold lights in a tube that looped quite easily through the wooden banisters. My husband really liked them and wanted to keep them on the stairs.

The Christmas lights were baulked. They didn’t always turn on and entire sections would be in darkness. Instead of buying new ones we thought about adapting a strip of Neopixel lights we had lying around. Then we thought about controlling the lights and came up with a temperature sensor.

The strip has 50 lights. When it’s less than 0 then first 8 lights come on in dark blue. Then the following:

Basically the lights will always be dark blue then the warmer it is the more lights will be on.

Temperature Lights Colour
 0 – 4  9 – 16 Light blue
 5 – 9 17 – 24 Dark green
 10 – 14 25 – 32 Light green
 15 – 19 33 – 40 Yellow
 19 – 24  41 – 48 Orange
 25+  48 – 50 Red

Equipment

  • Strip of 50 neopixels

I found out about these neopixels from Andrew Oakley and his Christmas grid: http://www.aoakley.com/articles/2015-11-18-raspberry-pi-christmas-led-matrix.php

This is the link to them on Amazon which is affiliated to Andrew’s Costwold Raspberry Jam

http://www.amazon.co.uk/gp/product/B00MXW054Y/ref=as_li_tl?ie=UTF8&camp=1634&creative=6738&creativeASIN=B00MXW054Y&linkCode=as2&tag=aoakley-21

  • A power source for the lights. I used this massive thing: (another affiliated link)

http://www.amazon.co.uk/gp/product/B00YPHPEKK/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&camp=1634&creative=6738&creativeASIN=B00YPHPEKK&linkCode=as2&tag=aoakley-21

  • 2 x terminal blocks
  • 2 x male to female jumper cables
  • A raspberry pi zero with SD card with Raspian installed
  • Power for the pi zero (temporary)

You could do a different setup with a cheaper power source but I like this setup as there’s no breadboard or soldering involved. Everything just connects together and works.

Build Instructions

  1. Using a screwdriver connect the terminal blocks to the two wires on the neopixels
  2. On the other side of the terminal blocks attach the male end of the male to female jumper wires
  3. 20170205_151705

    Terminal blocks connecting the neopixels to jumper wires

  4. Attach the ground wire to ground on the raspberry pi
  5. Attach the data wire to pin 18 on the raspberry pi
  6. Plug the power source to the neopixels

Code Instructions

First I got the neopixels connected to the pi zero and got them working. Then I got the local outside weather from an API.

  1. To get the neopixels working I used Les Pounders code from issue 219 of Linux Format. I removed the code that creates a visual slide for the neopixels
  2. To get the weather API connected I used Dougie Maitland’s answer in the Raspberry Pi forum (the second answer using forecast.io) https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=105953

Putting it altogether this is the code that runs on the raspberry pi:

#!/usr/bin/python3
from urllib.request import urlopen
import json
import time
from neopixel import *

apikey="get_your_own_key" # get a key from https://developer.forecast.io/register
# Latitude & longitude - current values are Lancaster University
lati="54.005546"
longi="-2.784876"

LED_COUNT = 50 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 5 # DMA channel to use for generating signal (try 5)
LED_BRIGHTNESS = 8 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)

def color(strip, color, start, end): 
 for i in range(start, end+1):
 strip.setPixelColor(i, color)
 strip.show() 
 
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS)
strip.begin()

count = 0
try:
 while True: 
 #get the data from the api website
 url="https://api.forecast.io/forecast/"+apikey+"/"+lati+","+longi+"?units=si"
 meteo=urlopen(url).read()
 meteo = meteo.decode('utf-8')
 weather = json.loads(meteo)

 currentTemp = weather['currently']['temperature']

 #negative number will always be on 
 color(strip, Color(0, 0, 255), 0,7) # Blue
 
 #what's the temp?
 if currentTemp > 0:
 color(strip, Color(75, 75, 255), 8, 15) # light Blue
 if currentTemp > 5:
 color(strip, Color(0, 255, 0), 16, 23) # dark Green
 if currentTemp > 10:
 color(strip, Color(75, 255, 75), 24, 31) # light Green
 if currentTemp > 15:
 color(strip, Color(255, 100, 0), 32, 39) # yellow 
 elif currentTemp > 20:
 color(strip, Color(255, 50, 0), 40, 47) #orange 
 elif currentTemp > 25:
 color(strip, Color(255, 0, 0), 48, 50) # Red 
 #check every 5 minutes (change to crontab)
 time.sleep(300)
 
except KeyboardInterrupt:
 print("Exit")
 color(strip, Color(0,0,0), 0, 49)

Working

The idea is that more lights will light up as it gets warmer. The temperature is checked every 5 minutes (I think that’s even too often). Looking forward to walking downstairs to a nice warm yellow light instead of the current blue 🙂

The video below shows all the lights lighting up, which will never happen unless it’s the end of the world and the sun is hurtling towards us. In that case at least we’ll get this pretty light show.

To do

Power the raspberry pi zero off the lights – you can attach the zero to the power cable of the lights (I think)

House it in a specially made case. Little toddler hands like jumper cables. Hubster is working on a 3D case for the zero to sit in

Get my own outside temperature? Stop relying on the API and get the outside temperature from… outside my house!

Update

I changed the lights to a strip of 240 neopixels: http://amzn.eu/eUsgDF9

Advertisements

9 thoughts on “Make: Neopixel temperature stair lights

  1. Andy says:

    This is amazing – If I had stairs I would be tempted to do this hooked up to some sensors so the stairs would play musical notes and flash as the kids stepped up it 😀

    Like

  2. tony says:

    Very pretty. There might be a societal application in this for older people who cannot judge how cold they are getting.

    Different app I know, but I saw a staircase “piano” mentioned by Andy in a shop in Bankok. It just encouraged me to go up and down the stairs quickly…..I should know better.

    Like

  3. Chris says:

    Great project, it inspired me to create my own weather predicting stairs! I used a pi zero, a 120 neo pixel strip and 2 PIR sensors at either end of the stairs. I use the darksky api to get the temperature for for tomorrow at my location as well as the sunrise/sunset time. If it’s dark outside and somebody triggers the PIR sensors the lights will walk up/down the stairs with a colour that represents the temperature for tomorrow before turning off. I also added a ‘party button’ that can be used to turn all the lights on while cycling through all the colours!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s