Roses are red,

violets are blue,

this flower changes color,

to show its love for you!

Give your valentine a truly special gift with the cyber flower digital valentine project!  This is a beautiful artificial flower that glows different colors using a Gemma M0 and its built-in DotStar LED.  If you pick up the cyber flower it detects your touch and animates a glowing heart beat to show its love.  This flower will never die--as long as its batteries are charged.

The cyber flower is a great demonstration of CircuitPython code.  CircuitPython is a version MicroPython and the Python programming language which can run on boards like the Gemma M0.  With simple Python code the cyber flower animates its DotStar LED.  You can even modify the code with ease and no need to install software or complex tools.

Before you get started it will help to familiarize yourself with the Gemma M0 and CircuitPython.  Then continue on to learn about the parts and hardware needed to build this project.


You'll need the following parts to build this project:

Gemma M0 - You need the Gemma M0 and not the older Gemma board for this project.  The M0 version has a built-in DotStar LED that will light up the power by itself--no need to add any extra hardware!  In addition the M0 version of Gemma can run CircuitPython code which is what this project is built to use!

An artificial flower - Check your local craft store for a wide assortment of artificial flowers.  A white color flower is best because it will show the true colors of the DotStar LED, however you can experiment with other colors too.  Look for a flower with enough room to hold the Gemma M0 board in its center, like a rose, tulip, or similar flower.

Battery - A small lipoly battery like a 350mAh version is easy to hide between the petals of the flower.  Or grab a battery extension cable and larger battery or 3xAAA battery pack for more power options.

Solid core wire - Solid core wire is best for attaching to Gemma M0 and then wrapping around the stem of the flower.  This wire is used to detect when someone touches the flower stem and will trigger a heart-beat animation on the LED.  You don't have to attach this wire--if you don't then the touch sensing probably won't work but you'll still see nice color animations from the LED.

Soldering tools - If you're attaching wires for capacitive sensing you'll need to solder them to pads on the Gemma M0 board.  Check out the Adafruit Guide to Excellent Soldering for more details on how to solder!


Once you have the parts you can solder a few wires to the Gemma M0 board for capacitive touch sensing.  This isn't absolutely necessary though and can be skipped if you aren't confident with soldering.  Without the wires the flower won't detect touches but will still animate different colors.  As an alternative you might be able to tape aluminum foil or copper tape to the pads of the Gemma M0 instead of soldering, but it might not be as robust or strong as soldering wires.

If you're soldering wires it's best to strip the insulation entirely off one length of wire and solder it to the board's ground pad.  This will greatly help the capacitive touch sensing when running off of battery power because it depends on the person touching the flower being grounded to the battery.  Then solder an insulated wire (i.e. don't strip off the insulation) to the D0 pad of the Gemma M0.  Your Gemma M0 should have two wires soldered to it as shown below:

  • Bare / un-insulated wire soldered to Gemma M0 GND / ground
  • Regular / insulated wire soldered to Gemma M0 D0.

Next cut out the pistil from the center of your flower if you need to make room for the Gemma M0 board.  Side cutters work well for this task:

Then nestle the Gemma M0 inside the center of the flower.  If the flower is small enough it might hold the Gemma M0 in place without any assistance.  Otherwise you might need to add tape, hot glue, or even sticky tack to hold the board in place:

Snake the wires through the petals and down the stem of the flower.  If you're using wires for capacitive touch sensing wrap them around the stem in a double helix pattern.  This way when someone touches the stem they'll touch both the uninsulated ground wire and the insulated capacitive touch sensing wire:

Be careful with the uninsulated ground wire to ensure it does not touch any other pin on the Gemma M0. If the ground wire touches the 3.3V or Vout pins it can short out the board and potentially damage it, the battery, or a computer connected to the Gemma M0! Take care to carefully route and move the ground wire!

Connect the battery and you're all set!  The flower is ready to have code loaded onto it that will drive the DotStar LED!

The software for this project is written in CircuitPython so it's easy to run and modify, just write the code straight to the board's USB drive!  If you're new to CircuitPython and Gemma M0 first check out the Gemma M0 CircuitPython guide pages.  These will explain what CircuitPython is and how to load it onto your Gemma M0 board.

Before you continue make sure your Gemma M0 is running the latest version of CircuitPython by updating its UF2 firmware.  Also be sure you can see the board's CIRCUITPY drive when you connect it to your computer with a USB cable.  Once you see the CIRCUITPY drive you're all set and ready to load the project code.

Now you need to install two dependencies from the CircuitPython bundle.  Like the bundle install page mentions for non-express boards like Gemma M0 this means you have to download the bundle zip file, open it on your computer, and copy the following files and folders to your board's CIRCUITPY drive:

  • adafruit_dotstar.mpy
  • adafruit_fancyled

