Project tutorial
Homemade Christmas Project

Homemade Christmas Project © GPL3+

Ultrasonic sensor will start Arduino playing Christmas songs while lights blink and a servo motor moves Santa Claus.

  • 535 views
  • 3 comments
  • 7 respects

Components and supplies

Apps and online services

About this project

A BRIEF EXPLANATION

As you can see in the video below, my arduino project starts in standby mode and the ultrasonic sensor is off. In the display the written hint recommends you to push the button to start. Then if you put something near the ultrasonic at a distance of less than 10 centimeters this will happen:

  • Songs play (3 different songs: Jingle Bells - We wish you a merry christmas - Santa claus is coming to town)
  • Lights blink (random function)
  • Servo motor moves (put a santa claus on it)
  • Christmas greetings are repeated on the display in 5 different languages

If you take off what you have put near the ultrasonic sensor, Arduino will stop.

Therefore if you want to put it into standby mode (ultrasonic senso off) than push the button.

CODE REVIEW

Array for the three christmas songs
 int canzoni [6][50]={{
 // Jingle Bells
 NOTE_E5, NOTE_E5, NOTE_E5,
 NOTE_E5, NOTE_E5, NOTE_E5,
 NOTE_E5, NOTE_G5, NOTE_C5, NOTE_D5,
 NOTE_E5,
 NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5,
 NOTE_F5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5,
 NOTE_E5, NOTE_D5, NOTE_D5, NOTE_E5,
 NOTE_D5, NOTE_G5
},{
 8, 8, 4,
 8, 8, 4,
 8, 8, 8, 8,
 2,
 8, 8, 8, 8,
 8, 8, 8, 16, 16,
 8, 8, 8, 8,
 4, 4
},{
 // We wish you a merry Christmas
 NOTE_B3, 
 NOTE_F4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4,
 NOTE_D4, NOTE_D4, NOTE_D4,
 NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_F4,
 NOTE_E4, NOTE_E4, NOTE_E4,
 NOTE_A4, NOTE_A4, NOTE_B4, NOTE_A4, NOTE_G4,
 NOTE_F4, NOTE_D4, NOTE_B3, NOTE_B3,
 NOTE_D4, NOTE_G4, NOTE_E4,
 NOTE_F4
},{
 4,
 4, 8, 8, 8, 8,
 4, 4, 4,
 4, 8, 8, 8, 8,
 4, 4, 4,
 4, 8, 8, 8, 8,
 4, 4, 8, 8,
 4, 4, 4,
 2
},{
 // Santa Claus is coming to town
 NOTE_G4,
 NOTE_E4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_G4,
 NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, NOTE_C5,
 NOTE_E4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_G4,
 NOTE_A4, NOTE_G4, NOTE_F4, NOTE_F4,
 NOTE_E4, NOTE_G4, NOTE_C4, NOTE_E4,
 NOTE_D4, NOTE_F4, NOTE_B3,
 NOTE_C4
},{
 8,
 8, 8, 4, 4, 4,
 8, 8, 4, 4, 4,
 8, 8, 4, 4, 4,
 8, 8, 4, 2,
 4, 4, 4, 4,
 4, 2, 4,
 1
}};
At first, until the button isn't pushed lettura == LOW and ultrasonic is off. If the button is pushed than we escape the while statement and ultrasonic is on.
while(lettura == LOW){
    lettura = digitalRead(pulsantePin);
    if(lettura == HIGH){
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("Arduino project");
   lcd.setCursor(0, 1);
   lcd.print("Andrea Magnante");
    delay(2000);
    }
   } 
Ultrasonic sensor check if there is something near it and an if-else statement decides what happens
long duration, distance;
 digitalWrite(trigPin, LOW);  
 delayMicroseconds(2); 
 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10); 
 digitalWrite(trigPin, LOW);
 duration = pulseIn(echoPin, HIGH);
 distance = (duration/2) / 29.1;
 if (distance < 10) {  
   illumina();
   suona();
 }
 else {
  digitalWrite(led[0], HIGH);
 } 
