The Arduino Christmas tree

Ever since I saw this How-To: Shrinkify Your Arduino Projects I wanted to do a project using Arduino Attiny85s. And because I want to bring my son into the world of Arduino and he was eager to learn how to solder I was thinking of an easy project. With Christmas being around the corner I wanted to do some kind of a blinking Christmas tree.

The Attiny85 has 5 pins to use so I thought it would be cool to hook up a shift register to blink some LEDs. First thing I did was buying Attiny85s and 8-Bit Shift Register (SN74HC595N) on ebay. 10 pcs of Attiny85 cost me 12 USD and 10 shift registers were 2.50 USD.

The idea was to control 8 LEDs with the shift register. That would use up 3 pins on the Attiny85… so this left me with 2 more pins. I decided to use them kind of doing multiplexing LEDs. So I could hook up 2 LEDs per shift register output but they would not share the same connection to ground. This was controlled by two transistors that are connected to the two remaining pins on the arduino.

So here’s the schema:
xmas breadboard

I read the Arduino Shift Register Tutorial on how to hook up the arduino.

Then I did the programming:

//Pin connected to ST_CP of 74HC595
int latchPin = 0;
//Pin connected to SH_CP of 74HC595
int clockPin = 1;
////Pin connected to DS of 74HC595
int dataPin = 2;

// to select which cathode to use
int row0 = 3;
int row1 = 4;

// variable to display via shift register
int numberToDisplay = 0;

void setup() {
  //set pins to output so you can control the shift register
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);

  pinMode(row0, OUTPUT);
  pinMode(row1, OUTPUT);

void loop() {

  // take a random number
  numberToDisplay = random(100,256);

  digitalWrite(row0, LOW);
  digitalWrite(row1, LOW);

  // choose randomly which of both rows set to gnd
  if (numberToDisplay%2 == 0)
    digitalWrite(row1, HIGH);
    digitalWrite(row0, HIGH);

  // take the latchPin low so 
  // the LEDs don't change while you're sending in bits:
  digitalWrite(latchPin, LOW);
  // shift out the bits:
  shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);  

  //take the latch pin high so the LEDs will light up:
  digitalWrite(latchPin, HIGH);

  // pause before next value:

So what this does is just getting a random number between 100 and 255 every 300ms and writes it out to the shift register. Depending if the random number is even or odd one or the other row of LEDs gets connected to ground through the transistor.

To upload the code to the Attiny I used my Arduino Uno as an ISP as described here.

Arduino Uno as a programmer for Attiny85

Arduino Uno as a programmer for Attiny85

Christmas tree control

Christmas tree control

Testing the circuit

Testing the circuit

Front view - Painted by my baby

Front view – Painted by my baby

Back View

Back View

Attiny85 circuit

Attiny85 circuit. Powered by a 9V battery.

In Action 1

In Action 1

In Action 2

In Action 2

2 thoughts on “The Arduino Christmas tree

  1. Pingback: Cash register for kids with Arduino | Hacking – DIY and Coding

  2. Hahaha! nice work! I have a bunch of those attiny85, but it works out to be better just to get the actually atmega328 here in my country, only another $2 per chip. 🙁 Great use of one of those chips, they are really fun to play with.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.