Introduction: Basics - Versatile ATTiny85 Lightning Bug

Over the past couple of years, I've been fascinated by my micro-controller hobby. So far, I've made what I consider three useful products. The first was a mailbox signal system, and then a toothbrush timer and now a "lightning bug". All of these are very simple projects and use the ATTiny85 micro-controller.

The current project is one that I came up with when I took my wife shopping. I don't do this often, believe me. Anyway, it was raining, so naturally, being the gentleman that I am, I dropped her off at the door and went to park my car. The rain stopped, and the perennial problem came up. How will she find my car in the big parking lot? Not being gentleman enough to leave the comfort of the car and actually go into the store to get her, I let her figure it out.

Then it hit me, what if I make a flashing light on the end of a stick, and poke it into the air above my car? I did exactly that and then realized that there were a lot of things that one can do with a stick that has a flashing light. So, I made a prototype, saw the potential and then came up with the current lightning bug.

Here goes.

Step 1: Tools and Materials

Tools

  • Soldering iron with clean tip
  • Flat file to keep the soldering tip clean
  • Pointed file to remove solder from grooves, in case some of the channels of the strip board are shorted out.
  • Wire stripper
  • Hemostat or long-nose pliers
  • Optional but important, anyway: Fan to remove solder fumes whenever you solder.
  • Drill bit 7/64" or 1/8" and drill, hand drill works fine. This is used to "cut" the strip on the strip board and prevent a short. You need to make four shallow holes. NOT all the way through! Just enough to sever the strips between the two sides of the micro-controller. More later.
  • Arduino Uno Programming Shield or equivalent (See this instructable for how to make a programmer for the ATTiny85 How to program ATTiny85)

Materials

  • Solder - lead free is probably best. Fumes are still present, regardless of what solder you get.
  • Strip board prototyping board. More discussion about this later. I bought mine from Tayda Electronics on eBay: Prototyping stripboard - eBay
  • Assorted hookup wire--little to none is needed for this project--I use 22 or 24 gauge. Unless you make a mistake in soldering or severing one of the copper strips in the wrong place, you will not need any wire.
  • Two CR3025 coin cells. I've been buying mine from these folks on eBay for several years already. No idea if the quality is good, but the price is. About 41 cents each. CR3025 coin cells
  • Coin cell holder. Preferably with a switch. Here is an example of what I mean: Coin Cell Battery Holder - eBay
  • 3 x 220 ohm 1/4 watt carbon resistors - available from many sources on eBay
  • RGB LED common cathode - for this project, it is important that you get the Common Cathode, because we are feeding 5 volts from the ports to the three color leads. I have no idea how you would use an RGB LED with a common anode. Here is an example of what I mean: RGB LED
  • Optional: steel wool to prepare surfaces for soldering
  • Optional: solder paste or flux. Most solder that you buy has a flux core, so this is technically not necessary.

Step 2: Prepare Prototyping Board

Tips and Hints. There are many kinds of prototyping boards out there. Some have contacts on each side of the small holes, some have a contact on only one side, some have strips of copper that connect four or five holes. The one I chose for this project has strips of copper about 1/8 wide with a channel between each pair. This allows one to avoid using a bunch of hookup wire connections. In my case, I don't use any wire except for the batteries.

It is tricky to solder components to these strips, especially if you do not have a steady hand, as in my case. You need a hot, sharp and clean iron to make the solder melt immediately and in place. If you hold the solder iron too long in one place, you will melt the copper strip right off the plastic backing. Not good.

It is also easy to make the mistake of solder melting across the channels of the strip board. In that case, there will be a short. The only way I know to correct this mistake is to take a very fine point chisel, or awl and scratch the groove open again. An alternative may be to use solder wicking ribbon and try to remove the solder that way.

One thing I do after preparing my strip board is to take my volt-ohm meter and test for shorts. I will test each pair of the IC socket and each pair of strip board channels. If there is no leakage (no short), then all is good to go.

One other tip that I strongly recommend is to use white-out typing correction fluid to mark the #1 position of the ATTiny85 chip AND the IC socket. This saves a lot of aggravation of trying to figure out the orientation of the chip on the IC socket. Those tiny indentations are sometimes hard to see. Of course, you have to use them to decide where to paint the white-out, but you'll get the idea. Soon.

