# MicroPython Smart Holiday Lights

## Overview

Danger: 

![](https://cdn-learn.adafruit.com/assets/assets/000/037/933/medium800/micropython_IMG_5682.jpg?1481275192)

Celebrate the holidays with MicroPython and smart holiday lights that are controlled from the web! &nbsp;This project shows you how to animate NeoPixels with MicroPython running on the ESP8266 WiFi microcontroller. &nbsp;Just pick the color and type of animation on a web page, click a button, and your holiday lights will spring to life with animated holiday cheer. &nbsp;The smart holiday lights will even remember their last animation&nbsp;run it on power up. &nbsp;This project is a great demonstration of&nbsp;the ESP8266 and MicroPython's strengths like easy WiFi access with the WebREPL and storing data in MicroPython's file system.

To follow this guide you'll want to be familiar with MicroPython&nbsp;by reading these&nbsp;guides:

- [MicroPython Basics: What is MicroPython?](../../../../micropython-basics-what-is-micropython)
- [MicroPython Basics: How to Load MicroPython on a Board](../../../../micropython-basics-how-to-load-micropython-on-a-board)
- [MicroPython Basics: Load Files & Run Code](../../../../micropython-basics-load-files-and-run-code)
- [MicroPython Basics: ESP8266 WebREPL](../../../../micropython-basics-esp8266-webrepl/overview)

See [all the MicroPython guides in the learning system](../../../../category/micropython) for more information.

In addition you'll want to read the [NeoPixel Uberguide](../../../../adafruit-neopixel-uberguide/overview) to understand the different types of pixels and considerations like how to power them.

# MicroPython Smart Holiday Lights

## Hardware

Danger: 

# Parts

You'll need the following hardware for this guide:

- **ESP8266 running MicroPython.** &nbsp;The [Feather HUZZAH ESP8266](https://www.adafruit.com/product/2821) is perfect if you don't have a board yet, but any ESP8266 board should work. &nbsp;See the [loading MicroPython on a board guide](../../../../micropython-basics-how-to-load-micropython-on-a-board/esp8266) for details on how to get MicroPython running on the board.
- **NeoPixels.** &nbsp;You can use any type of[&nbsp;NeoPixels like strips, matrices, and more](https://www.adafruit.com/category/168). &nbsp;However **be sure you use RGB and not RGBW pixels** as the code for this project assumes only RGB pixels. &nbsp;Three to four meters of a&nbsp;strip like the [30 pixels/meter NeoPixels](https://www.adafruit.com/products/1460) are perfect for wrapping around a small wreath or tiny tree. &nbsp;Check out the [NeoPixel Uberguide](../../../../adafruit-neopixel-uberguide/overview) for more information on the different types of NeoPixels&nbsp;and how to power them.
- **5V power supply.** &nbsp;You'll need a 5 volt power supply with enough current to drive all the pixels. &nbsp;Each NeoPixel can pull up to 60mA of current so be sure to get a large enough supply to support all your pixels! &nbsp;This [5V 10amp supply](https://www.adafruit.com/product/658) will handle up to about 150 NeoPixels at full brightness (grab a [barrel jack to terminal block adapter](https://www.adafruit.com/products/368)&nbsp;to make connecting the supply easy). &nbsp;Check out the [NeoPixel Uberguide](../../../../adafruit-neopixel-uberguide/overview) for more power supply options.
- **Large capacitor to protect pixels.** &nbsp;As the [NeoPixel Uberguide mentions](../../../../adafruit-neopixel-uberguide/power) you might want to add a large capacitor to the power connections to prevent damaging the pixels with a sudden rush of power. &nbsp;The [4700uF 10V electrolytic capacitor here](https://www.adafruit.com/product/1589) should work great.
- **Soldering tools.** &nbsp;You might need to solder some of the NeoPixel and other connections so be sure to have a [soldering iron, solder, and wire](https://www.adafruit.com/products/136) handy. &nbsp;If you're new to soldering check out the [guide to excellent soldering too](../../../../adafruit-guide-excellent-soldering/tools).

# Wiring

Connect your hardware as shown below:

![](https://cdn-learn.adafruit.com/assets/assets/000/037/931/medium800/micropython-smart-holiday-lights_bb.png?1481262392)

- **Power supply ground/-** to **NeoPixel GND/ground** and **Feather HUZZAH ESP8266 GND/ground.**
- **Power supply 5V/+** to **NeoPixel +5V** and **Feather HUZZAH ESP8266 USB** pin. &nbsp;For other ESP8266 boards check its specs to see which pin can support a 5V power input that runs the board.
- **Feather HUZZAH ESP8266 pin 15** to **NeoPixel Din/input**. &nbsp;You can use most other GPIO pins on the ESP8266 (except pin 16) but this guide will assume you're using pin 15.
- If you're using a capacitor to protect the pixels (highly recommended!) connect it as follows:

  - **Capacitor cathode** (the pin on the **side with the stripe** ) to **power supply ground/-**.
  - **Capacitor anode** to **power supply 5V/+**.

If you're using a&nbsp;barrel jack to terminal block adapter it's easiest to connect the capacitor directly to the terminals like below (be sure the side with the stripe is connected to the negative/ground terminal!):

![](https://cdn-learn.adafruit.com/assets/assets/000/037/934/medium800/micropython_IMG_5685.jpg?1481275216)

# MicroPython Smart Holiday Lights

## Software

Danger: 

# Setup MicroPython & WebREPL

First make sure you are running the latest version of ESP8266 MicroPython for your board. &nbsp;Check out the [how to load MicroPython on a board guide](../../../../micropython-basics-how-to-load-micropython-on-a-board/esp8266) for more information on&nbsp;loading MicroPython onto the ESP8266 board.

Note that at the time of this guide's writing the current version of ESP8266 MicroPython is **1.8.6**. &nbsp;Later versions might change the WebREPL so if you run into unexpected issues try going back to the 1.8.6 version.

Next [setup the WebREPL on the ESP8266 board by following this guide](../../../../micropython-basics-esp8266-webrepl/overview). &nbsp;Be aware the latest 1.8.6 version of MicroPython slightly changed how the WebREPL is setup so [follow the guide](../../../../micropython-basics-esp8266-webrepl/overview) or the [official instructions to enable the WebREPL](https://docs.micropython.org/en/latest/esp8266/esp8266/quickref.html#webrepl-web-browser-interactive-prompt). &nbsp;Don't continue until you have your ESP8266 running MicroPython and can connect to its WebREPL!

# Load&nbsp;MicroPython Code

After the WebREPL is enabled you'll need to download the MicroPython and webpage code for this project from its [home on GitHub](https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/master/ESP8266_MicroPython_Holiday_Lights) by clicking the button below:

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/ESP8266_MicroPython_Holiday_Lights/lights.py

Open the archive and find the following files:

- **lights.py** - This is the MicroPython code that will power the project.
- **lights.html** - This is the webpage you'll use to control the lights and animation.

Open **lights.py** in a text editor and notice the configuration values at the top:

```
# Static configuration that never changes:
PIXEL_PIN   = machine.Pin(15, machine.Pin.OUT)  # Pin connected to the NeoPixels.
PIXEL_COUNT = 32                                # Number of NeoPixels.
CONFIG_FILE = 'config.json'                     # Name of animation config file.
```

Change the **PIXEL\_COUNT** value to be the number of NeoPixels in your light strand/project.

If you're using a different pin other than GPIO15 to connect to the NeoPixels be sure to change it in the **PIXEL\_PIN** value.

The rest of the file can stay the same and doesn't need to be changed. &nbsp;Save the file and **rename it to main.py** so that it will run on boot of the board. &nbsp;Copy the file to the MicroPython board using either the WebREPL or a [tool like ampy](../../../../micropython-basics-load-files-and-run-code).

# Control Lights

Now for some&nbsp;fun, you're ready to control the lights from a web page! &nbsp;Open the **lights.html** page in your web browser (note that the page has been tested with the latest Chrome browser, but it should work with other modern web browsers like Safari and IE 8+). &nbsp;

You should see the page load and look like:

![](https://cdn-learn.adafruit.com/assets/assets/000/037/932/medium800/micropython_Screen_Shot_2016-12-09_at_12.20.23_AM.png?1481271650)

Make sure your computer is connected to the ESP8266 board's WiFi network just like when you're using&nbsp;the WebREPL (however be sure you aren't also connected to the WebREPL in another tab or browser!). &nbsp;

Set the board URL to the URL you use to access the WebREPL (if you aren't sure then leave the default value, it's what most WebREPL connections use). &nbsp;

In the password field enter the password you set when setting up and accessing the WebREPL.

You can control the animation of the lights with the fields on the page:

- **Animation** - This drop-down controls if the lights will animate in a solid pulse, chase, smooth fade, or blank animation (no animation).
- **Animation Period** - This value controls&nbsp;the speed of the animation (in milliseconds), or how long the animation stays on any specific color. &nbsp;Small values will speed up the animation and large values will slow it down.
- **Colors** - This drop-down controls the range of colors that the lights will display. &nbsp;You can pick a blue/red, green/red, or blue/white color set. &nbsp;Look at the index.html code and How it Works video 3 below to see how to add more colors!
- **Mirror Colors** - This checkbox controls if the selected colors should ramp up and down smoothly. &nbsp;The colors by default just ramp up, like from blue up to red, but by keeping mirror colors checked you'll see they ramp up and down, like from blue up to red and back down to blue again. &nbsp;Try turning mirroring on and off to see how it changes the animation.

Once you've picked your desired options click the **Update Lights** button. &nbsp;After a moment you should see the lights spring to life with the selected animation!

If the lights don't update be sure you can connect to the board using the WebREPL (you might need to press Ctrl-C once connected to stop the main.py loop and get to the Python prompt). &nbsp;Be sure to use the exact same board URL and password with lights.html as you do when accessing the WebREPL. &nbsp;Also try pressing the reset button on the board to do a hard reset and ensure the MicroPython code & WebREPL are running again.

Try changing the animation values and pressing update lights again to see the lights change. &nbsp;The code for this project will actually remember the last animation it was given so you can even unplug the board, plug it back in, and see the lights jump back to their last animation.

That's all there is to using the ESP8266 MicroPython smart holiday lights! &nbsp;Happy holidays!

# How It Works

If you're curious how the web page controls the lights watch the following videos which&nbsp;explore in depth how the project was created and works:

https://www.youtube.com/watch?v=5Kb6FKwqyBo

https://www.youtube.com/watch?v=9M37qUWR2ZI

https://www.youtube.com/watch?v=EfguZ8mLCgk


## Featured Products

### Adafruit Feather HUZZAH with ESP8266 - Loose Headers

[Adafruit Feather HUZZAH with ESP8266 - Loose Headers](https://www.adafruit.com/product/2821)
Feather is the new development board from Adafruit, and like its namesake, it is thin, light, and lets you fly! We designed Feather to be a new standard for portable microcontroller cores.

This is the&nbsp; **Adafruit Feather HUZZAH ESP8266** &nbsp;- our take on an...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2821)
[Related Guides to the Product](https://learn.adafruit.com/products/2821/guides)
### Adafruit HUZZAH ESP8266 Breakout

[Adafruit HUZZAH ESP8266 Breakout](https://www.adafruit.com/product/2471)
Add Internet to your next project with an adorable, bite-sized WiFi microcontroller, at a price you like! The ESP8266 processor from Espressif is an 80 MHz microcontroller with a full WiFi front-end (both as client and access point) and TCP/IP stack with DNS support as well. While this chip...

In Stock
[Buy Now](https://www.adafruit.com/product/2471)
[Related Guides to the Product](https://learn.adafruit.com/products/2471/guides)
### 5V 10A switching power supply

[5V 10A switching power supply](https://www.adafruit.com/product/658)
This is a beefy switching supply, for when you need a lot of power! It can supply 5V DC up to 10 Amps, running from 110V or 220V power (the plug it comes with is for US/Canada/Japan but you can use any plug adapter for your country, or just replace the cable with a standard computer/appliance...

Out of Stock
[Buy Now](https://www.adafruit.com/product/658)
[Related Guides to the Product](https://learn.adafruit.com/products/658/guides)
### Female DC Power adapter - 2.1mm jack to screw terminal block

[Female DC Power adapter - 2.1mm jack to screw terminal block](https://www.adafruit.com/product/368)
If you need to connect a DC power wall wart to a board that doesn't have a DC jack - this adapter will come in very handy! There is a 2.1mm DC jack on one end, and a screw terminal block on the other. The terminals are labeled with positive/negative assuming a positive-tip configuration...

In Stock
[Buy Now](https://www.adafruit.com/product/368)
[Related Guides to the Product](https://learn.adafruit.com/products/368/guides)
### 4700uF 10v Electrolytic Capacitor

[4700uF 10v Electrolytic Capacitor](https://www.adafruit.com/product/1589)
This Big Freaking Capacitor is just the trick when you have a lot of current sloshing around your project. They'll help smooth out voltage spikes by providing a little buffering. We use these to help stabilize solar panels on our [solar Lipoly...](http://www.adafruit.com/products/390)

In Stock
[Buy Now](https://www.adafruit.com/product/1589)
[Related Guides to the Product](https://learn.adafruit.com/products/1589/guides)
### Adafruit NeoPixel Digital RGB LED Strip - White 30 LED

[Adafruit NeoPixel Digital RGB LED Strip - White 30 LED](https://www.adafruit.com/product/1376)
You thought it couldn't get better than [our world-famous 32-LED-per-meter Digital LED strip](http://adafruit.com/products/306) but we will prove you wrong! These NeoPixel strips have 30 digitally-addressable pixel LEDs per meter and are very affordable and are only 12.5 mm...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1376)
[Related Guides to the Product](https://learn.adafruit.com/products/1376/guides)
### Adafruit NeoPixel Digital RGB LED Strip - Black 30 LED 5m

[Adafruit NeoPixel Digital RGB LED Strip - Black 30 LED 5m](https://www.adafruit.com/product/1460)
You thought it couldn't get better than [our world-famous 32-LED-per-meter Digital LED strip](http://adafruit.com/products/306) but we will prove you wrong! These NeoPixel strips have 30 digitally-addressable pixel LEDs per meter and are very affordable and are only 12.5 mm...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1460)
[Related Guides to the Product](https://learn.adafruit.com/products/1460/guides)
### Adafruit NeoPixel Digital RGB LED Strip - White 60 LED

[Adafruit NeoPixel Digital RGB LED Strip - White 60 LED](https://www.adafruit.com/product/1138)
You thought it couldn't get better than [our world-famous 32-LED-per-meter Digital LED strip](http://adafruit.com/products/306) but we will prove you wrong! You wanted **twice the LEDs**? We got it (well, its 1.875 times as many but that's within a margin of...

In Stock
[Buy Now](https://www.adafruit.com/product/1138)
[Related Guides to the Product](https://learn.adafruit.com/products/1138/guides)

## Related Guides

- [Adafruit Feather HUZZAH ESP8266](https://learn.adafruit.com/adafruit-feather-huzzah-esp8266.md)
- [Adafruit IO Home: Lights and Temperature ](https://learn.adafruit.com/adafruit-io-house-lights-and-temperature.md)
- [MQTT, Adafruit IO & You!](https://learn.adafruit.com/mqtt-adafruit-io-and-you.md)
- [1,500 NeoPixel LED Curtain with Raspberry Pi and Fadecandy](https://learn.adafruit.com/1500-neopixel-led-curtain-with-raspberry-pi-fadecandy.md)
- [CheerLights](https://learn.adafruit.com/cheerlights.md)
- [Adding a WiFi Co-Processor to CircuitPython](https://learn.adafruit.com/adding-a-wifi-co-processor-to-circuitpython-esp8266-esp32.md)
- [Build an ESP8266 Mobile Robot](https://learn.adafruit.com/build-an-esp8266-mobile-robot.md)
- [Building CircuitPython](https://learn.adafruit.com/building-circuitpython.md)
- [Weather Wise Wifi Umbrella Stand](https://learn.adafruit.com/weather-wise-wifi-umbrella-stand.md)
- [CircuitPython LED Animations](https://learn.adafruit.com/circuitpython-led-animations.md)
- [CircuitPython Hardware: LED Backpacks & FeatherWings](https://learn.adafruit.com/micropython-hardware-led-backpacks-and-featherwings.md)
- [MicroPython Basics: Blink a LED](https://learn.adafruit.com/micropython-basics-blink-a-led.md)
- [Crickit Powered Maker Ice Cream Truck!](https://learn.adafruit.com/crickit-maker-ice-cream-truck.md)
- [MicroPython Basics: ESP8266 WebREPL](https://learn.adafruit.com/micropython-basics-esp8266-webrepl.md)
- [Adafruit NeoPixel Überguide](https://learn.adafruit.com/adafruit-neopixel-uberguide.md)
- [Microsoft Azure Cost Monitor](https://learn.adafruit.com/azure-cost-monitor.md)
