Synchronizing Fireflies NG

s-dsc_0080.JPG

Update 04. Dec. 2008: This article is replaced by the new howto.

This is a remake of the fireflies which I did a year ago. I was always fascinated by the emergence of patterns. One I like most is the synchronization of hundreds or thousands of fireflies. First they flash randomly but after some time and influencing each other, they flash in sync.

This circuit simulates fireflies with small microcontrollers. Note that every firefly acts completely autonomously, it is not a preprogrammed pattern. It is a self organizing system.

The NG version uses a small PCB (Printed Circuit Board) and a RGB-LED.

Software

Each firefly has a value that stands for the power to flash. This value rises over time. If the power reaches a certain limit, the firefly flashes and the power is reset to zero. If the firefly detects another flash nearby, it increases the power by a small boost value. That way it will flash slightly earlier than last time. Doing so over and over again may lead to all fireflies flashing in sync.

The RGB-firefly uses color to express its mood. If all is in sync, it will flash in relaxed and cool blue. If it detects flashes that are not in sync, it will get a bit uncomfortable and the color will slightly change to green, yellow and red.

The circuit

Firefly schematic

The circuit is rather simple. Main parts are the microcontroller, the light sensor and the RGB-LED. The sensor and R4 are forming a voltage divider. An ADC (Analog Digital Conversion) channel at pin 3 is used to read the values of the sensor. The circuit is designed for 5V power supply. It has no integrated power regulator.

Parts

dsc_0008-s.JPG

Here are the parts, that are needed for a single firefly.

  • Firefly PCB
  • ATtiny13v, digi-key
  • RGB-LED, 4000 mcd, generic
  • 8-pin socket, generic
  • 3 * 100R resistor, R1, R2, R3, generic
  • 1 * 4.7kR resistor, R4, generic
  • Photoresistor (LDR), 4k to 11kR
  • pin header and socket (used for power supply)
  • ping pong ball

Various types of photoresistors exist. I tried two different versions and both work well. Only resistor R4 has to be adjusted, as R4 and the photoresistor are building a voltage divider. Choose R4 in a way, that gives you a good range of voltage and still limits the current through the photoresistor.

My latest experiments showed that a phototransistor seems even better suited. Compared to the LDR, it does not have a memory effect and reacts faster (~5ms compared to ~50ms). I chose the SFH 3310 and 100k for R4.

One thing to remember while choosing a light sensor, is that the spectral sensitivity of the sensor has to match the humans eye sensitivity (~400 nm – ~700 nm).

Solder it

s-dsc_0011.JPG

First solder the power connectors. Having a female and male connectors on the boards makes it easy to power a couple in a row.

s-dsc_0012.JPG

s-dsc_0013.JPG

Next insert the resistors. R1-3 are 100R, R4 is 4.7kR (depends on the sensor).

s-dsc_0015.JPG

Solder them.

s-dsc_0016.JPG

Cut off the legs.

s-dsc_0018.JPG

Next insert the 8-pin header for the controller. Note that the notch of the header points up.

s-dsc_0017.JPG

Solder the header.

s-dsc_0020.JPG

Next insert the LDR. For the LDR the orientation does not matter. For the phototransistor it does! The phototransistor has a long (emitter) and a short leg (collector). Insert it with the long leg at the bottom. And solder it.

t-dsc_0021.JPG t-dsc_0022.JPG

Now prepare the LED. Mine are clear and have a lens on top. Use sandpaper to roughen the surface. That way the light of the LED will be emitted in all directions.

s-dsc_0023.JPG

The RGB-LED has four pins. Mine is a common cathode.

  1. green (short)
  2. blue (longer)
  3. GND (longest)
  4. red (shortest)

Bend the two inner legs a bit off.
s-dsc_0024.JPG

Insert the LED. Be sure to have pin 1 in the hole with the square solder pad. The longest leg is in the diagonal opposite corner. Now solder it.

s-dsc_0025.JPG

Now it should look like this and we are almost done.

s-dsc_0026.JPG

Drill a 4mm hole in the ping pong ball. Use a file to widen the hole a bit. Try to put it on the LED.

Program the controller and insert it into the socket. Take care of the notch.

s-dsc_0027.JPG

Here is the final result, the first firefly. Ready for some action.

Issues

There are minor issues that I want to have fixed for the next batch of PCBs.

  • I will make the PCB a bit larger to make it more stable.
  • The circuit is missing bypass capacitors (100nF and 100uF). It works great without but it’s best practice to have them.
  • The sockets for the power supply are not protected against polarity reversal. Not quite sure how to fix this.

Conclusion

Firefly

