Jar of Fireflies (animated)




Introduction: Jar of Fireflies (animated)

It's a jar full of fireflies! Watch them glow and fly around the jar, or tap the lid to frighten them all into flying at once.

The "fireflies" are actually strings of tiny LEDs on flexible circuit boards, animated by an Arduino hidden in the lid.

This Instructable was inspired by another firefly jar by Keso. This one has animated fireflies and interactivity, but it will have a shorter battery life.

Step 1: Parts

To create a jar like this, you will need:

  • A nice jar
  • A 3xAA battery holder, with screw holes
  • 60 yellow-green SMD LEDs, plus spares
  • Flexible circuit board material, e.g. Pyralux
  • A way to etch circuit boards
  • Enamelled wire, a.k.a. magnet wire
  • 20 through-hole resistors
  • An Arduino Nano or compatible
  • A piezo sensor
  • An 820K through-hole resistor, or thereabouts
  • Heatshrink
  • A bit of wire
  • Cardboard
  • A switch
  • Five bolts, with nuts

Additionally, the following are useful during construction:

  • A bit of sticky tape
  • A couple of clothes pegs
  • A random bit of stripboard, veroboard, whatever
  • Sticky labels
  • Tweezers
  • Good lighting
  • A soldering iron with adjustable temperature and a fine tip
  • Five bits of single core wire or breadboard jumper leads
  • A breadboard
  • A sharp pointy thing for making holes in card
  • Tiny scissors (e.g. thread scissors)
  • A multimeter with a conductivity test feature
  • Black nail varnish
  • Tea

Step 2: Choose a Jar

The ideal jar has a screwtop lid that's both wide and deep enough to hide the 3xAA battery holder, with room to spare. It's also helpful if the glass isn't completely smooth. Patterns or embossed text will distort the structure of the LED fireflies and give a more realistic appearance.

Bonus points if your jar already has a handle, but if not, no problem: you can add one yourself. There's an example here.

Step 3: Choose the LEDs, Resistors and Switch

For best results, choose Surface Mount Device (SMD) LEDs that:

  • have a wide viewing angle, say 140º or more
  • fit the PCB design, i.e. 0.8mm x 1.1mm or thereabouts
  • draw between 20 and 30mA current. Higher current will be brighter.

You need 60 LEDs for five fireflies, but SMD LEDs are so tiny that they disappear into the carpet if you so much as breathe on them, so order plenty of spares.

Fireflies can be green, yellow or orange depending on species. This jar uses yellow-green LEDs (573 nm).

The resistors can be through-hole, there will be plenty of room to hide them in the lid. For maximum brightness, use an LED Resistor Calculator to work out the resistance you'd need for one LED, then divide that number by two and order 20 of those. If you're not sure, 100 ohms will be fine.

The switch should be short enough to fit under the lid. If the lid has some extra space like mine did, you can use a toggle switch; if not, a small slide switch would work better.

Step 4: Set Up a Firefly Test Rig

The firefly code includes a test mode that makes one firefly light up repeatedly from head to tail. We'll use this to make sure each LED is soldered correctly.

Enable test mode by uncommenting the "TEST_MODE" compiler directive. Then compile and upload the test code to your Arduino.

Put the Arduino on a breadboard. Connect a resistor from each of the pins D4, D5, D6 and D7 to unused columns.

Step 5: Make the Fireflies

Each firefly consists of twelve LEDs soldered to a flexible PCB. We're using charlieplexing to control the LEDs, so the direction and order in which LEDs are soldered is important. This stage is a bit of a faff*, but it'll be worth it :)

  1. Download the firefly PCB layout (bitmap, Dia)and arrange five copies to fit your Pyralux. Each one should be 3mm wide by 40mm long.
  2. Etch the circuit on the flexible PCB material. Any standard process should work; I got good results with toner transfer paper and fine etch crystals. If you're printing onto transfer paper, don't forget to flip the circuit before printing.
  3. Cut five lengths of enamelled wire, a bit longer than the jar is tall. Turn your soldering iron up to about 400ºC (752ºF) and set up adequate ventilation (this bit is toxic). Put a big blob of solder on the iron** and run the end of the wire through it until the coating wrinkles away, exposing a few mm of the shiny silver core.
  4. Turn the iron back to regular soldering temperature and solder a bit of single core wire on each end. This wire is temporary, and lets you plug the enamelled wire into a breadboard reliably.
  5. Label each wire with a colour: red, green, yellow and 2x blue.
  6. Solder the wires onto the PCB, using the reference diagram. The little flexible board is difficult to grip, so I suggest pegging it onto a random bit of stripboard or similar. It's distressingly easy to bridge the PCB traces while doing this bit, so test that none of the tracks have been bridged as you go.
  7. Plug the firefly wires into the breadboard: blues to the resistor on D4, green -> D5, yellow ->D6 and red -> D7.
  8. Solder on the first LED. Some soldering hints:
    1. Stick a bit of masking tape to your desk, sticky side up. Store the LEDs on it, then they won't ping away when you try to grab them with the tweezers.
    2. Draw yourself a reference for the LEDs' anode and cathode ends. Check the datasheet if you're not sure.
  9. Power on the Arduino and check that the LED flashes about once every 2s.
  10. Continue adding LEDs and testing. Note that the LEDs are soldered in alternate directions! When you have three LEDs done, you'll see something interesting: Three LEDs light in sequence, then the last two light together. This is a side effect of the incomplete charlieplexing matrix, and nothing to worry about as long as all the LEDs so far light up at least once.
  11. Trim off as much yellow as you can.
  12. Wrap the lower blue wire up around the firefly. Trim the end, burn the enamel, and solder to the top blue pad where the other blue wire is connected. (Yes, this will probably make the top blue wire fall off again. It might take a few attempts.)
  13. Wrap the lower yellow wire up around the firefly.
  14. Gently bend the firefly into an S or J shape. The wire wound around will hold it in place.Test once more!
  15. Desolder the temporary breadboard connection wires. It's finished!
  16. Make yourself a cup of tea. You've earned it.

