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
- A bit of wire
- 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
- 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
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 :)
- Download the firefly PCB layout (bitmap, Dia)and arrange five copies to fit your Pyralux. Each one should be 3mm wide by 40mm long.
- 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.
- 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.
- 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.
- Label each wire with a colour: red, green, yellow and 2x blue.
- 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.
- Plug the firefly wires into the breadboard: blues to the resistor on D4, green -> D5, yellow ->D6 and red -> D7.
- Solder on the first LED. Some soldering hints:
- 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.
- Draw yourself a reference for the LEDs' anode and cathode ends. Check the datasheet if you're not sure.
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.
- 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.
- On one of the circles, draw a circle that's about 1cm in from the edge. Poke 20 holes in it at regular intervals.
- 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.
- 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.)
- 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.
- Make one or more holes in the cardboard near the Arduino. For each firefly wire:
- thread it through the new hole
- trim it to reach the resistor on the correct Arduino pin (or the connector, for the Tx/Rx lines)
- burn off the enamel from the end as before
- add a bit of heatshrink
- solder the wire to the resistor on the pin
- push the heatshrink over the resistor and shrink it
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.