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.
|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|
- 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
- A power source for the lights. I used this massive thing: (another affiliated link)
- 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.
- Using a screwdriver connect the terminal blocks to the two wires on the neopixels
- On the other side of the terminal blocks attach the male end of the male to female jumper wires
- Attach the ground wire to ground on the raspberry pi
- Attach the data wire to pin 18 on the raspberry pi
- Plug the power source to the neopixels
First I got the neopixels connected to the pi zero and got them working. Then I got the local outside weather from an API.
- 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
- 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)
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.
— Lorraine Underwood (@LMcUnderwood) February 5, 2017
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!
I changed the lights to a strip of 240 neopixels: http://amzn.eu/eUsgDF9
— Lorraine Underwood (@LMcUnderwood) February 16, 2017