Project tutorial

Hackable Christmas Greeting Card © GPL3+

In this post we will make a cool Christmas greeting card with the possibility of changing the music and much more, with Cayenne IoT.

  • 487 views
  • 0 comments
  • 3 respects

Components and supplies

Apps and online services

About this project

Introduction

Hey Hacksters! Do you have a Christmas Greeting card? Bored and tired of it? Then this is your post.

In this post we will hack a cool Christmas Greeting Card with the possibility of changing the music, the led color (if you have one RGB) and brightness! All of this with Cayenne IoT to make it controllable with a smart phone! And we can make it also, our alarm clock!

Sneak Peak Video

Overview of the Christmas Greeting Card Project

What you need before starting the project

Of course you need the materials I said before. You need a Cayenne Account, make one here. Then you need Cayenne Library. Simply search for MKR1000 sample Sketch and connect your board to Cayenne Dashboard.

Assembly

Retire the electronics parts the card has and just fill the greeting card with your electronics, if you have a MKR1000 without headers it will be easier.

Cayenne dashboard

Just put 8 buttons for the songs with Virtual connection and put the pins from V1 to V8. For the LED, in my case I only had a single color LED, go to Actuators>Light>Luminosity and select Digital connection with pin D5.

But you can also put 3 more buttons for changing the color of a RGB LED. If you want to make a Christmas Greeting Card alarm clock just go to Scheduler and make an event which will turn on one of the songs at a certain time.

Songs

The project has 8 Christmas songs, but you can put more. The play system is like this Arduino example but modified: http://www.arduino.cc/en/Tutorial/Melody

Well, as you could see in the video the volume was very low, so I recorded the songs with a microphone:

  • Ding Dong Merrily on High
  • God Rest Ye Merry Gentlemen
  • O Little Town of Bethlehem
  • While Shepherds Watched
  • In The Bleak Midwinter
  • Hark the Herald Herald Angels Sing
  • O come all Ye Faithful
  • O Come O Come Emmanuel

https://soundcloud.com/neoxelox/sets/hacksterio-arduino-contests-songs

Schematics

Hackable Christmas Greeting Card - SCHEMATICS
Schematics
Schematics 9bq7nvtofw

Code

