# StarFlower NeoPixel Strand with MakeCode

## Introduction

https://youtu.be/9AcTg7H0s4Q

Make beautiful 3d printed glowing flowers to string around your room or your back yard.&nbsp; Use the Circuit Playground Express' onboard sensors to make the lights react to their environment:&nbsp; when it gets dark outside the lights come on automatically and shine bright, and when it's light out they will turn themselves quietly off.&nbsp;&nbsp;

This guide will cover modeling the flowers in Fusion360, connecting the light strand to a Circuit Playground Express, and creating animations and reactivity with the MakeCode editor.

There's so much you can do with the Circuit Playground Express. This project is a jumping-off place to creating your own designs and making the lights do whatever you can dream up.

![](https://cdn-learn.adafruit.com/assets/assets/000/050/790/medium800/3d_printing_IMG_2040.jpg?1518124230)

### Part: Circuit Playground Express
quantity: 1
Circuit Playground Express
[Circuit Playground Express](https://www.adafruit.com/product/3333)

### Part: Neopixel Strand
quantity: 1
4" Pitch Neopixel Strand
[Neopixel Strand](https://www.adafruit.com/product/3631)

### Part: 2 pin cable
quantity: 1
JST 2-pin cable
[2 pin cable](https://www.adafruit.com/product/261)

### Part: 3 pin cable
quantity: 1
JST 3-pin cable
[3 pin cable](https://www.adafruit.com/product/1663)

### Part: Screw Terminal
quantity: 1
2.1mm Screw Terminal Adapter
[Screw Terminal](https://www.adafruit.com/product/368)

### Part: Power Supply
quantity: 1
5v 2A power supply
[Power Supply](https://www.adafruit.com/product/276)

### Part: 1N4001 Diode
quantity: 1
1N4001 Diode
[1N4001 Diode](https://www.adafruit.com/product/755)

# Tools Needed

- 3d Printer (or 3d printing service)
- Soldering iron & accessories **OR**
- Wire strippers & alligator clips
- Heat gun
- Tiny screwdriver

# StarFlower NeoPixel Strand with MakeCode

## Wiring Diagram

![](https://cdn-learn.adafruit.com/assets/assets/000/050/795/medium800/3d_printing_adafruit_products_flower_diagram.jpg?1518137828)

The great thing about these NeoPixel strands is that most of the wiring is already done for you; we just need to make some connections at the ends.

We'll show making an adapter for the microcontroller, then attach the NeoPixels with their included connector. Power connects at the opposite end of the light strand. That’s something frequently overlooked with NeoPixel projects: while color data _must_ travel in a specific direction from “in” to “out,” **power can go either way.** In the diagram above, a 5V power supply is connected at the _end_ of the strand, and we tap off this at the _start_ of the strand to power the microcontroller, where the strand’s data input is also connected.

You can easily chain multiple light strands together with their included connectors.&nbsp; Just remember that if you have more than a few strands chained together, you may need a [beefier power supply.](https://www.adafruit.com/product/658)&nbsp; A modest 2 Amp supply is good for a couple strands, or more, depending on how you set the brightness level.

We've added a diode near the power supply to protect our pixels from too many volts.&nbsp; A lot of inexpensive power supplies aren't super accurate: they're labeled as 5v and they give off 5v-_ish_, and it's sometimes closer to 5.5 or 6.&nbsp;&nbsp;

These neopixel strands can be pretty finicky, and they really don't like more than 5v.&nbsp; Adding a diode between the power supply and the LED strand will compensate by dropping the voltage just enough, so we get around 4.5-5.7 volts.

Alternatively, you can use a [switching power supply](https://www.adafruit.com/product/1448)&nbsp;with a 3 or 4.5 volt option, or one that's rated for 4.5 volts or lower.&nbsp; **Just be sure you don't switch the supply up to 6 or 12 volts,** or you could fry your controller and pixels!

# StarFlower NeoPixel Strand with MakeCode

## 3D Printing

![](https://cdn-learn.adafruit.com/assets/assets/000/050/766/medium800/3d_printing_05_print.jpg?1517935859)

## Organic T-Splines

The&nbsp;shape was 3D modeled in Autodesk Fusion 360. It was created using t-splines, which is a part of the sculpting environment and toolset. The design is free to download and modify.

I've included three different sizes of flower, all of which will clip neatly onto the light strand.&nbsp; Choose your favorite size or print a few of each size to add lovely variety to your light strand.

[Download STL Files](https://cdn-learn.adafruit.com/assets/assets/000/050/760/original/adafruit_flower_lights.zip?1517878112)
[Download on Thingiverse](https://www.thingiverse.com/thing:2783501)
https://youtu.be/oR7VEsn2l0w

## 3D Printing

Because this part features no flat edges, it will require support material to 3D print properly. Most slicing software for 3D printers are capable of producing support material. A raft is also necessary for properly adhering the part to the bed.&nbsp;

Print them face down with the clips up in the air.&nbsp; This makes it easier to remove the supports without accidentally breaking off the clips.

If you don't have acccess to a 3D printer, can you&nbsp;upload the STL file to [3D Hubs](https://3dhubs.com)&nbsp;and have a local hub 3D print and send&nbsp;the parts to you.

This part is solid in design, so to make it hollow you'll want to print with 0% infill.

![](https://cdn-learn.adafruit.com/assets/assets/000/050/761/medium800/3d_printing_simplify3d_setup.jpg?1517935758)

## Slice Settings

Below are some recommened slice settings.

- Glow in the Dark, clear, or white PLA @ 220C extruder / 65C bed
- Bluetape on non-heated beds
- **Support and Raft required**
- **0% Infill**
- 2 shells/perimeters
- 60mm/s printing speed

**Support Settings**

- support type: everywhere
- 60 degree overhangs
- support infill desnity 15%
- horizontal offset from part 0.30mm

**Raft Settings**

- 3 surface layers
- offset from part 3.00mm
- separation distance 0.14mm
- raft infill 50%

## Removing Support Material

A pair of flush diagonal cutters can help remove support material from the part. It can also be removed by hand if it's of high quality. &nbsp;

# StarFlower NeoPixel Strand with MakeCode

## Assembly

NeoPixel color data must travel from the “in” end of the strand to the “out” end. Examine the backs of the pixels&nbsp;_very_&nbsp;closely. Printed on the PCB, you might see either some data direction arrows, or the words “IN” and “OUT” between pads. The weatherproofing epoxy makes things murky and you may need to look at several pixels before finding one.&nbsp;This is important! If you connect the microcontroller to the wrong end, the lights won't work.

![3d_printing_00_findarrow.jpg](https://cdn-learn.adafruit.com/assets/assets/000/050/734/medium640/3d_printing_00_findarrow.jpg?1517935612)

If you have multiple LED strands, plug them into each other to create one long überstrand.

Each strand should have a pair of extra wires with exposed ends, for connecting power. Only **one** of these pairs is required. The rest should have their exposed tips trimmed flush or covered with tape or heat-shrink tubing to prevent electrical shorts.

For 1 to 3 linked strands, let’s use the pair of wires at the **end**. For longer strands, choose a pair near the **middle.**

Find the silver stripe on your diode.

Diodes have a specific&nbsp;_polarity,&nbsp;_passing current in only one direction_…_the silver stripe is the + end.&nbsp;So we want to connect the + side of the screw terminal to the “dark” end with no stripe.

Bend the diode's leg on this side and slip it into the port on the screw terminal.&nbsp; Solder the other leg to the RED wire coming from the LED connector.

(Diode not shown) Connect a female DC power adapter using the screw connectors, being&nbsp; **super extra careful** &nbsp;to&nbsp; **follow the polarity markings** &nbsp;stamped on the DC jack:

- **+** &nbsp;(plus) connects to the strand’s&nbsp; **red** &nbsp;wire
- – (minus) to the opposite wire

You may need to strip away a little extra insulation from the wires to make a good connection with the terminals.&nbsp;Tug a little on each wire to make sure it's firmly in place.

![3d_printing_01_adafruit_products_dcjack.jpg](https://cdn-learn.adafruit.com/assets/assets/000/050/735/medium640/3d_printing_01_adafruit_products_dcjack.jpg?1517935614)

To connect the microcontroller at the “input” end of the strand, I soldered up this little&nbsp; **adapter cable&nbsp;** using a&nbsp; **3-pin JST plug** &nbsp;(to the LEDs) and a&nbsp; **2-pin JST cable** &nbsp;(to the Circuit Playground).

Don’t just follow the picture, take a good look at your actual hardware and be&nbsp; **super extra careful** &nbsp;to get the connections right:

- The&nbsp; **RED** &nbsp;wire from the LED strand should connect to the&nbsp; **RED** &nbsp;wire on the 2-pin JST plug.
- The&nbsp; **OPPOSITE** &nbsp;wire from the LED strand (furthest from the red wire) should connect to the&nbsp; **BLACK** &nbsp;wire on the 2-pin JST plug.
- The&nbsp; **MIDDLE** &nbsp;wire will get soldered to the Circuit Playground's A1 pin.

![3d_printing_02_adapter1.jpg](https://cdn-learn.adafruit.com/assets/assets/000/050/736/medium640/3d_printing_02_adapter1.jpg?1517935617)

![3d_printing_03_adapter2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/050/737/medium640/3d_printing_03_adapter2.jpg?1517935620)

If you don’t have a **3-pin JST plug** , and you’re 100% okay sacrificing the “output” end of your LED strand, you can cut that plug off and use it as an input-end adapter. Do this at the mid-point between the plug and the last pixel, so there’s enough wire to be useful. Was your DC jack connected to the extra power wires there? That’s okay! Remember, the strand can accept power from _either_ end.

If you're doing this project with kids, you can use alligator clips instead of soldering.&nbsp; It won't stay permanently attached, but it's a fun and easy way to get the lights up and running.

Clip the 3d printed flowers gently onto each light. If they don't seem to fit right, turn them 90 degrees -- the spacing between the clips is not exactly even; the wire goes between the wider clip spacing.

![3d_printing_04_clipon.jpg](https://cdn-learn.adafruit.com/assets/assets/000/050/765/medium640/3d_printing_04_clipon.jpg?1517935781)

If they still don't quite want to fit, use a heat gun on the clips for just 5-10 seconds to soften them a little bit, then press the flower onto the light. When the plastic cools it will grab and hold nice and tightly.

![](https://cdn-learn.adafruit.com/assets/assets/000/050/791/medium800/3d_printing_IMG_2025.jpg?1518124273)

# StarFlower NeoPixel Strand with MakeCode

## Programming with MakeCode

The Circuit Playground Express can be programmed a number of ways: it will run Arduino code, CircuitPython, or you can program it with MakeCode.&nbsp;&nbsp;

 **Microsoft MakeCode for Adafruit&nbsp;** is a web-based code editor&nbsp;for physical computing. It provides a block editor, similar to Scratch or Code.org, and also a JavaScript editor for more advanced users.&nbsp;

This means you can drag and drop light animations and functionality using the Circuit Playground Express' onboard sensors without ever writing a single line of code.&nbsp; &nbsp;Just snap the blocks together and watch your lights dance.

[Check out our MakeCode intro guide here.](https://learn.adafruit.com/makecode/what-is-makecode)
For this project, I used the Circuit Playground's onboard light sensor to turn the lights on automatically when the room gets dark.&nbsp; When the room brightens back up, the lights will turn off.

The lights are running MakeCode's built-in rainbow animation.&nbsp; [Check out this guide](../../../../neopixels-with-makecode/overview) for more info on working with neopixel strands and building your own animations.

Go to&nbsp;[https://makecode.adafruit.com/](https://makecode.adafruit.com/)and select "New Project".

### **Set Up the Light Strand**
We soldered our light strand to pin A1.&nbsp; Tell the code by adding an `on start`&nbsp;loop (Loops \> `on start`).&nbsp; This block will run ONCE when the board powers up, so it's the perfect place to define our setup.

Drag the `on start` block above the `forever` block.

![3d_printing_onstart.jpg](https://cdn-learn.adafruit.com/assets/assets/000/050/741/medium640/3d_printing_onstart.jpg?1517935645)

Next go to "Variables" and drag `set (item) to 0`&nbsp;into the `on start` block.&nbsp; &nbsp;

Change `(item)` to `(strip)`.&nbsp;&nbsp;

Go to the "Neopixel" bin (you may need to click the "Light" bin to make it appear).&nbsp; Drag `create strip on (A1) with (24) pixels`&nbsp;into the block you just made, replacing the "`0`" field.

In the "Neopixel" bin, find `strip > show animation () for 500 ms`.&nbsp; Drag this block into the `forever`loop.&nbsp;

![3d_printing_onstartstrip2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/050/745/medium640/3d_printing_onstartstrip2.jpg?1517935665)

# Download Code

Let's test to see if it's working.&nbsp;

1. Plug your Circuit Playground Express into your computer with a USB cable.&nbsp;
2. Click the reset button.&nbsp;
3. Green lights will appear on the Circuit Playground's face&nbsp; and it will appear in your list of devices, called **CPLAYBOOT**.&nbsp;

_If you don't see this, try double-clicking the reset button instead of single-clicking._

Click the pink **Download** button on your MakeCode screen and the code you just made will download to your computer.&nbsp; Drag it onto the **CPLAYBOOT** device.&nbsp;&nbsp;

Plug the light strand into power and you will see a pretty rainbow animation.&nbsp; Hooray!

# Add Ambient Light Sensing

Let's make the lights turn on auto-magically when it gets dark, and off again in bright daylight.&nbsp; We can do this using the Circuit Playground Express' onboard light sensor and a little bit of experimentation.

From the pink **Input** bin, drag four blocks:

- two instances of `on light (dark)`&nbsp;
- two instances of `set (dark) light threshold to 0`

From the **Neopixel** bin, drag two blocks:

- two instances of` (strip) set brightness to (0)`

![3d_printing_Flower_Strand_-_Adafruit_Circuit_Playground_Express.jpg](https://cdn-learn.adafruit.com/assets/assets/000/050/749/medium640/3d_printing_Flower_Strand_-_Adafruit_Circuit_Playground_Express.jpg?1517935691)

We want the lights to come ON when it gets dark in the room, and go OFF when it gets bright.&nbsp;

Place one instance of `(strip) set brightness to (0)`&nbsp;inside each `on light ()` loop.&nbsp; &nbsp;Leave the `(light)` one at 0, and set the&nbsp;`(dark)` one at 150 or so, or whatever you'd like your maximum brightness to be (on a scale of 1-255, 255 being the brightest they can go).&nbsp; &nbsp;

Next, place both the `set (dark) light threshold to 0` blocks inside the `on start` loop.&nbsp; Change `(dark)` to `(light)` on one of them, so one triggers above a certain brightness and the other triggers below a certain darkness.

# Calibrate

Every room or environment is different, so you'll need to experiment a bit to get the thresholds right.&nbsp; I found that `set (bright)` to 21 and `set (dark)` to 32 works well in a window-lit bedroom -- when I turn on my overhead lights, the light strand goes off, and when the overhead lights go off, the light strand comes on.&nbsp;&nbsp;

Download the code and drag it to **CPLAYBOOT** to test and see where your light threshold needs to be.&nbsp; Experiment until it behaves the way you want.&nbsp; A bright flashlight is helpful for experimentation!

Here's the completed project that you can play with directly.

https://makecode.com/_3y6YF3KDLDcX

![](https://cdn-learn.adafruit.com/assets/assets/000/050/792/medium800/3d_printing_IMG_2035.jpg?1518124308)


## Featured Products

### Circuit Playground Express

[Circuit Playground Express](https://www.adafruit.com/product/3333)
 **Circuit Playground Express** is the next step towards a perfect introduction to electronics and programming. We've taken the original Circuit Playground Classic and made it even better! Not only did we pack even more sensors in, we also made it even easier to...

In Stock
[Buy Now](https://www.adafruit.com/product/3333)
[Related Guides to the Product](https://learn.adafruit.com/products/3333/guides)
### Adafruit NeoPixel LED Dots Strand - 20 LED 4" Pitch

[Adafruit NeoPixel LED Dots Strand - 20 LED 4" Pitch](https://www.adafruit.com/product/3631)
Attaching NeoPixel strips to your costume can be a struggle as the flexible PCBs can crack when bent too much. So how to add little dots of color? Use these stranded NeoPixel dots! They're very small, so they're easy to embed into any structure, costume, or wearable. Each dot is...

In Stock
[Buy Now](https://www.adafruit.com/product/3631)
[Related Guides to the Product](https://learn.adafruit.com/products/3631/guides)
### 3-pin JST SM Plug + Receptacle Cable Set

[3-pin JST SM Plug + Receptacle Cable Set](https://www.adafruit.com/product/1663)
These 3-wire cables are 163mm (6.4") long and come as a set. One cable has a JST SM type connector plug on the end. The other cable has a matching JST SM type receptacle connector. They are good for whenever you have 3 wires you want to be able to plug and unplug. We like the solid and...

In Stock
[Buy Now](https://www.adafruit.com/product/1663)
[Related Guides to the Product](https://learn.adafruit.com/products/1663/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)
### JST PH 2-Pin Cable - Female Connector 100mm

[JST PH 2-Pin Cable - Female Connector 100mm](https://www.adafruit.com/product/261)
Red and black tinned wires with a 2-pin JST PH connector on the end. 4" / 100mm long. Matches up nicely with our Lipoly chargers!

[We have the socket 'mating' version of this cable](https://www.adafruit.com/product/3814) over here, <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/261)
[Related Guides to the Product](https://learn.adafruit.com/products/261/guides)
### 5V 2A (2000mA) switching power supply - UL Listed

[5V 2A (2000mA) switching power supply - UL Listed](https://www.adafruit.com/product/276)
This is an FCC/CE certified and UL listed power supply. Need a lot of 5V power? This switching supply gives a clean regulated 5V output at up to 2000mA. 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but you can pick one...

In Stock
[Buy Now](https://www.adafruit.com/product/276)
[Related Guides to the Product](https://learn.adafruit.com/products/276/guides)
### 1N4001 Diode - 10 pack

[1N4001 Diode - 10 pack](https://www.adafruit.com/product/755)
This here is a 10 pack of the classic 1N4001 power blocking diode. These are good for reverse polarity protection (put it between your DC power jack and circuitry to avoid a negative-voltage that would zap your delicate electronics), kickback protection (place across your solenoids, relays...

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

## Related Guides

- [Adafruit Circuit Playground Express](https://learn.adafruit.com/adafruit-circuit-playground-express.md)
- [Rose's Shield - Steven Universe](https://learn.adafruit.com/rose-s-shield-steven-universe.md)
- [Steven Universe Wearable, Fusable Gem](https://learn.adafruit.com/steven-universe-wearable-fusable-gem.md)
- [Glue Stick Light Pipe Sculpture](https://learn.adafruit.com/glue-stick-archway.md)
- [Meeting Time Keeper Stick](https://learn.adafruit.com/meeting-time-keeper-stick-with-cpx.md)
- [Obsidian Sword – Steven Universe](https://learn.adafruit.com/obsidian-sword-steven-universe.md)
- [Creating Custom LED Animations](https://learn.adafruit.com/creating-custom-led-animations.md)
- [Circuit Playground Seashell Pendant](https://learn.adafruit.com/circuit-playground-seashell-pendant.md)
- [Controlling a Classic Nintendo R.O.B. Robot Using Circuit Playground Express](https://learn.adafruit.com/controlling-a-classic-nintendo-r-o-b-robot-using-circuit-playground-express.md)
- [Jellyfish Umbrella with easy WLED WiFi Control](https://learn.adafruit.com/jellyfish-umbrella-with-easy-wled-wifi-control.md)
- [Cartoon Network and Make Code - Rose Quartz Shield Umbrella](https://learn.adafruit.com/cartoon-network-and-make-code-rose-quartz-shield-umbrella.md)
- [Make It Glow With Crickit](https://learn.adafruit.com/make-it-glow-with-crickit.md)
- [Edit CircuitPython Code on iOS with Runestone](https://learn.adafruit.com/editing-circuitpython-on-ios-with-runestone.md)
- [Circuit Playground Express Head-Tilt Ears](https://learn.adafruit.com/circuit-playground-express-head-tilt-ears.md)
- [Your First Power Switch Relay Project - Circuit Playground Smart Plug](https://learn.adafruit.com/beginner-first-project-power-switch-relay-circuit-playground-smart-plug.md)
- [Circuit Playground Express Sugar Glider](https://learn.adafruit.com/cpx-sugar-glider.md)
