Introduction: 3 Easy ATTiny Holiday Gifts

 Every year the holiday season rolls around and I get stuck on what to give for my friends and family.  People always say that it's better to make the gift yourself than buy it at a store so this year I did just that.  The first displays a name or basic image when waved through the air, the second fades smoothly between two white led's (It also has a safety pin to attach it to clothes or a purse), and the third is a mood light of sorts, scrolling seamlessly between colors. All are under $15 and are easy to assemble in less than an hour.  You could also give these instructions as well as parts as a gift to someone interested in learning electronics.

Note:  A basic level of soldering is assumed.  However, unlike my previous instructable I will glossover how to program an AVR.  I really hope that this helps people who are trying to get started in electronics.  I remember when I was there and will be happy to take any questions you may have.  Remember there are no stupid questions!  I have left it open to you to determine how you will lay out your circuit board in hopes that you will come up with a new way of displaying the simple circuits I have drawn out.  Please post pictures once you are done, I can't wait to see what you come up with!

Parts for All of the Projects
N = number of projects

xN ATTiny45 (www.digikey.com)
xN 8-pin DIP socket (RadioShack)
x 1  Large Perf Board (I got mine at RadioShack)
xN 3v Coin CellBattery and holder (RadioShack)
x1 Programmer (I use this and the supplied makefile will be configured to use this one)
x2N Resistors, one 10 ohm and one 10k ohm (RadioShack)


Here's a picture of the three completed projects:

Step 1: The Name Flasher

Other Parts

x5 DIFFUSED 3mm LED's (RadioShack)

This project uses persistence of vision to display an image or text when moved rapidly.  It works better when it's dark.  With the AVR we are switching between LED's faster then the eye can see we can create a picture in the air with very few components.

The Code:  (Download the .zip file at the bottom of the page for the code, makefile, etc. (That code does not have the extensive comments that this code does but if this code doesn't work, try the one in the zip file))

#define F_CPU 1000000
#include
#include
void dispClear()
{
  PORTB = ~0b00000000;
}
int main()
{
  DDRB = 0xFF; //For those of you who have never read C before the double slash indicates a comment.  This sets the pins of the avr as an output
  char x = 10;  //x is used to set the delay legnth.  Increasing the value give a slower switch between pixels, decreasing, a lower
  while(1)  //While(condition is true); {Do This}  (True in C is 1)
    {
      PORTB = ~0b00010001;  //My friend's name is Zoe so I drew out the characters on graph paper and then imputed them into PORTB.  The first three zeros don't matter because there are only five led's connected.  A one in one of the remaining five spaces indicates that the LED is on, a zero, off.
      _delay_ms(x);  //delay in miliseconds
      PORTB = ~0b00010011;
      _delay_ms(x);
      PORTB = ~0b00010101;
      _delay_ms(x);
      PORTB = ~0b00011001;
      _delay_ms(x);
      PORTB = ~0b00010001;
      _delay_ms(x);
      dispClear();  //Open space between characters
      _delay_ms(x);
      PORTB = ~0b00001110;
      _delay_ms(x);
      PORTB = ~0b00010001;
      _delay_ms(x*3);
      PORTB = ~0b00001110;
      _delay_ms(x);
      dispClear();
      _delay_ms(x);
      PORTB = ~0b00011111;
      _delay_ms(x);
      PORTB = ~0b00010101;
      _delay_ms(x);
      PORTB = ~0b00010001;
      _delay_ms(x);
      dispClear();
      _delay_ms(x*5);  //The word is done so for clairity I have a bigger space between words
    }
}

Now follow the instructions on page 4 to compile this code and send it to your AVR.

Step 2: The Purse Light

Other Parts

x2 LED's NON DIFFUSED (RadioShack)

This project fades smoothly between two LED's.  My mom wanted something to go on her purse to help her bee seen at night.  I felt like a flashing bike light would draw too much attention so I made this.



It uses PWM (Pulse Width Modulation) to give the effect of dimming and brightening.  What is actually happening is the led is flashing faster than the eye can see at varying intervals to simulate a change.  You can see this more clearly when you wave it in of your face as you would with the Name Flasher.  The code can be downloaded at the end of this page.  See page 4 on how to compile to your AVR.

Instead of commenting the code here I'll briefly explain the concept.  PWM is generated by a timer.  Each clock cycle the timer counts up one.  When it reaches a certain value (In this case OCR1B) it changes the state of a pin (In this case OC1B).  To get the LED's to "switch off" I wired the other one to [OPPOSITE]OC1B (That's what the bar across the top means).  Then we use x to increment and decrement the amount of time for the LED's to be on.

Step 3: The Color Scroller

Other Parts

x1 RGB LED (diffused is better) (RadioShack)

This to me is a classic.  I have always been fasinated by lights like this and find them very calming so naturally I wanted to make one.  Also their visibility in society gives them a real WOW factor.  "You MADE that?!" 



The code is nearly the same and, in my opinion, easier to read.  You can download the at the bottom.  This time we provide a PWM'd pin for each grounding pin on the RGB LED.  In this way we ground through the chip.  Volts can be measured as the difference between two points.  
3v-0v=3v
5v-2v=3v
***3v-3v=0v***
This last instance is what we are doing when we ground through the chip.  When there are three volts on both sides, per say, there are not enough volts to drive a LED.  So to fade between colors we chose a color and another color.  Set one equal to x and the other equal to 255-x or the INVERSE of x.  Like we were doing in the previous project.  Now go to step 4 to program.

Step 4: Programing

 First download and install Emacs, avr-gcc, and Avrdude and any dependancies they might have.  On Arch linux I did this with: sudo pacman -Sy emacs avrdude

Now it's time to hook up your programmer to your avr.  Wire the pins on the 6-pin ISP programmer (picture below) to the corosponding pins on your AVR (Datasheet, page 2)(I did this on a breadboard).  Now plug in the programmer to your computer and VERY QUICKLY touch the top of the AVR.  If it is hot, REMOVE THE PROGRAMMER FROM YOUR COMPUTER AT ONCE check your connections and try again (Power and Gnd backwards?).  If it is not hot then open emacs and press Ctl-x Ctl-f to find the .c file.  Open it and then press Meta(Usualy  Alt)-x and type compile.  Press enter twice and if you are lucky your AVR should now be running your code!

Thanks for reading!  I hope you enjoyed it and learned something.  Please, don't hesitate to ask questions and don't forget to post pics of what you come up with.  Happy holidays and don't forget to vote!

Homemade Holidays Contest

Participated in the
Homemade Holidays Contest