You Are Here: Home » AVR ATmega Projects » New Jar of Fireflies

New Jar of Fireflies




When I ran across the Jar of Fireflies Instructable sometime this past summer, I knew I had to build it.  Full credit to Keso for an excellent set of instructions!  I wouldn’t have gotten to the point of developing the firefly behavior without such a solid base for building the hardware, as well as firmware to start it out with.  If you have already built a firefly jar according to those plans, it should be straightforward to reprogram it with my firmware to change its behavior.

I wanted to go a step farther when I built the firefly jar as a Christmas present.  My goal was to have multiple fireflies interacting, including males that sometimes synchronize with each other, and females that respond to the flashes of males. I also wanted to base it on the behavior of our backyard firefly, Photinus pyralis , the common Eastern firefly, which is also one of the best studied.  I wrote my own software for the microcontroller to simulate this behavior.  The full project is documented here , but this Instructable should be enough to follow.

The latest version of the firmware is available on GitHub .

You will need two things to use this software:

Both of these are outside the scope of this Instructable.  For the first, please refer to the detailed instructions at the original Jar of Fireflies .  If you need help with programming the AVR, a good place to start is the AVR tutorial from Adafruit .

I tried making a video to demonstrate the flashing behavior.  The quality isn’t great (it’s from an iPhone, and I reduced the quality to upload it):

Step 1: Hardware

hardware

The only changes I made to the original hardware were the addition of a push on/push off switch (scavenged from a stick-on LED light) and a 6-pin programming header to allow reprogramming of the jar after it had been built. To make testing and debugging easier, I also built a prototype board on a 2″x2″ perfboard with the same schematic, so it is electrically identical but easier to see what it’s doing, and less fragile.  I’ve added a view of the point-to-point soldering on the back of the prototype board in case that is helpful to anyone.  The prototype board can also be used as a target board for programming ATtiny85 (and -45) chips for other purposes.  In the real jar, the switch and header are fixed to the underside of the lid with J-B Qwik to keep them well attached.

Step 2: Software

software

After I built the firefly jar, I had planned to modify the software to change its behavior somewhat.  I was completely new to AVR programming, and I realized that I didn’t understand much of what was going on in the original code, so I decided to write my own from the ground up.  It uses the AVR’s internal timers for controlling the timing and brightness of the LEDs.

The simulated fireflies exhibit the following behavior, based on observations of the species Photinus pyralis , the common Eastern firefly (more details and references ):

  • Male fireflies will appear one at a time, flashing at a regular interval, 5.9 ± 0.6 seconds, and gradually synchronize with each other.
  • If all males are in sync, a female may respond to a male’s flash after a delay of 2.1 ± 0.2 seconds.  The appearance of another male out of sync will cause the female to stop responding to the first one.  The female’s flash is 1/10 the intensity of the males’.
  • Each pulse is 0.5 second in duration with a steep increase and slower falloff, which I modeled as y=x*e-x2
  • Females are stationary, they will flash at the same LED each time, while males can “move” around, flashing at randomly selected LEDs.
  • One reaching the end state of 6 males flashing and one female responding, it will continue that pattern until it is reset at a random interval, about 5-20 minutes.

The code was compiled with avr-gcc 4.2.0.  I used an ATtiny85, and it also works with an ATtiny45 on my prototype board.  There are also two shorter example programs included that can be used as a base for different behaviors.  All source code is freely available under the GPL .

Download the source code and compiled .hex files here .

 

 

Leave a Comment

You must be logged in to post a comment.

Read previous post:
FanBus Digital Fan and LED Interface for PC
FanBus Digital Fan and LED Interface for PC using ATMega168 microcontroller

Last year I modified a blue LED fan with RGB LED's to enhance the look of my server case.  Last...

Close
Scroll to top