Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 10 | ||||
| × | 4 | ||||
Software apps and online services | ||||||
| ||||||
| ||||||
Hand tools and fabrication machines | ||||||
|
This project was made to be an interactive Christmas decoration, the tree LEDs, music played and the arms of Santa and Elf are all controlled using a phone app created using MIT App Inventor that communicates with the Arduino MKR1000.
First I made a cone shaped paper and painted it green.
Then I have added green cardboard to create leaves of the tree.
Then creating white snow effect using white cardboard.
Soldering LED lines I have made three lines:
Creating the star on top of the tree.
Then I have used gift paper to make gifts under the tree.
I have cut down the shapes of both Santa and Elf and connected servo motors to each arm of them.
Added some decoration white paper to the table and red ribbon on the tree.
#include <DFRobotDFPlayerMini.h> //DFPlayer MP3 Module control library
#include <Servo.h> //Servo motors control library
#include <WiFi101.h> //Wifi library
//Defining constants for pins
//Santa and Elf Outputs
const int SantaRHand = 0;
const int SantaLHand = 1;
const int ElfRHand = 2;
const int ElfLHand = 3;
//Tree Star pins
const int TreeStar1 = 6;
const int TreeStar2 = 7;
const int TreeStar3 = 8;
//Tree Star Patterns
const int TreeLine1 = 9;
const int TreeLine2 = 10;
const int TreeLine3 = 11;
//Defining variables
//Defining Tree Pattern Variable
int TreePattern = 1;
//Defining MP3 player variable
int CurrentSong =1;
DFRobotDFPlayerMini myDFPlayer; //Creating DFPlayer object
Servo myservo1; //Santa right hand instance
Servo myservo2; //Santa left hand instance
Servo myservo3; //Elf right hand instance
Servo myservo4; //Elf left hand instance
char ssid[] = "YourSSIDName"; // your network SSID (name)
char pass[] = "YourSSIDPassword"; // your network password
//int keyIndex = 0; // your network key Index number (needed only for WEP)
char current_state = 'a';
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {
Serial1.begin(9600); //Initializing serial communication to communicate with DFPlayer module
//Set TreeLine Pins to Outputs
pinMode(TreeLine1, OUTPUT);
pinMode(TreeLine2, OUTPUT);
pinMode(TreeLine3, OUTPUT);
while(!myDFPlayer.begin(Serial1)){} //Wait until DFPlayer starts
myDFPlayer.volume(30); //Setting the volume of DFPlayer 0-30
myservo1.attach(SantaRHand); //assigning servo objects to pins
myservo2.attach(SantaLHand);
myservo3.attach(ElfRHand);
myservo4.attach(ElfLHand);
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
server.begin(); // start the web server on port 80
}
void loop() {
////////////////////////////////////////////////////////////////////////////////////////////
WiFiClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
if (c == '\n') { // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
// the content of the HTTP response follows the header:
//client.print("Click <a href=\"/H\">here</a> turn the LED on pin 6 on<br>");
// client.print("Click <a href=\"/L\">here</a> turn the LED on pin 6 off<br>");
// client.print("Click <a href=\"/B\">here</a> Blink the LED on pin 6 On and Off<br>");
// The HTTP response ends with another blank line:
// client.println();
// break out of the while loop:
break;
}
else { // if you got a newline, then clear currentLine:
currentLine = "";
}
}
else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
// Check to see if the client request
if (currentLine.endsWith("GET /A")) {
current_state = 'a'; // Show start request
StartGreeting(); //Jump to greeting function (move hands)
myDFPlayer.play(1); //play first song on SD card
}
if (currentLine.endsWith("GET /B")) {
current_state = 'b'; // Show stop request
}
if (currentLine.endsWith("GET /C")) {
StartGreeting(); // Greeting request
}
//Tree Pattern Change Button
if (currentLine.endsWith("GET /D")) {
TreePattern = 1; //Change tree pattern
}
if (currentLine.endsWith("GET /E")) {
TreePattern = 2; //Change tree pattern
}
if (currentLine.endsWith("GET /F")) {
TreePattern = 3; //Change tree pattern
}
//Song Change Button
if (currentLine.endsWith("GET /G")) {
myDFPlayer.play(1); //Play First song
}
if (currentLine.endsWith("GET /H")) {
myDFPlayer.play(3); //Play Second Song
}
if (currentLine.endsWith("GET /I")) {
myDFPlayer.pause(); //Stop Playing songs (Pause)
}
}
}
// close the connection:
client.stop();
}
////////////////////////////////////////////////////////////////////////////////////////////
if (current_state == 'a') { // Show start request
turnOnTree();
}
if (current_state == 'b') { // Show Stop request
turnOffTree();
myDFPlayer.pause();
}
}
void StartGreeting(){
myDFPlayer.play(2); //Play greeting sound
analogWrite(TreeStar1,100); //adjust color of the star
analogWrite(TreeStar2,100);
analogWrite(TreeStar3,100);
digitalWrite(TreeLine1, HIGH); //change tree lines pattern
digitalWrite(TreeLine2, HIGH);
digitalWrite(TreeLine3, HIGH);
delay(6500);
SantaElfHi(); //move hands
SantaElfHi();
SantaElfHi();
analogWrite(TreeStar1,100);
analogWrite(TreeStar2,100);
analogWrite(TreeStar3,100);
digitalWrite(TreeLine1, HIGH);
digitalWrite(TreeLine2, HIGH);
digitalWrite(TreeLine3, HIGH);
delay(16000);
}
void SantaElfHi(){ //Move Santa and Elf Hands
myservo1.write(7);
delay(30);
myservo2.write(70);
delay(30);
myservo3.write(7);
delay(30);
myservo4.write(70);
delay(30);
analogWrite(TreeStar1,200);
analogWrite(TreeStar2,100);
analogWrite(TreeStar3,200);
digitalWrite(TreeLine1, HIGH);
digitalWrite(TreeLine2, HIGH);
digitalWrite(TreeLine3, HIGH);
delay(1000);
analogWrite(TreeStar1,0);
analogWrite(TreeStar2,0);
analogWrite(TreeStar3,0);
digitalWrite(TreeLine1, LOW);
digitalWrite(TreeLine2, LOW);
digitalWrite(TreeLine3, LOW);
myservo1.write(70);
delay(30);
myservo2.write(7);
delay(30);
myservo3.write(70);
delay(30);
myservo4.write(7);
delay(30);
delay(1000);
}
void turnOffTree(){
//turn off all leds
analogWrite(TreeStar1,0);
analogWrite(TreeStar2,0);
analogWrite(TreeStar3,0);
digitalWrite(TreeLine1, LOW);
digitalWrite(TreeLine2, LOW);
digitalWrite(TreeLine3, LOW);
}
void turnOnTree() {
//turn on tree leds with the selected pattern
switch (TreePattern) {
case 1:
analogWrite(TreeStar1,255);
digitalWrite(TreeLine1, HIGH);
delay(100);
analogWrite(TreeStar1,0);
analogWrite(TreeStar2,255);
digitalWrite(TreeLine2, HIGH);
delay(100);
analogWrite(TreeStar2,0);
analogWrite(TreeStar3,255);
digitalWrite(TreeLine3, HIGH);
delay(100);
analogWrite(TreeStar3,0);
digitalWrite(TreeLine1, LOW);
digitalWrite(TreeLine2, LOW);
digitalWrite(TreeLine3, LOW);
delay(100);
break;
case 2:
analogWrite(TreeStar1,255);
analogWrite(TreeStar2,0);
analogWrite(TreeStar3,255);
digitalWrite(TreeLine1, HIGH);
digitalWrite(TreeLine2, HIGH);
digitalWrite(TreeLine3, HIGH);
delay(100);
analogWrite(TreeStar1,255);
analogWrite(TreeStar2,255);
analogWrite(TreeStar3,0);
digitalWrite(TreeLine1, LOW);
digitalWrite(TreeLine2, LOW);
digitalWrite(TreeLine3, LOW);
delay(50);
analogWrite(TreeStar1,0);
analogWrite(TreeStar2,255);
analogWrite(TreeStar3,255);
digitalWrite(TreeLine1, HIGH);
digitalWrite(TreeLine2, HIGH);
digitalWrite(TreeLine3, HIGH);
delay(100);
analogWrite(TreeStar1,255);
analogWrite(TreeStar2,200);
analogWrite(TreeStar3,100);
digitalWrite(TreeLine1, LOW);
digitalWrite(TreeLine2, LOW);
digitalWrite(TreeLine3, HIGH);
delay(100);
analogWrite(TreeStar1,255);
analogWrite(TreeStar2,0);
analogWrite(TreeStar3,255);
digitalWrite(TreeLine1, LOW);
digitalWrite(TreeLine2, HIGH);
digitalWrite(TreeLine3, LOW);
delay(100);
analogWrite(TreeStar1,255);
analogWrite(TreeStar2,0);
analogWrite(TreeStar3,0);
digitalWrite(TreeLine1, HIGH);
digitalWrite(TreeLine2, LOW);
digitalWrite(TreeLine3, LOW);
delay(100);
analogWrite(TreeStar1,0);
analogWrite(TreeStar3,255);
digitalWrite(TreeLine1, LOW);
digitalWrite(TreeLine2, LOW);
digitalWrite(TreeLine3, LOW);
delay(100);
break;
case 3:
analogWrite(TreeStar1,255);
digitalWrite(TreeLine1, HIGH);
digitalWrite(TreeLine2, LOW);
digitalWrite(TreeLine3, LOW);
delay(60);
analogWrite(TreeStar1,0);
analogWrite(TreeStar2,255);
digitalWrite(TreeLine1, LOW);
digitalWrite(TreeLine2, HIGH);
digitalWrite(TreeLine3, LOW);
delay(60);
analogWrite(TreeStar2,0);
analogWrite(TreeStar3,255);
digitalWrite(TreeLine1, LOW);
digitalWrite(TreeLine2, LOW);
digitalWrite(TreeLine3, HIGH);
delay(60);
analogWrite(TreeStar1,255);
analogWrite(TreeStar3,255);
digitalWrite(TreeLine1, LOW);
digitalWrite(TreeLine2, HIGH);
digitalWrite(TreeLine3, LOW);
delay(60);
break;
}
}
Comments