Introduction: Smart LED Window
A fake window, powered by LED strip lights, controlled by a Raspberry Pi
Like most basements, mine was dark with only a couple tiny windows letting in almost no light. In order to brighten it up and make it feel a little less claustrophobic, I created a fake window to let in some natural-looking light.
The window is controllable via web interface. The LED strip brightness can be manually, or automatically set according to sunset/sunrise times and the weather pulled from the Yahoo! API. If it's sunny, the window is bright, if it's cloudy, the window is more dim. It fades on at sunrise, and fades off at sunset.
Materials Needed
- 2 - 8ft trim boards for frame
- 2 - 8ft 1x4 boards for sides and sill for frame
- 2 - 8ft 1x3 boards for sides for frame
- Old sheet, or canvas (to cover the back of the frame)
- Tin foil (to cover the canvas)
- Spray glue
- Short nails, or staples for staple gun
- 1.5in screws
- Window shade
- 2 - 16ft LED strip lights, daylight white (Amazon)
- 12 volt power supply for lights (Amazon)
- Extra wire (2-3 ft.)
- 2 jumper wires (male to female) for Raspberry Pi GPIO
- Raspberry Pi (vers. 2 or newer)
- MOSFET for controlling LEDs (Arrow)
Tools Needed
- Saw (handsaw or table saw)
- Screwdriver or drill
- Staple gun
- Soldering Iron
Step 1: Build the Window Frame
Determine the exact dimensions needed for the window. My window shade dimensions were 31x44 inches, so that was my starting point. I used the 1x4 board on the two long sides, overlapping the shade by 2 inches. This will allow the shade to move up and down while keeping it approx. 1 inch away from the LEDs to provides better diffusion of the light. If the shade is too close to the LEDs, you'll be able to see the LEDs through the shade.
Measure and cut the 1x2 board, and the trim board to match the length of the 1x4 boards. Then affix these boards to line up with the outside of the 1x4 board.
Now we'll need to measure and cut the 1x3 boards for the top and bottom of the frame. The top should be same width as the frame, and the bottom (window sill) should be about one inch longer on either side. Attach these with screws.
Last, measure and cut a trim piece which will go under the sill. This is typically the same width as the window (not the sill).
Step 2: Attach the Canvas Backing and Tin Foil
With the frame created take the canvas (or sheet) and use a staple gun to staple and cover the BACK of the frame. Stretch it relatively tight before stapling. Put a staple every 3 or 4 inches. When complete, cut off any excess material.
Now, using the spray glue, spray the canvas from the FRONT side and then cover with tin foil. Make sure the shiny side is pointing out. Cut off any excess tinfoil when done. This will help more of the light from the LEDs to be reflected out, and create a nice even diffusion of the light.
Step 3: Attach and Wire the LED Strip Lights, Raspberry Pi and MOSFET
Make sure the power is UNPLUGGED while wiring everything up! We don't want to short out the power supply, or kill the Raspberry Pi while setting everything up.ds
We need to attach the LED strip lights to the canvas/tinfoil backing. For the size window I was creating, rows of about 3-4 inches apart worked perfect. Start in the upper right, and work your way down, peeling the adhesive backing off the strips as you go. Once the first strip is attached, begin attaching the second strip where the first strip left off. DON'T connect the strips to each other. The second strip will be VERY dim by the end if you do this. We'll want to wire them up in parallel instead.
Each strip should come with a plastic connector wired to a female plug. Cut off the female plug, and strip and expose the black and red wires. Connect the plastic connector end to the strip lights. Then connect the wires as shown in the diagram.
Using the MOSFET wired to the Raspberry Pi, we can control the lights. See the wiring diagram above. I used GPIO 21, and the ground pin right next to it for this. Any GPIO and ground will work. I got the MOSFET from Arrow, about $0.50 (link).
To power the Raspberry Pi, I used a 12v to 5v DC Buck Converter (Amazon). This is not required, any Raspberry Pi power supply can be used. But using the Buck converter, I can power the whole setup from the single LED Strip power supply.
Step 4: Install and Configure Software on the Raspberry Pi
I'm assuming the Raspberry Pi is at least version 2 or newer, with the latest Raspbian/Pixel OS installed, and Wifi already configured. Open a terminal, or SSH in for the following steps.
Install the web server
I used Lighttpd for the web server, and a combination of Python and PHP for functionality.
sudo apt-get install lighttpd php5 php5-common php5-cgi
Next, set some privileges on the web directories:
sudo chown -R www-data:www-data /var/www
sudo chmod -R 775 /var/www
sudo usermod -a -G www-data pi
Now enable PHP
sudo lighty-enable-mod fastcgi-php
And restart the server
sudo /etc/init.d/lighttpd force-reload
Grab the code from Github
I've published all the code for the web interface, and auto-brightness script on Github. Download the files. Place the html directory in /var/www/, and put window.py in /home/pi/
Add some cron jobs
We need the pigpiod program to start on boot, and also we want our "auto-brightness" script to run every 10 minutes. Lets add these to the root cron:
sudo crontab -e
And then add the following:
# Auto adjust the window brightness
*/10 * * * * /home/pi/window.py
# Start Pi GPIO Daemon on reboot
@reboot /usr/bin/pigpiod
Reboot and Test
Reboot the Pi. When it comes back up the web interface should be accessible on your computer or smartphone by going to http://IP_ADDR in a browser.
Step 5: Enjoy
Enjoy your window, and the extra light!

First Prize in the
IoT Builders Contest

Runner Up in the
Circuits Contest 2016

