Synchronizing Fireflies
7 Steps
Have you ever asked yourself how do hundreds and thousands of fireflies are able to synchronize themselves? How does it work, that they are able to blink all together without having a kind of boss firefly?

This instructable gives a solution and shows how this synchronization can be achieved.

I have always been fascinated by self organization of insects. A couple of years ago I wrote a Java-Applet that simulates a square of thousands of fireflies. It worked well and was fun to watch. This time I have done it in hardware.

Credits for inspirations goes to Keso and his Jar of fireflies http://www.instructables.com/id/E7U5HYMSVIEWP86SAL/.

Any comments or corrections are welcome.

Update 2008-09-12: There is a new version of the fireflies online at Synchronizing Firefly Howto. It has a custom PCB for every firefly. And you can buy a kit at the Tinker Store.

Here is the video:

Remove these ads by Signing Up

## Step 1: How it works

The algorithm

What can be observed is that the fireflies start with random blinking. But as time goes by, they are able to slowly synchronize with their nearest neighbors. And these neighbors are synchronizing themselfes with their neighbors and so on an so on. Until the whole tree or the whole valley blinks in the same cycle.

And what is it good for? It is used to attract other specimen. With all the blinking in sync it is much easier to find a partner.

One of the easiest algorithm to explain this behaviour goes like this: You have a value that holds the power to flash. As time passes this power will slightly raise. If the power reaches a certain level, the firefly flashes and the power is consumed. The rate at which the power raises is nearly the same for all fireflies. So they have the same frequency but not the same point in time to flash.

While slowly charging with power the firefly is able to detect a flash of another firefly nearby. It adds then a higher value to its power value. Some kind of power boost, if you wish. That means the next flash will occur earlier than the one before. And next one even earlier, until these two are flashing exactly at the same point in time and with the same speed.

You can find more on this algorithm e.g. here:

The Hardware

I decided to use my previous instructable (Programmable LED) as starting point. It consists of a microcontroller, an LED and an Light Dependent Resistor (LDR). That should be enough to simulate a simple firefly. It is able to flash, to see and to count.

I just had to modify the program and the orientation of the LED and the LDR. LED and LDR must been placed in a way that one firefly circuit is able to interfere with another. So one LDR must be able to "see" the LED of another firefly. And it should not only see one neighbour but more. That can be done by letting the LED and the LDR pointing up from the ground and use some white paper to reflect the flashes.

 1-40 of 116 Next »