Back to Business.

  1. The first thing you want to do is cut the strip board to the size you want. I measure mine by the number of perforated holes. Mine happens to be 8 holes x 8 holes. I'd suggest 9 x 9 to give a little extra leeway.
  2. Next is to drill the gaps to separate the channels or copper strips where needed. I've provided a drawing (Bottom Side - Part 1) to show how this is done. I drilled four places just enough to make the strips discontinuous. (I'd highly recommend a 7/64" bit instead of a 1/8" bit.) If this step were skipped, the pins of the IC would short out and nothing would work. There may be other ways to disrupt the continuity along a channel, but this is the easiest.
  3. The next step is to start placing the components and soldering them to the strip board. I started with the IC socket, soldered the pins into place and then soldered the leads of the resistors into their channels opposite pins 5, 6 and 7.
  4. The next step was to solder the RGB LED into place. The longest lead is the cathode. That should be soldered into the same channel as the Ground (Pin #4). I soldered the Red, Green, and Blue leads into channels of their own and then soldered the loose end of the resistors to each of those leads. You can get an idea how this looks from the Bottom Side - Part 2 picture. It shows the gap holes and the holes with solder connections.
  5. Finally, I soldered the battery socket leads. Red goes to Pin #8 and Black goes to Pin #4 (GND).
  6. Look at the picture labeled Top Side to see how the top of the bug should look.

Step 3: Schematic

This is a very simple project as electronic projects go, but I find that it is nice if a schematic is provided regardless of how simple the project is.

Step 4: Programming the ATTiny85

I will make short work of this step. There are many articles that tell how to program the ATTiny85 micro controller. Here are a couple of references: https://www.instructables.com/id/How-to-Program-ATtiny85-With-Arduino-UNO/

https://www.instructables.com/id/How-to-program-the-ATtiny85-with-the-Arduino-uno-b/.

Once you have the programming environment--Arduino Uno and a prototyping board or shield set up for the ATTiny85, you can program the chip to do a wide variety of things that require flashing LEDs. My reason for making this article was to make something that would signal my wife as to the location of our car in a large parking lot. I'll call that #1.

#1. Signal Light using the Lightning Bug. This uses three ports of the ATtiny85 to fire up the three colors of the RGB LED, namely Red, Green and Blue in a regular sequence. I didn't pay much attention to which port lit up which color, but all three colors are represented. I've attached the program I used which is called. ATTiny85SignalStick.ino. You can use this program with the Arduino programming environment which you have by now, if you set up the Arduino Uno programming setup for ATTiny85.

#2. Toothbrush Timer. This one uses two colors of the Lightning Bug. They flash as such: Five flashes to get ready, then 20 flashes to brush 1/4 segment of the mouth, another flash to signal movement of the toothbrush to another segment of the mouth and then 20 flashes until 4 sets of 20 flashes has occurred. The total time elapsed should be about two minutes. Just what the dentist ordered. The program for this is called, ATTiny85Toothbrush

Step 5: Put It All Together

Once you have programmed the ATTiny85, you are ready to pop the chip into the IC socket and pop the batteries into the battery holder and turn on the switch. You should see a sequence of Red, Green and Blue--not necessarily in that order. Soon you will know which port is handling which color, and you can simply change the program to flash the colors in whatever order you wish. If you soldered the Red lead to outPin0 (pin #5), and the Green lead to outPin1(pin #6) and the Blue lead to outPin2(pin #7), you would get Red, Green and Blue.

With RGB LEDs, you can actually combine colors and get colors other than red, green and blue. Colors made with light combine differently than colors made with color printers. For example with the LED, if you combine green and red, you should get a yellow or yellowish color. If you combine blue and red, you should see a cyan color. Google for a color wheel using "RGB additive color wheel" or something like that.

The original code looks like this, in my case the colors were :

digitalWrite(outPin0, HIGH); // Red
delay(35);
digitalWrite(outPin0, 0); // no light
delay(55);
digitalWrite(outPin1, HIGH); // Green
delay(35);
digitalWrite(outPin1, 0); // no light
delay(55);
digitalWrite(outPin2, HIGH); // Blue
delay(35);
digitalWrite(outPin2, 0); // no light
delay(55);
Now, let's change the code to make different colors:
This will give Yellow,
digitalWrite(outPin0, HIGH); // Red
digitalWrite(outPin1, HIGH); // Green
delay(35);
digitalWrite(outPin0, 0); // don't forget to turn BOTH colors off!
digitalWrite(outPin1, 0);
delay(55);
// This will give Cyan
digitalWrite(outPin1, HIGH); // Green
digitalWrite(outPin2, HIGH); // Blue
delay(35);
digitalWrite(outPin1, 0);
digitalWrite(outPin2, 0);
delay(55);
// This will give Magenta
digitalWrite(outPin2, HIGH); // Blue
digitalWrite(outPin0, HIGH); // Red
digitalWrite(outPin0, 0);
digitalWrite(outPin2, 0);
delay(55);

Step 6: Some Thoughts on Versatility

In my dreamland state, I can think of a few different uses for this gadget. I'm sure that those with more imagination can think of a lot more. Here are a few:

  1. Hot glue a bug to the end of a stick, turn it on and poke it high in the air in the parking lot when your spouse is looking for your car.
  2. Tape a bug to the door of your classroom, so your students know immediately which room you are in, in case you have to change classrooms.
  3. Change the program and use the random() function to make the colors change randomly instead of in order.
  4. Using the random() function to use the bug as a game in which the players try to guess the next color. Start with only three colors and then advance to six or more.
  5. Put the bug on the dashboard of your car, turn it on and make it easier to find your car, especially if the paint job is like all the other cars in the parking lot. My guess is that you should avoid red and blue, because the police may consider those colors proprietary to their line of work.
  6. Pin a bug on your two-year old child to keep track of him/her in the playground.
  7. When you watch TV, turn on the bug occasionally to give yourself some relief from the nonsense you are watching.
  8. Don't forget that this project only uses three of five ports. You can use two ports for analog input, if you wish. For example, you can use one for measuring light (photoresistor) and another for temperature (thermoresistor) and then code the light flashes to do whatever you want. Or, you can make them all output ports and have one RBG LED and two more colored LEDs.
  9. There is no end to what you can do with these things.

Add ideas in the comment section. I'm sure you can find many uses for this Lightning Bug
Good day and enjoy yourself!

Comments

author
WannaDuino (author)2016-11-27

is it possible to explain the attiny and those pwm, ( pulse with module)? or modulaition or monitor?

and what that can used for?

if i am correct, the pwm pinouts are only for leds?

or only DIGITAL?

i realy want to try this one, but yeah then i need to know, why i not use a flashlight instead or scream. ( thats me joking a bit) but yeah yopu get my point.

WannaDuino!!!

author
carlos66ba (author)2016-09-27

Nice project. Note that you can use PWM to produce more variety of
colors and brightness. Here is a sample code that I used for this.

// Red = 1.9 V
// Green = 2.1 V
// Blue = 3.4 V, 30 mA
// attiny85 pins: GND = leg 4, Vcc = leg 8
const int BLUEPIN = 1; // attiny85 leg 6
const int GREENPIN = 0; // attiny85 leg 5
const int REDPIN = 4; // attiny85 leg 3

void setup()
{
pinMode(REDPIN, OUTPUT); // tell Arduino REDPIN is an output
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
}

void loop()
{

int r = 12; // any number 0 to 255

int g = 12; // any number 0 to 255

int b = 12; // any number 0 to 255

analogWrite(REDPIN, r);

analogWrite(GREENPIN, g);
analogWrite(BLUEPIN, b);
delay(10);

}

author
stannickel (author)carlos66ba2016-09-28

Absolutely right. Using analogWrite() you can vary the brightness and do some really cool things with that feature. For my original purpose, I wanted to have the brightest light available so it could be seen far away. It seemed to me that digitalWrite() with HIGH and LOW was the brightest. Your code allows for a lot more variation on the theme. Thanks!

author
stannickel (author)stannickel2016-09-28

One more thing, if I am not mistaken, there are only 3 PWM ports on the chip, meaning you are limited to those ports. Those are the ones you are using. The other two can be used with digitalWrite() to allow for a total of five ports that can use LEDs in one way or the other. I like you precise assignment of voltages to each of the colors. I was not that careful. If you use those assignments, you can maximize the lifespan of the LED and maximize the efficiency as well. Again, thanks for your improvement and contribution.

author
carlos66ba (author)stannickel2016-09-28

You are right, I think only these 3 pins support hardware PWM, but you can also emulate PWM on software on the other pins if needed using timer interrupts (but it is a lot harder!).

About This Instructable

1,217views

18favorites

License:

More by stannickel:Low Cost Coffee Bean RoasterAdventures in Endodontics - Hands-free Facial Ice PackSolar Flashlight for Survival Kit
Add instructable to: