You Are Here: Home » AVR ATmega Projects » Jar of Fireflies using AVR ATTiny45 microcontroller

Jar of Fireflies using AVR ATTiny45 microcontroller




This project uses green surface-mount LED’s along with an AVR ATTiny45 microcontroller to simulate the behavior of fireflies in a jar.

(note: the firefly behavior in this video has been greatly sped up in order to be easier to represent in a short film. The default behavior has significantly more variance in its brightness and delay between plays.)

Step: 1 About this Project

About this Project

The inspiration for this project comes from having never lived in an area where fireflies were common and being deeply fascinated whenever I encounter them in my travels.

The flash patterns have been digitized from firefly behavioral research data found online and were modeled in Mathematica so that variations of speed and intensity could be generated. The final output was transformed by a lightness function and written into header files as 8-bit PWM data.

The software is written in avr-gcc C and source code is provided along with a pre-compiled .hex for convenience. The code has been significantly optimized for efficiency and to minimize power consumption. Crude runtime estimates predict a 600mAh 3V CR2450 battery should last between 4 to 10 months, depending on the song pattern used. RIght now the source comes with two patterns, song1 and song2, with song2 as default. Song2’s estimated runtime is 2 months, song1’s is 5 months.

This project involves a fair amount of surface-mount level soldering. However the circuit design is trivial and the fact that we’re able to use an off-the-shelf SMD prototyping board rather than having a custom PCB made greatly saves on cost. It would be very simple to create a non-surface mount version using the PDIP version of the ATTiny45 and through-hole LED’s.

The cost of the electronic components comes in at around $10-$15 (after shipping) or so and assembly time is on the order of 2 hours.

Step: 2 Parts

In this section I list the parts I used in the construction of this project. In many cases, the exact part is not required and a substitute will suffice. For instance, it isn’t required that you use a CR2450 battery to power the circuit, any 3V power supply will suffice and CR2450’s just happened to be the cheapest battery that I found which fit the size and capacity requirements I was looking for.

– 1 AVR ATTiny45V microcontroller, 8-pin SOIC package (DigiKey part# ATTINY45V-10SU-ND) (see note 1)
– 1 Surfboard 9081 SMD prototyping board (DigiKey part# 9081CA-ND)
– 6 Green LED’s (DigiKey Part# 160-1446-1-ND) (see note 2)
– 1 22.0K Ohm 1206 resistor (see note 3)
– 2 100 Ohm 1206 resistors (see note 2)
– 1 CR2450 battery holder (DigiKey Part# BH2430T-C-ND)
– 1 CR2450 battery (any 3V power supply will do)
– 1 spool of #38 Magnet wire (Ngineering.com Part# N5038)- 6 inches or so of bare thin wire, I used stripped wirewrapping wire but about anything will do


Notes:

#1 – The difference between an ATTiny45V and an ATTiny45 is that the ATTiny45V is spec’d to run on voltages between 1.8V – 5.5V while the ATTiny45 wants 2.7V – 5.5V. For this project, the only implication is that the ATTiny45V can possibly run for just a little bit longer as the battery dies. In reality this probably isn’t the case and the ATTiny45 can be considered interchangable with the ATTiny45V (guess which one I happened to have on-hand when I started?). Use whatever one you can get your hands on. Also, the ATTiny85 will work just fine too for a little bit more money.

#2 – Substituting a different model of LED with different current-draw characteristics will have implications on what resistor you use. See the Circuit Schematic section for more information and check the spec sheet for your LED’s.

#3 – This is only a pull-up resistor, the specific value is not important. It just needs to be ‘big enough’ without being ‘too big’. See the Circuit Schematic section for more information.


Step: 3 Tools

Tools

These are the tools I used:

Radio Shack #270-373 1-1/8″ Micro Smooth Clips
“clip-on-a-stick” – One of the Micro Smooth Clips mounted on a nail or other sort of stick.
Temperature-Regulated Soldering Iron with a fine tip (I use the Weller WD1001 digital soldering station with 65 watt iron and 0.010″ x 0.291″L micro tip). On a budget however, a 15-watt Radio Shack style soldering iron should be fine.
Helping Hands
Multimeter (for circuit testing)
Wire shears
Flux (I like the Kester Water-Soluble Flux-Pen, available at HMC Electronics (part# 2331ZXFP))
Solder (the thinner the better)
Tweezers
Exacto Knife / Razor blade

Step: 4 Circuit Board Assembly – Part 1 of 3

Preparing the circuitboard and attaching the resistors –

Flux the pads –

I tend to flux everything, even when using solder that already contains flux. This is especially true when I’m using the water-soluable flux-pen since cleanup is so easy and the pen makes it easy to not get flux everywhere.

Solder jumper wire across pads as illustrated –

The consequence of not having our own PCB made for this project is that we have to add our own bus wires. Also note the bus wires on PIN_C, PIN_D, and PIN_E. These are not strictly necessary but it looks cleaner this way and also gives us some elbowroom when attaching a clip to the microprocessor for programming.

Solder resistors to the board –

There are a number of good guides on the internet with examples of how to solder surface mount components. In general, you want to start by puting a little bit of solder on one pad. Holding the component in a pair of tweezers, heat the solder and hold one side of the component in the solder until it flows onto the pin. You want to keep the component flush with the board while you’re doing this. Then, solder the other side. See the pic.

Step: 5 Circuit Board Assembly – Part 2 of 3

Soldering the microcontroller to the board –

Bend pins on the microcontroller –

Another consequence of not having our own PCB made is that we have to deal with the unusual width of the ATTiny45 chip which happens to be slightly wider than will comfortably fit on the Surfboard. The simple solution is to bend the pins inwards so that the chip stands on the pads instead of sitting on them.

Solder microcontroller to board –

Again, there are many SMD soldering guides out there but the executive summary is this:

– Flux the pins of the chip (I find this makes it *much* easier to get a good solder joint, especially with the weird surface topology of these bent pins)
– Hold the chip to the pad and draw solder down from the square pad and onto the first pin of the chip (add more solder if there isn’t enough on the square pad but you’ll typically have enough already).
– Make sure that the solder actually flows up and *onto* the pin. The soldering motion is sort of like “pushing” the solder onto the pin.
– Once the first pin is soldered, go to the pin on the opposite corner of the chip and solder that down as well. Once those two corners are tacked down, the chip should remain firmly in place and the remaining pins become simple to complete.

Also, be very careful that you solder the chip to the board in the correct orientation! If you look closely on the chip you’ll see a little round indentation on the top in one of the corners. That indentation marks pin #1 which I’ve otherwise marked as the “reset’ pin on the chip (see diagram). If you solder it down in the wrong orientation, I promise you that it won’t work ;)Soldering the microcontroller to the board –

Bend pins on the microcontroller –

Another consequence of not having our own PCB made is that we have to deal with the unusual width of the ATTiny45 chip which happens to be slightly wider than will comfortably fit on the Surfboard. The simple solution is to bend the pins inwards so that the chip stands on the pads instead of sitting on them.

Solder microcontroller to board –

Again, there are many SMD soldering guides out there but the executive summary is this:

– Flux the pins of the chip (I find this makes it *much* easier to get a good solder joint, especially with the weird surface topology of these bent pins)
– Hold the chip to the pad and draw solder down from the square pad and onto the first pin of the chip (add more solder if there isn’t enough on the square pad but you’ll typically have enough already).
– Make sure that the solder actually flows up and *onto* the pin. The soldering motion is sort of like “pushing” the solder onto the pin.
– Once the first pin is soldered, go to the pin on the opposite corner of the chip and solder that down as well. Once those two corners are tacked down, the chip should remain firmly in place and the remaining pins become simple to complete.

Also, be very careful that you solder the chip to the board in the correct orientation! If you look closely on the chip you’ll see a little round indentation on the top in one of the corners. That indentation marks pin #1 which I’ve otherwise marked as the “reset’ pin on the chip (see diagram). If you solder it down in the wrong orientation, I promise you that it won’t work 😉

For more detail: Jar of Fireflies using AVR ATTiny45 microcontroller

Leave a Comment

You must be logged in to post a comment.

Read previous post:
Music Playing Alarm Clock using ATmega644 microcontroller

This Instructable will be about designing a music player from using various building blocks. You will understand the communication between...

Close
Scroll to top