When we put something near the ultrasonic sensor arduino calls illumina() and suona() functions
void illumina(){                      // wait for 1/2 a second
 digitalWrite(led[0], LOW);    // turn the LED off by making the voltage LOW
 digitalWrite(led[1], HIGH);    // turn the LED on (HIGH is the voltage level)
 delay(150);                      // wait for 1/2 a second
 digitalWrite(led[1], LOW);     // turn the LED off by making the voltage LOW
 digitalWrite(led[2], HIGH);     // turn the LED on (HIGH is the voltage level)
 delay(150);                      // wait for 1/2 a second
 digitalWrite(led[2], LOW);      // turn the LED off by making the voltage LOW
 digitalWrite(led[3], HIGH);     // turn the LED on (HIGH is the voltage level)
 delay(150);                      // wait for 1/2 a second
 digitalWrite(led[3], LOW);      // turn the LED off by making the voltage LOW
 digitalWrite(led[2], HIGH);      // turn the LED off by making the voltage LOW
 delay(150); 
 digitalWrite(led[2], LOW);      // turn the LED off by making the voltage LOW
 digitalWrite(led[1], HIGH);      // turn the LED off by making the voltage LOW
 delay(150); 
 digitalWrite(led[1], LOW);      // turn the LED off by making the voltage LOW
 digitalWrite(led[0], HIGH);      // turn the LED off by making the voltage LOW
 delay(150);   
}
void suona(){
 lcd.clear();
 int pos = 180;
 int m = 0;
 int n = 0;
 int z = 0;
 int pari;
 if(ripetizione==6){
    pari = 0;
 }
 else if(ripetizione==0){
   pari = 4;
 }
 else if(ripetizione==4){
   pari = 2;
 }
 int dispari= pari+1;
 lcd.setCursor(0, 1);
 lcd.print("To you all"); 
 for(int i = 0; i < numeroNote; i++){
   lcd.setCursor(0, 0);
   lcd.print(messaggi[z]);
   delay(80);
   digitalWrite(led[m],LOW);
   digitalWrite(led[n],LOW);
   m = random(0,4);
   n = random(0,4);
   int durata = 1500 / canzoni[dispari][i];
   tone(buzzerPin, canzoni[pari][i], durata); 
   digitalWrite(led[m],HIGH);
   digitalWrite(led[n],HIGH);
   delay(durata * 1.3);
   myservo.write(pos);
   pos = pos -7;
   z++;
   if(z==5){
     z=0;
   }
}
 ripetizione = pari;
 digitalWrite(led[m],LOW);
 digitalWrite(led[n],LOW);
   lcd.clear();
   lcd.setCursor(0, 0);
   lcd.print("Arduino project");
   lcd.setCursor(0, 1);
   lcd.print("Andrea Magnante");
}
If we push the button after playing songs then arduino enter into standby mode
if(pulsanteStato == HIGH){
    lettura = LOW;
    digitalWrite(led[0],LOW);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Welcome :)");
    lcd.setCursor(0, 1);
    lcd.print("Push the button!");
    delay(2000);
 }

VIDEO

Check the project's test video!

CREDITS

Do you like my idea?

Try to do that if you want to have fun with an arduino christmas project and click respect if you like it! :)

πŸŽ‰πŸŽ… Merry christmas, everyone! πŸŽ„πŸŽ

Code

Christmas codeC/C++
#include "pitches.h"
#include <LiquidCrystal.h>
#include <Servo.h>

