Demo Video

In this project, we will show you how  the Christmas/LED lights accompany the song. Using gizDuino LIN-UNO, piezo buzzer.

Materials:

*** Note: You can use 12V relay for 110~240VAC (Christmas LED Lights) or Solid State Relay. (On the sample application we use PVG612 SSR kit for 5~12VDC power load (Lights), and to less the noise of switching contact if triggered.)

Breadboard:

CONNECTIONS:
gizDuino LIN-UNO to Serial LCD
GND --> GND
TX(D1) --> RX
RX(D0) --> TX
D2 --> Button 3 //Jingle Bells
D3 --> Button 2 // Sta Claus is coming to town
D4 --> Button 1 // We wish you a merry Christmas
D9 --> Piezo Buzzer
Serial LCD
Pin 5 --> Green LED
Pin 6 --> Orange LED
Pin 7 --> Clear LED
Pin 10 --> +V (Relay)
GND --> -V (Relay)
+VIN --> 7~12VDC
GND --> GND
PVG612 SSR KIT to Christmas Light
L1 --> -V (Negative Polarity)
PVG612 SSR KIT to Power Supply
L3 --> -V (5VDC)
Christmas Light to Power Supply
+V (Positive Polarity) --> +V (5VDC)

 

EGIZMO SERIAL LCD LIBRARY:

Download eGizmo_SerialLCD Library!

(Examples: Hello_world,Digital pins, Digital read,Temperature Display)

How to add the Library?

Add the eGizmo SerialLCD library. Go to My Documents> Arduino> libraries. Place the eGizmo_SerialLCD folder (which contains examples folder,src,cpp,h, keywords files).

Codes:

/*
DIY Christmas Song Sketch
Using gizDuino LIN-UNO (Arduino UNO).
*/
#include <eGizmo_SerialLCD.h>
#include "pitches.h"
#define melodyPin 9
//For Arduino UNO or Gizduino V users
/*
SoftwareSerial mySerial(2,3);
eGizmo_SerialLCD mainDisplay(&myserial);
*/
//For MEGA, X, and Plus users
eGizmo_SerialLCD mainDisplay(&Serial, 2, 16); //Set to 2x16 LCD
// Jingle Bells
int melody[] = {
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
};
int tempo[] = {
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
int wish_melody[] = {
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
};
int wish_tempo[] = {
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
int santa_melody[] = {
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
};
int santa_tempo[] = {
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
};
int SW_ONE = 0;
int SW_TWO = 0;
int SW_THREE = 0;
#define LED_INDICATOR 10
#define BUZZER 9
#define SONG1 2
#define SONG2 3
#define SONG3 4
#define SONG1_LED 5
#define SONG2_LED 6
#define SONG3_LED 7
void setup(){
//Initialize
mainDisplay.begin();
//mainDisplay.print(message, row, column);
//note: you can place your message/row/column in any positions
mainDisplay.print("Hello", 1,6);
mainDisplay.print("World!", 2,6);
delay(2000); //2 seconds delay time
mainDisplay.printOver("EVERYONE!", 2,6);
delay(2000); //2 seconds delay time
//Clear all
mainDisplay.clear();
delay(2000); //2 seconds delay time
mainDisplay.scroll(1,"MERRY CHRISTMAS 2018!!!"); // Message Scrolling from left to right on the 1st row
delay(1000); //1 sec delay time
mainDisplay.scroll(2,"FROM: e-Gizmo Mechatronix Central"); // Message Scrolling from left to right on the 2nd row
//mainDisplay.print("SerialLCD Sample", 3,0); //Display message on 3rd row
//mainDisplay.print("**4x20 & 2x16 LCD**", 4,0); //Display message on 4th row
// for(int i = 0; i <=10; i++){
// mainDisplay.pinMode(i,OUTPUT);
// }
mainDisplay.pinMode(LED_INDICATOR,OUTPUT);
pinMode(BUZZER,OUTPUT);
pinMode(SONG1,INPUT);
pinMode(SONG2,INPUT);
pinMode(SONG3,INPUT);
mainDisplay.pinMode(SONG1_LED,INPUT);
mainDisplay.pinMode(SONG2_LED,INPUT);
mainDisplay.pinMode(SONG3_LED,INPUT);
mainDisplay.digitalWrite(SONG1_LED,LOW);
mainDisplay.digitalWrite(SONG2_LED,LOW);
mainDisplay.digitalWrite(SONG3_LED,LOW);
}
void loop(){
SW_ONE = digitalRead(SONG1);
SW_TWO= digitalRead(SONG2);
SW_THREE =digitalRead(SONG3);
if (SW_ONE == HIGH) {
MUSIC(1);
}
else if (SW_TWO == HIGH) {
MUSIC(2);
}
else if (SW_THREE == HIGH) {
MUSIC(3);
}
}
int SONG = 0;
void MUSIC(int s) {
// iterate over the notes of the melody:
SONG = s;
if (SONG == 3) {
Serial.println(" 'We wish you a Merry Christmas'");
mainDisplay.digitalWrite(SONG1_LED,HIGH);
mainDisplay.digitalWrite(SONG2_LED,LOW);
mainDisplay.digitalWrite(SONG3_LED,LOW);
int size = sizeof(wish_melody) / sizeof(int);
for (int thisNote = 0; thisNote < size; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / wish_tempo[thisNote];
BUZZ(melodyPin, wish_melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
BUZZ(melodyPin, 0, noteDuration);
}
}
else if (SONG == 2) {
Serial.println(" 'Santa Claus is coming to town'");
mainDisplay.digitalWrite(SONG1_LED,LOW);
mainDisplay.digitalWrite(SONG2_LED,HIGH);
mainDisplay.digitalWrite(SONG3_LED,LOW);
int size = sizeof(santa_melody) / sizeof(int);
for (int thisNote = 0; thisNote < size; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 900 / santa_tempo[thisNote];
BUZZ(melodyPin, santa_melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
BUZZ(melodyPin, 0, noteDuration);
}
}
else {
Serial.println(" 'Jingle Bells'");
mainDisplay.digitalWrite(SONG1_LED,LOW);
mainDisplay.digitalWrite(SONG2_LED,LOW);
mainDisplay.digitalWrite(SONG3_LED,HIGH);
int size = sizeof(melody) / sizeof(int);
for (int thisNote = 0; thisNote < size; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / tempo[thisNote];
BUZZ(melodyPin, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
BUZZ(melodyPin, 0, noteDuration);
}
}
}
void BUZZ(int targetPin, long frequency, long length) {
mainDisplay.digitalWrite(LED_INDICATOR, HIGH);
long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
//// 1 second's worth of microseconds, divided by the frequency, then split in half since
//// there are two phases to each cycle
long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
//// multiply frequency, which is really cycles per second, by the number of seconds to
//// get the total number of cycles to produce
for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
digitalWrite(BUZZER, HIGH); // write the buzzer pin high to push out the diaphram
delayMicroseconds(delayValue); // wait for the calculated delay value
digitalWrite(BUZZER, LOW); // write the buzzer pin low to pull back the diaphram
delayMicroseconds(delayValue); // wait again or the calculated delay value
}
mainDisplay.digitalWrite(LED_INDICATOR, LOW);
}

Add this pitches.h

/*************************************************
* Public Constants
*************************************************/
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
view rawpitches.h hosted with ? by GitHub

Reference:

Piezo Christmas Songs: https://www.hackster.io/joshi/piezo-christmas-songs-fd1ae9