Hackable Christmas Greeting Card - CODEArduino
Code
/* 
Project created by Neoxelox for Hackster.io Arduino Contest 31/12/2016 
Cayenne MKR1000 Example 
This sketch connects to the Cayenne server using an Arduino/Genuino MKR1000 and runs the main communication loop. 
The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager. 
Steps: 
1. Install the Arduino SAMD Boards from the Arduino Boards Manager if you have not done so already. 
2. Install the WiFi101 library (https://github.com/arduino-libraries/WiFi101) from the Arduino Library Manager if you have not done so already. 
3. Select the Arduino/Genuino MKR1000 board and the correct port in the Arduino IDE. 
4. Set the token variable to match the Arduino token from the Dashboard. 
5. Set the network name and password. 
6. Compile and upload this sketch. 
For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically 
send data on those pins to the Cayenne server. If the widgets use Virtual Pins, data 
should be sent to those pins using virtualWrites. Examples for sending and receiving 
Virtual Pin data are under the Basics folder. 
*/ 
//#define CAYENNE_DEBUG         // Uncomment to show debug messages 
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space 
#include <CayenneMKR1000.h> 
#define LED_VIRTUAL_PIN V0 
#define SONG_VIRTUAL_PIN V1 
#define SONG2_VIRTUAL_PIN V2 
#define SONG3_VIRTUAL_PIN V3 
#define SONG4_VIRTUAL_PIN V4 
#define SONG5_VIRTUAL_PIN V5 
#define SONG6_VIRTUAL_PIN V6 
#define SONG7_VIRTUAL_PIN V7 
#define SONG8_VIRTUAL_PIN V8 
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard. 
char token[] = "*********"; 
// Your network name and password. 
char ssid[] = "*********"; 
char password[] = "**********"; 
int speakerPin = 6; 
int leds = 5; 
int yesno = 0; 
//Buzzer----------------------------------- 
int tempo = 150; 
//Buzzer----------------------------------- 
void setup() 
{ 
 Serial.begin(9600); 
 Cayenne.begin(token, ssid, password); 
 pinMode(speakerPin, OUTPUT); 
 pinMode(leds, OUTPUT); 
} 
void loop() 
{ 
 Cayenne.run(); 
} 
//BUZZER----------------------------------------------------------------------------- 
void playTone(int tone, int duration) { 
 for (long i = 0; i < duration * 1000L; i += tone * 2) { 
   digitalWrite(speakerPin, HIGH); 
   delayMicroseconds(tone); 
   digitalWrite(speakerPin, LOW); 
   delayMicroseconds(tone); 
 } 
} 
void playNote(char note, int duration) { 
 char names[] = { 'c', 'd', 'e', 'f', 's', 'g', 'a', 'v', 'b', 'C', 'D', 'E' }; 
 int tones[] = { 1915, 1700, 1519, 1432, 1352, 1275, 1136, 1073, 1014, 956, 852, 758 }; 
 // play the tone corresponding to the note name 
 for (int i = 0; i < 8; i++) { 
   if (names[i] == note) { 
     playTone(tones[i], duration); 
   } 
 } 
} 
//BUZZER------------------------------------------------------------------------------ 
//CAYENNE VIRTUAL DASHBOARD----------------------------------------------------------- 
CAYENNE_IN(LED_VIRTUAL_PIN) 
{ 
 // get value sent from dashboard 
 int currentValue = getValue.asInt(); // 0 to 1023 
 analogWrite(leds, currentValue / 4); // must be from 0 to 255 
} 
//Ding Dong Merrily 
CAYENNE_IN(SONG_VIRTUAL_PIN) 
{ 
   yesno = getValue.asInt(); 
   if (yesno == 1){ 
   int length = 73; 
   char notes[] = "ggagsed deggsgg ggagsed deggsgg DCbCDbCbabCabagabgagsgasgsesgeseddeggsgg "; // a space represents a rest 
   int beats[] = { 2,2,1,1,1,1,4,2,2,2,2,2,2,4,2,2,2,2,1,1,1,1,4,2,2,2,2,2,2,4,2,2,3,1,1,1,1,1,3,1,1,1,1,1,3,1,1,1,1,1,3,1,1,1,1,1,3,1,1,1,1,1,3,1,2,2,2,2,2,2,4,2,2 }; 
   for (int i = 0; i < length; i++) {         
        if (notes[i] == ' ') { 
        delay(beats[i] * tempo); // rest 
       } else { 
       playNote(notes[i], beats[i] * tempo); 
       } 
      // pause between notes 
      delay(tempo / 2);  
      yesno = getValue.asInt(); 
      if (yesno == 0){ 
          break; 
       } 
     }  
   } 
} 
//God Rest Ye Merry Gentlemen 
CAYENNE_IN(SONG2_VIRTUAL_PIN) 
{ 
   yesno = getValue.asInt(); 
   if (yesno == 1){ 
  int length = 69; 
  char notes[] = "ddaagfedcdefga ddaagfedcdefga avgavCDagfdefgfgavaagfedfedgfgavCDagfed"; 
  int beats[] = { 2,2,2,2,2,2,2,2,2,2,2,2,2,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,2,2,4,2,2,2,2,2,2,4,1,1,2,4,2,2,2,2,2,2,2,2,2,2,8 }; 
   for (int i = 0; i < length; i++) { 
        if (notes[i] == ' ') { 
        delay(beats[i] * tempo); // rest 
       } else { 
       playNote(notes[i], beats[i] * tempo); 
       } 
      // pause between notes 
      delay(tempo / 2);  
      yesno = getValue.asInt(); 
      if (yesno == 0){ 
          break; 
       } 
     }  
   } 
} 
//O Little Town of Bethlehem 
CAYENNE_IN(SONG3_VIRTUAL_PIN) 
{ 
   yesno = getValue.asInt(); 
   if (yesno == 1){ 
 int length = 71; 
 char notes[] = "cfffgagavCavafggfcfffgagavCavafggffaCDCvagfgavCcfagfccfffgagavCavafggf "; 
 int beats[] = { 2,2,2,2,2,1,1,1,1,2,2,2,1,1,2,2,6,2,2,2,2,2,1,1,1,1,2,2,2,1,1,2,2,6,1,1,3,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,4,4,2,2,2,2,1,1,1,1,2,2,2,1,1,2,2,6,2 }; 
   for (int i = 0; i < length; i++) { 
        if (notes[i] == ' ') { 
        delay(beats[i] * tempo); // rest 
       } else { 
       playNote(notes[i], beats[i] * tempo); 
       } 
      // pause between notes 
      delay(tempo / 2);  
      yesno = getValue.asInt(); 
      if (yesno == 0){ 
          break; 
       } 
     }  
   } 
} 
//While Shephards Watched 
CAYENNE_IN(SONG4_VIRTUAL_PIN) 
{ 
   yesno = getValue.asInt(); 
   if (yesno == 1){ 
  int length = 29; 
  char notes[] = "faagfvvagaCCbCaDCvagfeagffef "; 
  int beats[] = { 2,3,1,2,2,2,2,2,2,2,2,2,2,6,2,3,1,2,2,2,2,2,2,2,2,2,2,6,2 }; 
   for (int i = 0; i < length; i++) { 
        if (notes[i] == ' ') { 
        delay(beats[i] * tempo); // rest 
       } else { 
       playNote(notes[i], beats[i] * tempo); 
       } 
      // pause between notes 
      delay(tempo / 2);  
      yesno = getValue.asInt(); 
      if (yesno == 0){ 
          break; 
       } 
     }  
   } 
} 
//In The Bleak Midwinter 
CAYENNE_IN(SONG5_VIRTUAL_PIN) 
{ 
   yesno = getValue.asInt(); 
   if (yesno == 1){ 
  int length = 51; 
  char notes[] = "aavCagfgagdgavCaggfgagff vavCDDaaCagfecavCagfgagff "; 
  int beats[] = { 2,3,1,2,2,4,4,3,1,2,2,8,3,1,2,2,3,1,4,2,2,3,1,6,2,3,1,2,2,2,2,2,2,2,2,2,2,6,2,2,2,2,2,4,4,2,2,3,1,8,8}; 
   for (int i = 0; i < length; i++) { 
        if (notes[i] == ' ') { 
        delay(beats[i] * tempo); // rest 
       } else { 
       playNote(notes[i], beats[i] * tempo); 
       } 
      // pause between notes 
      delay(tempo / 2);  
      yesno = getValue.asInt(); 
      if (yesno == 0){ 
          break; 
       } 
     }  
   } 
} 
//Hark the Herald 
CAYENNE_IN(SONG6_VIRTUAL_PIN) 
{ 
   yesno = getValue.asInt(); 
   if (yesno == 1){ 
  int length = 77; 
  char notes[] = "cffefaagCCCvagacffefaagCffeedcCCCfvaagCCCfvaagDDDCvavgavCffgaDDDCvavgavCffgf "; 
  int beats[] = {2,2,3,1,2,2,2,2,2,2,3,1,2,2,4,2,2,3,1,2,2,2,2,2,2,3,1,2,2,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,2,1,1,3,1,2,2,4,3,1,2,2,2,2,4,2,1,1,3,1,2,2,4,8}; 
   for (int i = 0; i < length; i++) { 
        if (notes[i] == ' ') { 
        delay(beats[i] * tempo); // rest 
       } else { 
       playNote(notes[i], beats[i] * tempo); 
       } 
      // pause between notes 
      delay(tempo / 2);  
      yesno = getValue.asInt(); 
      if (yesno == 0){ 
          break; 
       } 
     }  
   } 
} 
//O come all Ye Faithful 
CAYENNE_IN(SONG7_VIRTUAL_PIN) 
{ 
   yesno = getValue.asInt(); 
   if (yesno == 1){ 
  int length = 64; 
  char notes[] = "ggdgadbabCbaggsesgabsedd DCbCbabgasedggsgagdbbabCbabCbagsgCbagg "; 
  int beats[] = { 2,4,2,2,4,4,2,2,2,2,4,2,2,4,2,2,2,2,2,2,4,3,1,6,2,4,2,2,4,4,2,2,2,2,3,1,2,2,2,2,2,2,4,2,2,2,2,2,2,4,2,2,2,2,2,2,4,2,2,4,3,1,6,8 }; 
   for (int i = 0; i < length; i++) { 
        if (notes[i] == ' ') { 
        delay(beats[i] * tempo); // rest 
       } else { 
       playNote(notes[i], beats[i] * tempo); 
       } 
      // pause between notes 
      delay(tempo / 2);  
      yesno = getValue.asInt(); 
      if (yesno == 0){ 
          break; 
       } 
     }  
   } 
} 
//O Come O Come Emmanuel 
CAYENNE_IN(SONG8_VIRTUAL_PIN) 
{ 
   yesno = getValue.asInt(); 
   if (yesno == 1){ 
  int length = 63; 
  char notes[] = "egbbbaCbagabgegasedeaaeesgsedgabbbaCbag DD bb baCdagabgegasede "; 
  int beats[] = { 2,2,2,2,2,2,2,2,2,6,2,2,2,2,2,2,2,2,2,6,2,2,2,2,2,4,2,2,6,2,2,2,2,2,2,2,2,2,4,2,2,4,2,2,4,2,2,2,2,2,2,6,2,2,2,2,2,2,2,2,2,8,8 }; 
   for (int i = 0; i < length; i++) { 
        if (notes[i] == ' ') { 
        delay(beats[i] * tempo); // rest 
       } else { 
       playNote(notes[i], beats[i] * tempo); 
       } 
      // pause between notes 
      delay(tempo / 2);  
      yesno = getValue.asInt(); 
      if (yesno == 0){ 
          break; 
       } 
     }  
   } 
} 
//CAYENNE VIRTUAL DASHBOARD----------------------------------------------------------- 

Comments

Similar projects you might like

Development Board for AtTiny MCU

by Vincenzo G.

  • 100 views
  • 0 comments
  • 4 respects

The Magnetic Field and RGB Tester

Project tutorial by Kutluhan Aktar

  • 164 views
  • 0 comments
  • 2 respects

Version 2.0 Advanced Attendance System (Without Ethernet)

Project tutorial by GadgetProgrammers

  • 2,840 views
  • 5 comments
  • 44 respects

How To Use DS18B20 Water Proof Temperature Sensor

Project showcase by IoTBoys

  • 145 views
  • 0 comments
  • 3 respects

Ultrasonic Security System

Project tutorial by Krepak

  • 264 views
  • 0 comments
  • 4 respects
Add projectSign up / Login