Be sure you've copied both these files and folders (and all the files inside the folders) to your CIRCUITPY drive before continuing!

Next download the file with the code for the cyber flower project by clicking the button below or going to its home on GitHub:

Copy this to your Gemma M0's CIRCUITPY drive.  Make sure to overwrite any that's already on the board!

At this point be sure your CIRCUITPY drive has the cyber flower, adafruit_dotstar.mpy, and adafruit_fancyled files and folder on it.  You can delete any other files and folders on the drive (boot_out.txt is created by the board with debug data, you can ignore it):

The flower code might start running as soon as you copy the file to your board.  However just to be sure you can eject the CIRCUITPY drive from your computer, then press the board's reset button and the flower code should start running.

When the flower code first starts it will wait 5 seconds and flash the Gemma M0's tiny red LED on and off.  This is a short delay that gives you time to stop touching the board and the D0 and ground wires.  For the capacitive touch sensing to work you want the board to be 'calibrated' with nothing touching it, so during the initial startup delay put the flower down so nothing is touching it.  Then after 5 seconds the red LED will stop flashing and the DotStar LED will turn on to animate different colors.  At this point the flower code is running--try picking up the flower or touching the D0 wire to see the heart beat animation!

Note that if the flower is only powered by a battery (i.e. not connected to your computer) you might need to touch both the ground wire and D0 wire to trigger the heart beat animation.  This is why assembling the flower with a bare / uninsulated wire connected to ground is best, it allows someone to touch the flower and simultaneously ground themselves and trigger the capacitive sensing.

Also be aware if you have trouble getting all the dependencies copied to your board and working, there's a variant that does not have any dependencies called  You can download and rename it to, then copy to your Gemma M0's CIRCUITPY drive.  There are no other dependencies needed to use this version of the code (but it's a little harder to read and follow compared to the main code above).

Modify The Flower Code

Out of the box the flower code should work great without any modifications.  However since it's all simple Python code you can easily change it with any text editor.  The code is written with a few variables at the top that you can change to modify how the flower works.  First make sure you're familiar with editing and running code on a CircuitPython board.

If you open the flower on the CIRCUITPY drive, notice these values at the top:

# Variables that control the code.  Try changing these to modify speed, color,
# etc.
START_DELAY = 5.0       # How many seconds to wait after power up before
                        # jumping into the animation and initializing the
                        # touch input.  This gives you time to take move your
                        # fingers off the flower so the capacitive touch
                        # sensing is better calibrated.  During the delay
                        # the small red LED on the board will flash.

TOUCH_PIN = board.D0    # The board pin to listen for touches and trigger the
                        # heart beat animation.  You can change this to any
                        # other pin like board.D2 or board.D1.  Make sure not
                        # to touch this pin as the board powers on or the
                        # capacitive sensing will get confused (just reset
                        # the board and try again).

BRIGHTNESS = 1.0        # The brightness of the colors.  Set this to a value
                        # anywhere within 0 and 1.0, where 1.0 is full bright.
                        # For example 0.5 would be half brightness.

RAINBOW_PERIOD_S = 18.0 # How many seconds it takes for the default rainbow
                        # cycle animation to perform a full cycle.  Increase
                        # this to slow down the animation or decrease to speed
                        # it up.

HEARTBEAT_BPM = 60.0    # Heartbeat animation beats per minute.  Increase to
                        # speed up the heartbeat, and decrease to slow down.

HEARTBEAT_HUE = 300.0   # The color hue to use when animating the heartbeat
                        # animation.  Pick a value in the range of 0 to 359
                        # degrees, see the hue spectrum here:

On the right you can see comments (text after a # character) which describe the values.  Try changing one of these, like the HEARTBEAT_HUE value at the bottom.  If you change HEARTBEAT_HUE from 300.0 to 180.0 it will change the color of the heart beat animation to a cyan/blue color.  Modify the value and save the file on your CIRCUITPY drive.  The board should see the changed code and start running it again (remember it has a 5 second startup delay where it blinks the red LED).  If you touch the D0 pad now the heart beat should be cyan/blue--cool!

Experiment with changing other values like HEARTBEAT_BPM to change how fast the heart beat animation runs, or RAINBOW_PERIOD_S to change how long it takes for the DotStar to cycle through a rainbow of colors.  Each time you change a value just save the on the board again and it should start running with the new code!

That's all there is to the cyber flower digital valentine project!

This guide was first published on Feb 05, 2018. It was last updated on Feb 05, 2018.