Playing with these fireflies is really mesmerizing. It’s not like most computer controlled things because it is non deterministic. Every time you start it, it will produce new patterns and behave differently.

I am quite happy how well the PCB worked out. It was my second design that I have had produced. Now I am feeling confident enough to go for a bigger batch of PCBs.

Downloads and Links

53 Comments

  1. To overcome the possibility of polarity reversal use 3 pin sockets/plugs; Outer pins being ground and the center one being the ‘live’ ;)

    Like

  2. Naaa, use batteries ;)

    Congratulations! Looks really good! Still thinking of a BEAM version. Did you remove the color chhange or does it simply not show in the video?

    So what nexts? Traffic Light Pingers?

    Like

  3. @Omer, thanks for your suggestion, I will try that.

    @Marcus, the colors are so great in real and so lame in the videos. But you can see some colors in the second video (at ~1:28).

    Cheers,
    Alex

    Like

  4. If you want to stick with 2 pins for power, you can put a diode across the power and ground connections so that if you hook it up backwards, current will flow through the diode and be clipped at .6 V for a Silicon diode or .2 V for a Schottky diode.

    Like

  5. Congrats.

    The addition of color really improved the project, it as beautiful before but the color really makes it easier to see witch firefly is out of sync.

    Liked the idea of putting the LED on top of the LDR.

    Like

  6. Very nice job, it would be realy interesting to see how they behave if you had a single line of say 25 to see them strobe along the line and slowly come to synchronisation in small groups at differect sections, and then finally all in synch.

    Like

  7. Hi – Nice work!!

    I’m wondering how hard it would be to measure the level of light for each pulse (or pulse window). Maybe this would then allow for quicker synchronisation as the unit measuring could pick the best time based on amount of light in given time = proximity of the mass being in sync.. ??

    Just a couple of thoughts anyway – keep it up! :)

    Heath

    Like

  8. these must be really interesting and relaxing in person. I think the next thing you should add to them is a relaxing “chirp” noise, something to really complete the effect of the firefly…. Really digging the project.

    Like

  9. Very interesting project. I like the way the rebellious element near the end was put back in the rank progressively :)

    I’m wondering how do you prevent fireflies to react to their own flashes ?

    Like

  10. So cool!

    what jonathan said ^^^ you just need a diode across the + and – hooked up backwards.

    pick up a copy of “the art of electronics” you won’t regret it :)

    Like

  11. Hello,
    I am a high school science teacher and would like for my physics class to build the fireflies on an individual basis. They could then link them together and watch how they eventually synchronize. Please let me know how much complete kits of parts, PCB and ping pong ball would be on an individual and bulk rate of 15 to 30 kits.

    Thank you for coming up with a great way to teach electronics and simple programing.

    Sincerely,
    JImmie

    Like

  12. Jimmie,
    it would be great to see them used for teaching in a class.
    I will release them as a kit and I hope it’s all up and running in November.
    Cheers,
    Alex

    Like

  13. I believe that this is how the basic neuron learns, actually. Instead of light, it uses pulses of electrochemical signals. The strength of the signal determines the proximity, and after a while of successful prediction, the neuron gains more and more ‘stubbornness’ about changing its learned behavior. This is what creates the plasticity of the brain.

    The natural laws dictate that things follow the path of least resistance, and find the lowest energy state. Evolution itself can be described as the constant seeking of the lowest energy state (a balanced world). One can think of blinking in synchronicity as the lowest energy state if you assign the out of sync blinking as being an energy consuming tug of war.

    There is no reason why one shouldn’t be able to easily modify this project and turn it into an adaptive learning network.

    Like

  14. This project is really cool. Self-assembling patterns are always sweet, and here they also look excellent. Good work.

    Like

  15. Well done — always interesting to see how this is progressing. If you put one in front of a mirror, does it go crazy?

    Like

  16. David,
    the fireflies can only connect to their direct neighbours, in that there is a difference to neurons, which are more widely connected.

    MadScott,
    no, the firefly is blind, when it flashes, so it won’t see it’s flash in the mirror. Ok, it depends, on how far you put the mirror ;)

    Like

  17. What is the effective range of the LDR and later the phototransistor? Could several Fireflies be spread around the room with enough sensitivity to sync with the rest?

    Like

  18. No, definitely not. The fireflies have to stay really close together, at most 15 cm apart from each other. The LDR and the phototransistor did not make a noticable difference.
    Take a look at the video at the top of this posting. It shows, how far apart two fireflies can be without sensing each other.

    Like

  19. Great Work!
    I wonder if it would be possible to place (nearly) all electronics inside the ping pong ball? Perhaps if the µC and the resistors are in SMD technique?

    Oliver

    Like

  20. Oliver,
    thanks, yes, I thought of that too. The ping pong ball would be a great enclosure. But I am not sure if the light sensor will be sensitive enough if it was placed inside. Maybe I’ll try that.
    Cheers,
    Alex

    Like

  21. Great project. I have everything “mostly” working on my breadboard with two attiny13’s, but I’m wondering how you would modify your code to work with a common annode rgb led?

    I’ve got the smart-led code you reference to work well and that was built originally using a common annode rgb led but that code makes it easy with a simple commented out line for cathode vs. annode.

    Still getting my head wrapped around this stuff :) thanks for any direction.

    Like

  22. Justin,
    common anode means the pins are active low. It should work if you swap the lines that switch the LED on and off. So swap the line
    PORTB |= (1 << R_BIT); // switch on
    with
    PORTB &= ~(1 << R_BIT); // switch off
    and do so for G and B as well.
    Cheers,
    Alex

    Like

  23. Regarding the polarity protection on the power connections, a simple solution would be to use 3 pins

    — +V
    — 0V
    — +V

    If reversed, the circuit would continue to function.

    Like

  24. Oops, it seems someone beat me to it! I should read the previous comments first!

    Like

  25. Awesome project!!! I have two questions:
    1. would ATTINY13-20PU work:
    # IC, 8-BIT 1K FLASH MCU Timers, No. of:1
    # Bits, No. of:8
    # Frequency, clock:20MHz
    # Memory size, RAM:64Byte
    # Memory size:1 Kb
    # Temp, op. min:-40(degree C)
    # EEPROM size:64Byte
    # Temp, op. max:85(degree C)
    # I/O lines, No. of:6
    # Memory RoHS Compliant: Yes

    2. is it possible make one firefly “master” that blinks at constant rate and other “slaves” to synchronize whit him?

    Thanks!!

    Like

  26. Dantex,
    a ATtiny13-20 would work. But it requires a higher supply voltage (2.8V compared to 1.8V).
    Having a master should be possible, but you may find out that it is harder to have slaves synchronizing with a dedicated master.
    And IMHO the synchronization of them without having a master is way cooler ;)
    Cheers,
    Alex

    Like

  27. Alex, do you have a precompiled .hex file for the project? I ordered the Atmel chips and phototransistors, then discovered the .hex was not in your .zip file.

    Very cool project!

    Like

  28. this is awesome! ive always wanted to make an LED circuit to light up my room at night.

    i was just wondering.. is it possible to modify the circuit to be powered by a USB port on my laptop?

    thanks

    Like

  29. Alex, what if you stood them on their side and arranged them in a circle? That way, the light sensors would point more directly at the light sources (of course, that might require moving the sensor so that it wasn’t directly under the ping pong ball).

    Great project, nicely executed…

    Like

  30. How do you program the AVR?

    Can someone recommend a development board and software please

    (Windows compatible)

    Nigel

    Like

  31. I have been thinking about this project being applied to a grander scale. I think it would be interesting to adapt an xbee or other wireless technology to this so that the synchronization can take place from farther away.

    You could also incorporate color change into the algorithm so that as the wireless signal strength increases the RGB led moves across a predetermined spectrum to indicate relative proximity to another unit. Its use would be similar to a homing beacon. In this way many separate units from greater distances could coalesce into one synchronous throbbing group.

    Many of these could be deployed at gatherings where there are lots of people so that a group who is together can find their mates in the crowd.

    Like

  32. Hi Qubock,
    oh, you want to go SMT? Want to share your design?
    The SFH 3710 looks like the same component with another package. It should work perfectly.
    Cheers,
    Alex

    Like

  33. Alex,

    Its been a long time since I’ve seen a firefly swarm, but if memory serves, they go in and out of sync with one another. Would there be an easy way to replicate this behavior? Perhaps putting creating a small random chance each cycle that a unit will change its flash to an arbitrary time?

    Thanks much, and keep up superb work,
    Esmaeil

    Like

  34. Alex, great project!

    How many fireflies does it take to notice the synchronizing behavior? I have three so far and they only sorta sync up. (I know the sensors are working because they all get nervous and blink green in bright light)

    I plan to build at least ten more, thats how much fun they are!

    Like

  35. Three should be enough to notice it. Maybe try a piece of cardboard to separate the fireflies to see the difference. What do you mean by “sorta”? Not in sync? Nearly in sync? Hard to see, but not in sync?
    And what are you using as diffusor?

    Like

  36. “sorta in sync” and then they drift apart. Subjectively, it seems like they drift more than I saw in your vids. No difusers yet; I’ll add some and see if that helps. Once I have my small flock of them built I hope the emergent behaviour is more obvious.

    Like

Comments are closed.