int pulsantePin = 7;
int pulsanteStato;
int attesaDebounce = 50;
unsigned long ultimoTempoDebounce = 0;
int ultimaLettura = LOW;
int ripetizione = 6;
int buzzerPin = 11;
int canzoni [6][50]={{
  // Jingle Bells
  NOTE_E5, NOTE_E5, NOTE_E5,
  NOTE_E5, NOTE_E5, NOTE_E5,
  NOTE_E5, NOTE_G5, NOTE_C5, NOTE_D5,
  NOTE_E5,
  NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5,
  NOTE_F5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5,
  NOTE_E5, NOTE_D5, NOTE_D5, NOTE_E5,
  NOTE_D5, NOTE_G5
},{
  8, 8, 4,
  8, 8, 4,
  8, 8, 8, 8,
  2,
  8, 8, 8, 8,
  8, 8, 8, 16, 16,
  8, 8, 8, 8,
  4, 4
},{
  // We wish you a merry Christmas
  NOTE_B3, 
  NOTE_F4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4,
  NOTE_D4, NOTE_D4, NOTE_D4,
  NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_F4,
  NOTE_E4, NOTE_E4, NOTE_E4,
  NOTE_A4, NOTE_A4, NOTE_B4, NOTE_A4, NOTE_G4,
  NOTE_F4, NOTE_D4, NOTE_B3, NOTE_B3,
  NOTE_D4, NOTE_G4, NOTE_E4,
  NOTE_F4
},{
  4,
  4, 8, 8, 8, 8,
  4, 4, 4,
  4, 8, 8, 8, 8,
  4, 4, 4,
  4, 8, 8, 8, 8,
  4, 4, 8, 8,
  4, 4, 4,
  2
},{
  // Santa Claus is coming to town
  NOTE_G4,
  NOTE_E4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_G4,
  NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, NOTE_C5,
  NOTE_E4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_G4,
  NOTE_A4, NOTE_G4, NOTE_F4, NOTE_F4,
  NOTE_E4, NOTE_G4, NOTE_C4, NOTE_E4,
  NOTE_D4, NOTE_F4, NOTE_B3,
  NOTE_C4
},{
  8,
  8, 8, 4, 4, 4,
  8, 8, 4, 4, 4,
  8, 8, 4, 4, 4,
  8, 8, 4, 2,
  4, 4, 4, 4,
  4, 2, 4,
  1
}};


LiquidCrystal lcd(14, 15, 16, 17, 18, 19);

String messaggi[] = {
  "Merry Christmas",
  "Buon Natale",
  "Joyeux Noel",
  "Shub Naya Baras",
  "Feliz Navidad"
};

int numeroNote = 26;
#define trigPin 13
#define echoPin 12
int led[] = {2,3,4,5};
int lettura = LOW;
 
Servo myservo;
 
int pos = 0;
int w = 0;

// the setup routine runs once when you press reset:
void setup() { 
  pinMode(pulsantePin, INPUT);
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Welcome :)");
  lcd.setCursor(0, 1);
  lcd.print("Push the button!");
  myservo.attach(8);
  pinMode(buzzerPin, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  for(int x = 0; x<4; x++){
  pinMode(led[x], OUTPUT);   
  } 
}

// the loop routine runs over and over again forever:
void loop() {
    while(lettura == LOW){
     lettura = digitalRead(pulsantePin);
     if(lettura == HIGH){
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Arduino project");
    lcd.setCursor(0, 1);
    lcd.print("Andrea Magnante");
     delay(2000);
     }
    }
   
  long duration, distance;
  digitalWrite(trigPin, LOW);  
  delayMicroseconds(2); 
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); 
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance < 10) {  
    illumina();
    suona();
  }
  else {
   digitalWrite(led[0], HIGH);
  }
  if (distance >= 400 || distance <= 0){    
    Serial.println("Out of range");
  }
  else {
    Serial.print(distance);
    Serial.println(" cm"); //in centimeters
  }
  pulsanteStato = digitalRead(pulsantePin);
  
  if(pulsanteStato == HIGH){
     lettura = LOW;
     digitalWrite(led[0],LOW);
     lcd.clear();
     lcd.setCursor(0, 0);
     lcd.print("Welcome :)");
     lcd.setCursor(0, 1);
     lcd.print("Push the button!");
     delay(2000);
  }
  
  
}