First Prize in the
Dorm Hacks Contest 2016
80 Comments
1 year ago
I want to control a pre-built led ceiling panel which runs on a 25-42v driver. Is it possible to use a mosfet as you have? Or would I need to buy a PWM dimmable driver? If so, how would that work?
Question 3 years ago
I'm keen to try this but note that it uses Darksky in the code rather than the Yahoo! API suggested in the article. With Darksky now unavailable (thanks Apple...) is there an original code to Yahoo! API or an update that I'm missing? Thanks1
Answer 3 years ago
I also have been wanting to complete this project. I'm not really all that versed in coding, but it seems the Yahoo! API has since changed since the original implementation (the source Yahoo! code is still available on GitHub as a previous version). As a result I tried to get the OpenWeather API to work with it since they have a guide to go from DarkSky to OpenWeather, but I'm not having any luck. I tried contacting the author as well to see if any future update might be possible, but I've not heard back.
If there's any kind of reward to offer to help get this project switched to a different API, I would be game to contribute...!
Reply 2 years ago
Create account and grab API key from https://home.openweathermap.org/api_keys
Below is the segment of code I modified to make it work.
Updated url, settings config, and cloudy/sunny/mixed logic to use openweather data.
url = "https://api.openweathermap.org/data/2.5/onecall?lat=" + str(lat) + "&lon=" + str(lon)
url = url + "&exclude=minutely,hourly,daily&appid=" + api_key
# Refresh weather data every 15 minutes
if (settings['timestamp'] + 900) < time.time():
try:
if debug:
print('Getting openweathermap.orgweather data...')
data = requests.get(url, timeout=10).json()
# Save/cache values -- Updated to use API source names
settings['auto'] = 1
settings['clouds'] = data['current']['clouds']
settings['sunrise'] = data['current']['sunrise']
settings['sunset'] = data['current']['sunset']
settings['timestamp'] = round(time.time())
f = open(confFile, 'w')
f.write(json.dumps(settings))
f.close()
except:
print("Error: Unable to connect to openweathermap.org API")
# Set max brightness based on weather // changing percentages to reflect diff api source
if settings['clouds'] > 80:
maxBright = cloudy
elif settings['clouds'] < 30:
maxBright = sunny
else:
maxBright = mixed
3 years ago
Hey i would like to make something like this for photography purposes, did you meybly measured and chcecked how much light does it provide? what kind of matelial you used to diffuse light so "pointy" LEDS light would dissapear?
Tip 4 years ago
here is working link for the arrow mosfet used https://www.arrow.com/en/products/irlb8721pbf/infineon-technologies-ag
Reply 4 years ago
Thank you! I wanted to check before buying, is this the same as well? https://www.digikey.com/product-detail/en/IRLB8721PBF/IRLB8721PBF-ND/2127670/?itemSeq=300904241 (The shipping is about half the cost)
Reply 4 years ago
i believe so... i was using the manufacture number in the url of the original (but now broken) link to arrow.com. that url contains irlb8721pbf, which matches the product you linked to as well :)
Reply 4 years ago
Thanks. Yeah, I got it and it works just fine when I run the current through it without the PI connected. Now I'm just trying to get the PI to send the signal to the MOSFET to turn the lights on...
Reply 3 years ago
i'm having the same issue. did you find a solution? and what pin are you using?
Question 4 years ago
So instead of PHP5 I used "sudo apt-get install lighttpd php php-common php-cgi" since PHP5 was no longer available. However, when I try to use the slider or the "Auto" brightness it does not adjust the light from being off. Is there something I need to change in my setup to get this to work?
Answer 4 years ago
Just needed to install pigpio, all set!
sudo apt-get install pigpio python-pigpio python3-pigpio
4 years ago
I am trying to build this unit. The code is not available and the ph5 is out of date. Any way that you could update this information.
5 years ago
I live in an RV and we have to cover the windows with insulation to prevent heat from getting in since we are in Florida. I found this idea and it was exactly what I was trying to figure out how to do myself. I'm going to have the insulation up on the window, blocking out all the light, and build this for our window behind the couch to mimic the daylight. Hopefully it'll make it feel less like a cave in here during the day. If it works on that window, I'll probably do it on another one as well to make it more ambient in here.
6 years ago
Does this meet egress Code requirements? Just kidding, being a retired building inspector. I love the idea... and birds won't be flying into it. You should manufacture and sell them.
Reply 5 years ago
10/10 would buy two right away!
6 years ago
Really like this project. I always wanted to do one like this.
Recently have bought some strips with new kind of "addressable" leds SK6812, very similar to WS2812 that is RGB but also available with "W-WW-A" combination (read White-WarmWhite-Amber) that can mimic a wide spectrum of natural light.
You don't really need to "address" every single led, but the advantage is that the control line for white shade and luminosity is just one, so that the versatile ESP8266 can master the whole thing easily.
(unfortunately these strips work at 5V, so you need more amps to achieve the some luminosity)
Also there are sketches for ESP8266 that use its embedded Access Point feature and expose a simple html page with various controls.
6 years ago
I have everything hooked up and it works except the lights are much dimmer than they should be. They are not wired in series (I have them hooked up via headers and when I unhook one set the brightness does not change of the other set).
Could it be my MOSFET? I used this one: http://www.microcenter.com/product/421874/Mosfet_To-220abirfz44n
All of the other parts are the exact same as what you used.
Reply 6 years ago
Hmm, it could be the MOSFET. You want a "logic level" mosfet that can be driven by the 3.3v coming out of the Pi's GPIO. Some of the MOSFETs are 5v, meaning the Pi would only be able to partially open the gate leading to a dim LED. I don't see any specs on that site that say anything about voltage requirements.
Reply 6 years ago
I went ahead and ordered the same MOSFET that you used so hopefully that's it. I soldered the parts to an Adafruit Perma-Proto HAT and right now the LED strips are only getting 7.2 volts but if I put the multimeter leads between the hot where the LED strips connect and the standard ground it's the full 12 volts. I'll report back on the result.