Then make four more fireflies in the same way.

* "bit of a faff": British colloquialism meaning "very difficult; maddeningly frustrating; expect lots of swearing".

** If anyone asks, it wasn't me that told you to do this.

Step 6: Make the Jar Assembly

Congratulations, the hard part is done! The next stage is mounting the fireflies and other components into the jar. The exact steps will vary depending on the size of your jar and components, but the general idea is to have a circle of card under the jar lid with everything hanging down from it. If the switch fits under the jar lid, you can have it pointing up so it's easy to get to; if not, you'd have to mount it facing down.

  1. Place the jar upside down on the cardboard and draw around it. Repeat, then cut out to get two cardboard circles. Place them on top of the jar and check that the lid will screw down with the card in place.
  2. On one of the circles, draw a circle that's about 1cm in from the edge. Poke 20 holes in it at regular intervals.
  3. Thread the firefly wires through the holes. Move or redo the wire labels so you keep track of which wire is which. For each firefly, pull the wires through until it will hang at a nice height inside the jar (make each height a bit different). Stick the wires down when you're happy with the heights.
  4. Solder the connector and 20 resistors to the Arduino. (The connector lets you disconnect fireflies from the Tx/Rx lines when you need to upload code.)
  5. Arrange the battery holder, switch, Arduino and piezo sensor inside the inner circle, on the same side as the fireflies (ie. the components will hang facing downwards inside the jar). Make holes as required, then bolt on the battery holder, screw in the switch, tape down the piezo sensor and fix the Arduino in with a twist-tie or two.
  6. Make one or more holes in the cardboard near the Arduino. For each firefly wire:
    1. thread it through the new hole
    2. trim it to reach the resistor on the correct Arduino pin (or the connector, for the Tx/Rx lines)
    3. burn off the enamel from the end as before
    4. add a bit of heatshrink
    5. solder the wire to the resistor on the pin
    6. push the heatshrink over the resistor and shrink it
  7. Trim and solder the battery holder wires, via the switch, to the Arduino (not forgetting to add heatshrink).
  8. Trim the piezo sensor wires and solder them to the Arduino with the 820K ohm resistor in parallel.
  9. Take the second cardboard circle and make a hole in it for the switch to poke through, then unscrew the switch and put it through both cardboard circles before reattaching it.
  10. Make five holes through both cardboard circles, evenly spaced around the inner circle that you drew earlier, being careful to avoid the firefly wires. Put a bolt through each one and tighten the nut. These bolts rest against the sides of the jar, and let you operate the switch without the circles sliding about on top of the jar and potentially damaging the fireflies.

Step 7: Test, Calibrate and Finish

Comment out the TEST_MODE compiler directive, recompile, and upload the firefly control code to the Arduino. You'll need to disconnect the firefly lines on the Tx/Rx pins while you upload code.

Disconnect the USB, add batteries to the jar and power it on. Hopefully all the fireflies are lighting up at random. Check each one for loose connections and fix anything you find. When you're happy with them, spray them with PCB enamel to protect the copper.

Screw on the lid, then knock on it to see if the piezo sensor is working. You should see all the fireflies light up at once. If not (or if it's too sensitive and the fireflies are "frightened" by any movement), change the piezo threshold number in the code ("KNOCK_THRESHOLD") and reupload it. A lower number will make it more sensitive. If you're having problems getting a good threshold, you can check the values coming from the sensor by printing them out over serial.

If the LEDs on the Arduino are spoiling the effect, you can desolder them, or just cover them up with a thick blob of black nail varnish.

Label the switch "on" and "off" positions.

And there you go: a jar full of fireflies.

First Time Author Contest

Participated in the
First Time Author Contest

Be the First to Share


    • Audio Challenge 2020

      Audio Challenge 2020
    • Maps Challenge

      Maps Challenge
    • Backyard Contest

      Backyard Contest

    6 Discussions

    Mad Props
    Mad Props

    2 years ago

    This is outta my league to make and it may be for others as well. I be t you could sell these, they are so cool!


    Reply 2 years ago

    Thanks! I see you're using lighting effects in your props too, maybe there's something you could use here? Arduino is a great place to start if you need customised lighting patterns.


    2 years ago

    This is ultra cool for those of us who live in parts of the country that don't have fireflies. Although if I do happen to visit an area with real fireflies, you can bet your ass that I'm doing the traditional thing by catching those suckers and putting them in a jar.
    The real ones won't be safe from me. He he he.


    Reply 2 years ago

    I'm in the same boat, I'd love to see the real thing!


    2 years ago

    It looks great!