This attractive illuminated scene can serve as a lamp or a living piece of art for your home.

Environmental Sensing

The NeoPixel strip that illuminates the city scene is controlled by a Circuit Playground Express, and is programmed to react to certain environmental conditions.

Two modes allow the NeoPixel strip to dim or brighten the strip in accordance with ambient light levels, or adjust its color based on the temperature measured by its onboard thermistor. 

Parts

The electronics for this project are simple, a Circuit Playground Express paired with a short strip of NeoPixels can work wonders together. Portable power supplies are also recommended, though not strictly necessary.

Circuit Playground Express is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and...
$24.95
In Stock
Adding glowy color to your projects has never been easier: no more soldering or stripping wires, clip 'em on and glow! This Adafruit NeoPixel LED Strip with Alligator...
$12.50
In Stock
This battery holder connects 3 AAA batteries together in series for powering all kinds of projects. We spec'd these out because the box is slim, and 3 AAA's add up to about...
$1.95
In Stock
Battery power for your portable project! These batteries are good quality at a good price, and work fantastic with any of the kits or projects in the shop that use AAA's. This is a...
$1.50
In Stock

Materials

In addition, for this project you will also need:

In this section we will upload and test the code for this project.

Getting Familiar

The code was created using Microsoft MakeCode for Adafruit, a web-based code editor. MakeCode provides a block editor, similar to Scratch or Code.org, and also a JavaScript editor for more advanced users.

If you'd like to learn more about MakeCode, this guide is a good place to start.

Bootloader Mode

When you connect Circuit Playground Express to your computer for the first time, it will appear as a flash (or thumb) drive named CIRCUITPY.

BUT we'd like to make it work with MakeCode. 

All that's required to do this is to connect the board to your computer with a micro USB cable and click the small reset button in the center of the board. The available thumb drive should eject itself and show up again as CPLAYBOOT. Your code file will be placed on CPLAYBOOT.

Click this link or the button below to interact with and change the code for this project.

How to Upload Code

To upload code, connect you Circuit Playground Express to your computer using the micro USB cable, click the Download button to download the .uf2 file to your computer, and drag 'n drop that .UF2 file onto the CPLAYBOOT drive in your computer's file explorer or finder.

The drive will automatically eject itself (your computer may give you a "failed to eject drive correctly" error, you can ignore this). The code is now on your Circuit Playground Express and ready to run!

How it Works

The code for this project uses MakeCode's Variables and Functions to create two modes, one in which the NeoPixel strip changes its brightness based on readings from its light sensor, and one in which it changes its color based on its temperature reading.

In the forever block we can see the two modes that the NeoPixel strip is capable of displaying.

To detect light we are using the onboard analog light sensor. This can be used to detect ambient light, with similar spectral response to the human eye. This sensor will read between 0 and 1023 with higher values corresponding to higher light levels (a reading of about 300 is common for most indoor light levels).

 

Temperature is measured using an NTC thermistor in the top right part of the board. While it isn't an all-in-one temperature sensor, it's easy to calculate the temperature based on the analog voltage output. 

These two pink blocks determine how we change from one mode to the other.

The color change function is calculated for a minimum of 60 degrees and maximum of 85 degrees, for a 25 degree swing. This means that at 60 degrees the NeoPixel strip will be full blue, at 85 degrees, full red. We'll show you how to change the range and temperature scale in a following page.

The silhouettes of New York City and Seattle were chosen as skylines for this project, though you can choose any city that you like. 

A quick Google search for the city name of interest + skyline will turn up a wealth of results.

Another search for clouds + stencil leads to many options for background clouds that make a beautiful backdrop for the city.

If you're lucky enough to have access to a laser cutter, you can cut out your skyline that way.

Alternately, you can print or trace your skyline on heavy construction paper and cut it out using scissors and/or a hobby knife.

The Circuit

The circuit for this project is wonderfully simple to build, thanks to the alligator clips already attached to the NeoPixel strip.

 Connect the Black clip to GND, White to A1, and Red to Vout.

Connect Electronics

 

Tape NeoPixel strip, Circuit Playground Express, and battery pack to a long rectangle of cardboard. 

Hot Glue!

 

Glue clouds onto cardboard base.

 

This will serve as a backdrop for the city, reflecting light from the NeoPixel strip.

Once your clouds and skyline have been glued in place, you should be ready to turn on power to the Circuit Playground Express and experience your illuminated city for the first time!

You can test that it responds to ambient light conditions by moving your hand over the light sensor on the Circuit Playground Express board and watching the NeoPixel strip dim as your shadow passes over (when slide switch is in the Left position).

MakeCode is Adaptable

If you want to adapt your skyline to fulfill different purposes, you can readily implement changes through MakeCode. See below for a few examples of changes and alternatives you can try.

Shifting Temperature Window

Depending on location, you may want to adjust the temperature settings if you think the temperature will fall outside of the programmed 60-85 degree window.

Changing the value in the minimum_temp bubble in Function Color from 60 to something like 40 will widen the window to accommodate a colder environment, though this will also result in subtler changes in color for every degree of temperature change. You can change the minimum & maximum temperatures registered here as well as degrees Celsius or Fahrenheit. 

NeoPixel Animation

If you'd like to change or add to the NeoPixel strip, you will find the NEOPIXEL section becomes available after you click on the LIGHT section. Here you may find many fun options for animating the NeoPixel strip. 

To reveal the NEOPIXEL section in MakeCode, first click on LIGHT

Non-Interactive Alternative

If you prefer something less-interactive, you can replace the complicated interactive code with a simpler version that just cycles through night and day. Click this link or the button below to open this code in a new window.

Drag and drop the .UF2 file from this example code onto your CPX to test it out.

This code will tell your NeoPixel strip cycle through daytime (yellow) and nighttime (blue). You can alter the speed at which these changes occur by changing the value in the set cycle_time to block.

Exploring Further

If you enjoy MakeCode and want to continue exploring you can check out lots more MakeCode projects on the Adafruit Learn System.

This guide was first published on Jan 04, 2019. It was last updated on Jan 04, 2019.