void illumina(){                      // wait for 1/2 a second
  digitalWrite(led[0], LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(led[1], HIGH);    // turn the LED on (HIGH is the voltage level)
  delay(150);                      // wait for 1/2 a second
  digitalWrite(led[1], LOW);     // turn the LED off by making the voltage LOW
  digitalWrite(led[2], HIGH);     // turn the LED on (HIGH is the voltage level)
  delay(150);                      // wait for 1/2 a second
  digitalWrite(led[2], LOW);      // turn the LED off by making the voltage LOW
  digitalWrite(led[3], HIGH);     // turn the LED on (HIGH is the voltage level)
  delay(150);                      // wait for 1/2 a second
  digitalWrite(led[3], LOW);      // turn the LED off by making the voltage LOW
  digitalWrite(led[2], HIGH);      // turn the LED off by making the voltage LOW
  delay(150); 
  digitalWrite(led[2], LOW);      // turn the LED off by making the voltage LOW
  digitalWrite(led[1], HIGH);      // turn the LED off by making the voltage LOW
  delay(150); 
  digitalWrite(led[1], LOW);      // turn the LED off by making the voltage LOW
  digitalWrite(led[0], HIGH);      // turn the LED off by making the voltage LOW
  delay(150);   
}

void suona(){
  lcd.clear();
  int pos = 180;
  int m = 0;
  int n = 0;
  int z = 0;
  int pari;
  if(ripetizione==6 || ripetizione == 2){
     pari = 0;
  }
  else if(ripetizione==0){
    pari = 4;
  }
  else if(ripetizione==4){
    pari = 2;
  }
  
  int dispari= pari+1;
  lcd.setCursor(0, 1);
  lcd.print("To you all"); 
  for(int i = 0; i < numeroNote; i++){
    
    lcd.setCursor(0, 0);
    lcd.print(messaggi[z]);
    delay(80);
    digitalWrite(led[m],LOW);
    digitalWrite(led[n],LOW);
    m = random(0,4);
    n = random(0,4);
    int durata = 1500 / canzoni[dispari][i];
    tone(buzzerPin, canzoni[pari][i], durata); 
    digitalWrite(led[m],HIGH);
    digitalWrite(led[n],HIGH);
    delay(durata * 1.3);
    myservo.write(pos);
    pos = pos -7;
    z++;
    if(z==5){
      z=0;
    }
 }
  ripetizione = pari;
  digitalWrite(led[m],LOW);
  digitalWrite(led[n],LOW);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Arduino project");
    lcd.setCursor(0, 1);
    lcd.print("Andrea Magnante");
   
}

Schematics

Arduino project
Below there is a zoom of all components used and how they are connected.
Arduinoproject bb myohwxirmq
Lights (zoom)
Lights connection:
red light: positive leg connected to digital pin 2
white light : positive leg connected to digital pin 3
blue light : positive leg connected to digital pin 4
green light : positive leg connected to digital pin 5

Negative leg of the 4 lights connected, using resistors, to the same row where GND is connected
Led zoom buzhxhojpt
Ultrasonic (zoom)
Ultrasonic connection:
- Vcc connected to breadboard's positive row
- Gnd connected to breadboard's negative row
- Trig connected to digital pin 13
- Echo connected to digital pin 12

5V connected to breadboard's negative row
GND connected to breadboard's positive row
Ultrasonic zoom ywl7apmuaw
Display (zoom)
Display connection (from left to right):
leg 1 connected to breadboard's negative row
leg 2 connected to breadboard's positive row
leg 3 connected to breadboard's negative row (using resistor)
leg 4 connected to analog pin A0
leg 5 connected to breadboard's negative row
leg 6 connected to analog pin A1
leg 11 connected to analog pin A2
leg 12 connected to analog pin A3
leg 13 connected to analog pin A4
leg 14 connected to analog pin A5
leg 15 connected to breadboard's positive row (using resistor)
leg 16 connected to breadboard's negative row
Display (zoom) gg6llndf41
Servo motor (zoom)
Servo motor connection:
- Red wire connected to breadboar's positive row
- Black wire connected to breadboard's negative row
- Yellow wire connected to digital pin 8
Servomotor (zoom) jdyvfdzrqg
Buzz (zoom)
Buzz connection:
- Black leg connected to breadboard's negative row
- Red leg connected to digital pin 11
Buzz (zoom) ilsagtlkce
Button (zoom)
Button connection:
- Left leg connected to breadboard's positive row
- Right leg connected to digital pin 7 and using a resistor connected to breadboard's negative row
Button (zoom) 0jvyq4mo1v

Comments

Similar projects you might like

Piezo Christmas Songs

Project showcase by joshi

  • 14,082 views
  • 14 comments
  • 45 respects

Programmable Christmas Mason Jar Lights

Project tutorial by Katie Kristoff

  • 2,385 views
  • 0 comments
  • 16 respects

Arduino Christmas Cheer!

Project tutorial by Dante Roumega

  • 1,197 views
  • 0 comments
  • 5 respects

Ultrasonic Sensor with Alarm, LCD and Temperature

Project tutorial by MichDragstar

  • 4,645 views
  • 7 comments
  • 19 respects

PIR Automated Intelligent Zebra Crossing

Project showcase by Adersh B

  • 2,262 views
  • 1 comment
  • 5 respects

Arduino Latest Christmas Tweet Reader

Project tutorial by Erhan Alankus

  • 1,119 views
  • 0 comments
  • 4 respects
Add projectSign up / Login