Hamid_f says: Nov 30, 2011. 2:44 AM
Hi Alex,
I remembered an old german tv documentary (maybe Spektrüm) about non-linear and chaotic systems, fractals and some structures called "cooperative aggregation" or "cooperative memory" (i don't know exact term), if you remove a little pixels of a picture after iterations lost information can be repaired (rebuilt). brightness of each pixel is sum of neighbors brightness with particular weight. a focused camera on a tv was setup of this idea. do you know about this?
alex_weber (author) says: Nov 30, 2011. 2:30 PM
No, unfortunately I don't.
If you find it somewhere, please let me know. Sounds interesting.
abend says: May 17, 2012. 7:52 PM
That sounds a lot like Hopfield networks, which are a type of artificial neural network.
Sep 11, 2011. 6:01 PM
Why use a socket when you can soder the chip right to the board and you could bend the leds down maybe or they might just light a ton of them up.
alex_weber (author) says: Sep 11, 2011. 11:09 PM
The socket is for reprogramming them. The is not enough room for an ISP header.
eulaliaaaa! says: Aug 5, 2010. 6:28 PM
(Piano music) You would not believe your eyes, if ten million fireflies, Ate out your eyes and then farewell. They fill the open air, and scatter body parts everywhere, I don't mean to be rude but an arm is over there.
theawesomeninja says: Aug 22, 2011. 12:19 PM
♫ I'd like to make myself go pee....But planet earth is gory. It's hard to stay coherent when I'm all but torn apart. And it appears my dog consumed my heart.....♫
trailleadr says: Aug 21, 2011. 6:52 PM
lmao, now that's funny!!
Ghost Wolf says: Sep 5, 2009. 7:50 PM
Do you need to program every single ic?
alex_weber (author) says: Sep 6, 2009. 12:40 AM
Yes, you have to. Gets a bit tedious, but there is no other way.
JD_Mortal says: Aug 22, 2011. 12:19 AM
The "other way" would be to use an ATMEGA 328 P (Arduino Duemilanove) with a LED-ARRAY setup. This involves a slightly more complex program, but it saves you some soldering and hardware costs.

You use the 13 digital outputs to create a grid for the LEDs 6x7 = 42 max leds. You use the 6 analog inputs with 7 stacked resistors (making a grid array of inputs) with the light sensors. Or you can use less leds, and have the extra digital pins as part of the analog input array.

Since the LEDs don't need full power, or constant power to look ON... You turn on each led in the grid, of each row, while you cycle through the grid. (Look up the 3D LED array, and you will see what I am talking about.) Additionally, adding a capacitor to the LED will help it appear ON and brighter between grid cycles.

Plus you get the added bonus of being able to scroll letters and do a-life programs!

Love this setup BTW. Would be neat with them all freely inside a jar, frozen in epoxy or mounted on a screen in the jar.
Ghost Wolf says: Sep 6, 2009. 5:10 PM
Once you turn it off (0Vs) will the ic lose it's memory?
alex_weber (author) says: Sep 6, 2009. 11:31 PM
Yes and no. Yes, it will loose its main memory. And no, it will not loose its program. The program is stored in flash ram, like on your USB memory stick.
Ghost Wolf says: Sep 7, 2009. 11:11 AM
What is the main memory used for?
alex_weber (author) says: Sep 7, 2009. 2:39 PM
The main memory is used for variables while executing the program. It is used to store, which part of the program is executing right now. If the controller looses power, the main memory is lost. If you turn power on again, it will start the program from the beginning, because it has lost its state. It is like booting up your PC. Data on your harddisk is still there but data in memory is gone. Does that clear things up?
Ghost Wolf says: Sep 7, 2009. 6:44 PM
Yes thank you very much
Ghost Wolf says: Sep 8, 2009. 7:30 PM
Can you use different LEDs?
alex_weber (author) says: Sep 8, 2009. 11:28 PM
Sure. The sensor detects only brightness, not color.
Ghost Wolf says: Sep 9, 2009. 9:17 PM
Thanks i just wanted to know, a another question I have Is there any photos of the back side?
alex_weber (author) says: Sep 10, 2009. 1:53 PM
No, I'm sorry.
Ghost Wolf says: Sep 12, 2009. 11:33 AM
I was just wondering because I want to how you supply power to the unit
an1153 says: Aug 21, 2011. 10:55 PM
LOL
broper says: Aug 21, 2011. 8:50 AM
cool
mkpeker says: Apr 10, 2011. 1:30 PM
Thanks for your good project but unfortunately this circuit doesnt matches with the code on step7.

True circuit:

pin1: 10k to vcc
between pin2-3: LDR(best 10k LDR)
between 3-4: 1k resistor
pin4:GND
pin 5 and 6 not connected
pin7: green led by 220 ohm to GND
pin8:vcc

Thank you anyway
elektroking says: May 20, 2010. 2:03 AM
Hello
i have a tiny13 and want to put in te program of the fire flies but with mikroc PRO for AVR it doesn't work. Witch programmer have jou used for the program?

Kluzze
AndyGadget says: May 3, 2010. 4:41 AM
Any chance of restoring the video?
I'd really like to see this.
GOwin says: Dec 27, 2009. 9:35 AM
very nice!

Is there a way to "talk" to each firefly (ie ask one to turn itself on or off)?
Xenel says: Mar 7, 2009. 3:43 PM
Synchronizing Christmas tree lights anyone?
lasermaster3531 says: Jul 18, 2009. 1:13 PM
cool!!
twist2b says: Jul 1, 2009. 7:30 AM
What if I want to have a couple all over my room, they go off all day, but by night they can synchronize when there is no light. Here is the question though, how large of a distance can you get? And how can you make something like this to work with larger distances?
o_k_boy says: Jun 3, 2009. 1:26 PM
hi alex, great project - i'm a newcomer to avr programming and have been reading your blog and instructables carefully. they have been very useful, so thank you very much. i know this version of firefiles has been superseded now, but in the schematic you have the ldr positioned between pins 1 and 2 of the avr - is this correct or should it be between 2 and 3?
alex_weber (author) says: Jun 3, 2009. 2:54 PM
Hi o_k_boy, yes, you are right, good catch. The ldr is between 2 AND 3. You can check also the source code for the pin definitions. Cheers, Alex
uberdum05 says: Jan 25, 2009. 12:29 PM
Could you do this with 1 arduino board and 5 photoresistor / led combinations??
alex_weber (author) says: Jan 25, 2009. 2:22 PM
Hi uberdum05, yes, you could. But you would loose some of the non deterministic behaviour that arise from using independent devices with slightly different timings. Every firefly has its own internal oscillator and they are all a bit different. If you do it with a single Arduino, I think it will be much less chaotic. Cheers, Alex
Carlos Marmo says: Oct 30, 2008. 2:56 PM
Wonderful work! Much Style! Congratulations!
Goodhart says: Sep 20, 2008. 4:55 PM
Oh cool, a hardware version of Emergence theory......I will have to have a go at this in the future. :-)
kiowamike says: Sep 15, 2008. 5:41 PM
Great project! I am putting together the parts for this thing but, I am having trouble finding the LDR's. Since I don't speek Dutch or German, I was wondering if you have a Digikey.com part number. Thanks.
alex_weber (author) says: Sep 16, 2008. 8:37 PM
Hi kiowamike,
try this at digikey: http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail?name=PDV-P9001-ND
Maybe you have to adjust the resistor connected to the LDR.
Cheers,
Alex
kiowamike says: Sep 16, 2008. 9:17 PM
Thanks a bunch. I'll give it a try and let you know how it works.
azog says: Aug 11, 2008. 5:10 AM