Fran’s Digital Fireflies

Here’s a simple Arduino project to recreate the digital firefly jars you might have seen around the last few years. From Frantone:

This was a simple little project that was really just an excuse for me to learn Arduino.  I bought some really attractive Ball canning jars at the market and thought that it would be really cool to use them to make some kind of bedside firefly jar.  I thought that I would use an array of RC transistor timers to drive some vintage 70’s amber lens LEDs I had in stock.  But I wanted these virtual fireflies to act like the real thing, and I soon realized that there would have to be 4 separate operations to depict a realistic firefly blink, with a quick fade-on period, a brief stay-on period, a slower fade-off period, and a long off-rest period.  Visualizing the large array of discrete RC timers I would need to create several fireflies was going to be prohibitively complex to shove into a jar lid, so I thought that this would be a really good job for a microcontroller. 

Proto-typin’!
I got an Arduino UNO R3 board from Adafruit Industries that acts as a USB interface to an ATmega328 microcontroller, and I wrote the code on my PC using the Arduino open-source software.

6 of the 14 ATmega328 I/O pins provide 8-bit pulse width modulated (PWM) output with the ‘analogWrite()’ function and I wrote the code to create the illusion of 6 firefly tails, giving each of them their own ‘personality’ through independently varying rates and fluctuations, so that the sequence would be ever changing.  I also wanted my fireflies to respond to the environment, because as we all know the real things would never come out to do their dance before twilight – so I added a photoreactive circuit using a common photo resistor and a 2N3904 transistor to turn on the LEDs only when the ambient light was suitably dimmed. 

This was going to end up being a self-contained autonomous display, so I would prototype it on the UNO board to prove the concept, then I would remove the programmed Atmega328 microcontroller chip and transplant it to my own smaller battery powered board that would contain the completed circuit, which I would build into the bottom of the jar lid. 

I wrote this code as a single continuous loop program with 24 subroutines to independently control the four states (fading on, staying on, fading off, and staying off) of each of the 6 output pins (ledPin function) to drive each LED, and global variables had to be set to keep track of what state each firefly was in and at what point in that state, so that the results could be written to the pin outputs and those variables could also be updated with each cycle of the loop, which constantly changes the write values, creating the illusion of multitasking six independent routines with a single processor.

It is a very simple program and it works satisfyingly well – more satisfying was the fact that I was able to finish this code and have it debugged within just a day or two of beginning to read up on what the heck Arduino was.  It is quite literally that easy to work with.  If you have any coding experience at all in BASIC or C then you will have no problem transposing your coding chops to Arduino.  It’s awesome!

Read More.


Adafruit publishes a wide range of writing and video content, including interviews and reporting on the maker market and the wider technology world. Our standards page is intended as a guide to best practices that Adafruit uses, as well as an outline of the ethical standards Adafruit aspires to. While Adafruit is not an independent journalistic institution, Adafruit strives to be a fair, informative, and positive voice within the community – check it out here: adafruit.com/editorialstandards

Join Adafruit on Mastodon

Adafruit is on Mastodon, join in! adafruit.com/mastodon

Stop breadboarding and soldering – start making immediately! Adafruit’s Circuit Playground is jam-packed with LEDs, sensors, buttons, alligator clip pads and more. Build projects with Circuit Playground in a few minutes with the drag-and-drop MakeCode programming site, learn computer science using the CS Discoveries class on code.org, jump into CircuitPython to learn Python and hardware together, TinyGO, or even use the Arduino IDE. Circuit Playground Express is the newest and best Circuit Playground board, with support for CircuitPython, MakeCode, and Arduino. It has a powerful processor, 10 NeoPixels, mini speaker, InfraRed receive and transmit, two buttons, a switch, 14 alligator clip pads, and lots of sensors: capacitive touch, IR proximity, temperature, light, motion and sound. A whole wide world of electronics and coding is waiting for you, and it fits in the palm of your hand.

Have an amazing project to share? The Electronics Show and Tell is every Wednesday at 7pm ET! To join, head over to YouTube and check out the show’s live chat – we’ll post the link there.

Join us every Wednesday night at 8pm ET for Ask an Engineer!

Join over 36,000+ makers on Adafruit’s Discord channels and be part of the community! http://adafru.it/discord

CircuitPython – The easiest way to program microcontrollers – CircuitPython.org


Maker Business — “Packaging” chips in the US

Wearables — Enclosures help fight body humidity in costumes

Electronics — Transformers: More than meets the eye!

Python for Microcontrollers — Python on Microcontrollers Newsletter: Silicon Labs introduces CircuitPython support, and more! #CircuitPython #Python #micropython @ThePSF @Raspberry_Pi

Adafruit IoT Monthly — Guardian Robot, Weather-wise Umbrella Stand, and more!

Microsoft MakeCode — MakeCode Thank You!

EYE on NPI — Maxim’s Himalaya uSLIC Step-Down Power Module #EyeOnNPI @maximintegrated @digikey

New Products – Adafruit Industries – Makers, hackers, artists, designers and engineers! — #NewProds 7/19/23 Feat. Adafruit Matrix Portal S3 CircuitPython Powered Internet Display!

Get the only spam-free daily newsletter about wearables, running a "maker business", electronic tips and more! Subscribe at AdafruitDaily.com !



No Comments

No comments yet.

Sorry, the comment form is closed at this time.