Project tutorial
The 12. Birthday - Project 12

The 12. Birthday - Project 12 © GPL3+

The next round in my birthday table decoration challenge.

  • 519 views
  • 0 comments
  • 3 respects

Components and supplies

Necessary tools and machines

Hy gluegun
Hot glue gun (generic)

Apps and online services

About this project

Another year is over and the preparation for the next birthday is running. This time, a bit more movement should come into the table decoration.

For the history of this article you should look at the Project 11 briefly. The implementation of the 11 was fun. This year, I wanted to put some movement on the table. And there's another birthday girl's request: it must have something to do with Harry Potter!

With the keywords Movement and Harry Potter my first idea was the Weasley's house clock, which shows when a Weasley is at home.

Concept

I wanted to implement that so that instead of the persons, the numbers 1 and 2 appear. At the beginning the two numbers are invisible in the box. After switching on they fold out and make a few movements.

The numbers 1 and 2 for the "12" get the look of the font of Harry Potter.

Hardware

I've glued the box together out of 4 wooden strips - sawn miter - together. The movement of numbers is done by servos. The installation was very simple in this case. They were only glued to the inside wall of the box with hot glue.

The numbers and 1 and 2 are sawed out of plywood and glued to the usually included arms of the servos.

As a microcontroller, I chose an Arduino Nano. The power comes through a small power bank. Both fit quite well in the box and also holds a party long.

Software

So that the noise level of the servo's does not bother permanently, the "12" should stay in the end position for a while. My simple servo's produces a little noise anyhow. That's why they will be turned off, if they stay longer in one position.

There are two voids for this: ServosOn() and ServosOff().

void ServosOn() {   
  servo1.attach(PinServo1);    
  servo2.attach(PinServo2); 
} 
void ServosOff() {   
  servo1.detach();    
  servo2.detach(); 
} 

A servo is easily moved via a write command. For this I have defined two limit values top / bottom.

int PosBottom=12;
int PosTop=89; 
servo2.write(PosBottom);
delay(5000);
servo2.write(PosTop); 

For a little more Harry Potter feeling, each number has been enhanced with its own RGB LED. So a few colorful flash effects can be installed when they appear or disappear.

void Blink12(int r, int g, int b, int dauer1,  int dauer2) { 
  Led1(r,g,b);   
  Led2(r,g,b);   
  delay(dauer1);   
  Led1(LOW,LOW,LOW);   
  Led2(LOW,LOW,LOW);   
  delay(dauer2); 
} 

As a color for the box, I chose black. That was already pretty dark. Therefore came on the front again 6 more LEDs. Each 2 of them are controlled by a pin.

For the LEDs I use a running light effect.

void RunningLight() {   
  for (int i=0; i<4; i=i+1){     
    digitalWrite(PinLed1, HIGH);     
    digitalWrite(PinLed2, LOW);
    digitalWrite(PinLed3, LOW);
    delay(200);
    digitalWrite(PinLed1, LOW);
    digitalWrite(PinLed2, HIGH);
    digitalWrite(PinLed3, LOW);
    delay(200);
    digitalWrite(PinLed1, LOW);
    digitalWrite(PinLed2, LOW);
    digitalWrite(PinLed3, HIGH);
    delay(200);
   }     
  digitalWrite(PinLed3, LOW); 
} 

Result

To the two servo's 1 and 2 came another with a sign "Congratulations". You find some impressions in the Youtube video.

So Happy Birthday!

PS: Wenn Sie diesen Artikel in deutsch lesen möchten, schauen Sie doch auf techpluscode.de

Code

Arduino Source Code for the 12 animationArduino
//Project 12


// Integrate libraries
#include <Servo.h>


Servo servo1;
Servo servo2;
Servo servo3;

int PinLed1=2;
int PinLed2=3;
int PinLed3=4;
int PinServo1=8;
int PinServo2=12;
int PinServo3=10;

int PinLed2G=A1;
int PinLed2B=A2;
int PinLed2R=A3;
int PinLed1G=A4;
int PinLed1B=A5;
int PinLed1R=A0;

int PosBottom=12;
int PosTop=89;



void setup() {
  servo1.attach(PinServo1); 
  servo2.attach(PinServo2); 
  servo3.attach(PinServo3); 
  pinMode(PinLed1, OUTPUT);
  pinMode(PinLed2, OUTPUT);
  pinMode(PinLed3, OUTPUT);

  pinMode(PinLed1R, OUTPUT);
  pinMode(PinLed1G, OUTPUT);
  pinMode(PinLed1B, OUTPUT);

  pinMode(PinLed2R, OUTPUT);
  pinMode(PinLed2G, OUTPUT);
  pinMode(PinLed2B, OUTPUT);
}


void Led1(boolean r, boolean g, boolean b) {
  digitalWrite(PinLed1R, r);
  digitalWrite(PinLed1G, g);
  digitalWrite(PinLed1B, b);
}

void Led2(boolean r, boolean g, boolean b) {
  digitalWrite(PinLed2R, r);
  digitalWrite(PinLed2G, g);
  digitalWrite(PinLed2B, b);
}


void Move1(int pos) {
  servo1.attach(PinServo1); 
  servo1.write(pos);
  delay(1000);
  servo1.detach();
}

void ServosOn() {
  servo1.attach(PinServo1); 
  servo2.attach(PinServo2); 
  servo3.attach(PinServo3); 
}

void ServosOff() {
  servo1.detach(); 
  servo2.detach(); 
  servo3.detach(); 
}


void Blink12(int r, int g, int b, int dauer1,  int dauer2) {
  //Led1 and 2 goes on an off
  Led1(r,g,b);
  Led2(r,g,b);
  delay(dauer1);
  Led1(LOW,LOW,LOW);
  Led2(LOW,LOW,LOW);
  delay(dauer2);

}

void RunningLight() {
  for (int i=0; i<4; i=i+1){
    digitalWrite(PinLed1, HIGH);
    digitalWrite(PinLed2, LOW);
    digitalWrite(PinLed3, LOW);
    delay(200);
    digitalWrite(PinLed1, LOW);
    digitalWrite(PinLed2, HIGH);
    digitalWrite(PinLed3, LOW);
    delay(200);
    digitalWrite(PinLed1, LOW);
    digitalWrite(PinLed2, LOW);
    digitalWrite(PinLed3, HIGH);
    delay(200);
    }
    digitalWrite(PinLed3, LOW);
}  

void loop() {

  //Lights off
  //all elements down
  ServosOff();

  
  Led1(LOW,LOW,LOW);
  Led2(LOW,LOW,LOW);
  servo1.write(PosBottom);
  delay(50);
  servo2.write(PosBottom);
 


  for (int i=0; i<3; i=i+1){
    servo3.write(PosBottom);
    Blink12(HIGH,LOW,LOW,200,50);
    Blink12(HIGH,HIGH,LOW,200,50);
    Blink12(HIGH,LOW,LOW,200,50);
    servo3.write(PosTop);
    Blink12(HIGH,HIGH,LOW,200,50);
    Blink12(HIGH,LOW,LOW,200,50);
    Blink12(HIGH,HIGH,LOW,200,50);
  }

  RunningLight();
  
  digitalWrite(PinLed1, HIGH);
  digitalWrite(PinLed2, HIGH);
  digitalWrite(PinLed3, HIGH);

  delay(2000);
  
  //Led1 and 2 flash briefly
  for (int i=0; i<6; i=i+1){
    Blink12(HIGH,HIGH,HIGH,100,50);
  }
  
  //2 to top
  servo2.write(PosTop);
  delay(1000);
  
  //Led1 and 2 flash briefly
  for (int i=0; i<6; i=i+1){
    Blink12(HIGH,HIGH,HIGH,100,50);
  }
  
  //1 to top
  servo1.write(PosTop);
  delay(1000);


  //1 and 2 to bottom and top again
  servo1.write(PosBottom);
  servo2.write(PosBottom);
  delay(1000);
  servo1.write(PosTop);
  servo2.write(PosTop);
  delay(1000);
  ServosOff();
  
  //Led1 and 2 flash briefly
  for (int i=0; i<6; i=i+1){
    Blink12(HIGH,HIGH,HIGH,100,50);
  }

  digitalWrite(PinLed1, LOW);
  digitalWrite(PinLed2, LOW);
  digitalWrite(PinLed3, LOW);
  
  //Colorchanges
  for (int i=0; i<2; i=i+1){
    for (int j=0; j<2; j=j+1){
      for (int k=0; k<2; k=k+1){
        Led1(i,j,k);
        Led2(k,i,j);
        delay(500);
        Led1(j,i,k);
        Led2(k,j,i);
        delay(500);
      }
    }
  }  

  //Led1 and 2 flash briefly
  for (int i=0; i<6; i=i+1){
    Blink12(HIGH,HIGH,HIGH,100,50);
  }
  
  delay(1000);
  RunningLight();


  delay(8000);
  
  ServosOff();
  servo1.write(PosBottom);
  servo2.write(PosBottom);
  delay(2000);

  //flash yellow
  for (int i=0; i<5; i=i+1){
    Blink12(HIGH,LOW,HIGH,100,100);
  }
  
  servo3.write(PosBottom);
  delay(1000);
  ServosOff();
  RunningLight();
  delay(8000);


}

Comments

Similar projects you might like

Happy Birthday Melody On Arduino Nano With 3-way Polyphony

Project tutorial by Liss

  • 10,954 views
  • 8 comments
  • 45 respects

Birthday Alarm That'll Run for 50 Years

Project tutorial by Vishnu M Aiea

  • 8,424 views
  • 11 comments
  • 33 respects

Little Rover

Project tutorial by Jeremie

  • 3,847 views
  • 3 comments
  • 16 respects

Otto DIY+ Arduino Bluetooth Robot Easy to 3D Print

Project tutorial by Team Otto builders

  • 48,258 views
  • 117 comments
  • 162 respects

OttoDIY Build Your Own Robot in One Hour!

Project tutorial by Camilo Parra Palacio

  • 104,245 views
  • 128 comments
  • 296 respects
Add projectSign up / Login