amrmostaafaa
Published © LGPL

How to Build an Arduino-Based Santa Claus for Christmas

Make a Santa Claus that talks, sings, and takes selfie photos whenever someone passes by him.

BeginnerFull instructions provided2,302
How to Build an Arduino-Based Santa Claus for Christmas

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
1Sheeld
1Sheeld
×1
Breadboard (generic)
Breadboard (generic)
×1
Relay (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
christmas tree with AC light
×1
electric AC wires
×1
fiber
×1
pvc tubes
×1
cardboard sheet
×1
santa claus wear
×1
pvc joints
×1

Hand tools and fabrication machines

drill
Hot glue gun (generic)
Hot glue gun (generic)
saw
cable ties
screws
L-corners
screw driver
scissors
tape
pvc cement

Story

Read more

Schematics

schematic

Code

code

Arduino
/* Include required shields */
#define CUSTOM_SETTINGS
#define INCLUDE_CAMERA_SHIELD
#define INCLUDE_BUZZER_SHIELD
#define INCLUDE_TERMINAL_SHIELD
#define INCLUDE_TEXT_TO_SPEECH_SHIELD
#define INCLUDE_VOICE_RECOGNIZER_SHIELD
#define INCLUDE_MUSIC_PLAYER_SHIELD
#define INCLUDE_TWITTER_SHIELD


/* Include 1Sheeld library. */
#include <OneSheeld.h>

//sensor pins
#define TRIG_PIN         3
#define ECHO_PIN         5
#define RELAY            13

bool peopleAreHere = false;
bool theySaidYes = false;

/* Variable to save the measured distance from ultrasonic */
int distance;

//Set commands to be recognized by the Arduino Voice Recognition Shield
const char ok[] = "sure";
const char no[] = "no";

void setup()
{
  pinMode(TRIG_PIN , OUTPUT);
  pinMode(ECHO_PIN , INPUT);
  pinMode(RELAY , OUTPUT);
  /* Start 1Sheeld communication. */
  OneSheeld.begin();
}

void loop()
{
  /* Get the current distance from the ultrasonic */
  distance = getUltrasonicDistance();

  /* Print the distance on the Terminal shield */
  Terminal.println(distance);

  
  if (distance > 110)
  {
    digitalWrite(RELAY , LOW);
    MusicPlayer.stop();
    peopleAreHere = false;
  }
  
  /* Check if distance is less than 2 meter */
  if (distance <= 110 && distance > 0 && (peopleAreHere == false) )
  {
    peopleAreHere = true;
    digitalWrite(RELAY , HIGH);
    MusicPlayer.play();
    OneSheeld.delay(18000);
  }

  if (peopleAreHere)
  {
    //MusicPlayer.pause();
    TextToSpeech.say("Hey, why don't we take a photo together ?");
    OneSheeld.delay(3000);
    VoiceRecognition.start();
    peopleAreHere = false;
  }

  
  if (VoiceRecognition.isNewCommandReceived())
  {
    //Compare the last command received by the Arduino Voice Recognition Shield with the command "yes"
    if ( !strcmp(ok, VoiceRecognition.getLastCommand()) )
    {
      
      theySaidYes = true;
      
      
    }

    //Compare the last command received by the Arduino Voice Recognition Shield with the command "no"
    else
    {
      
      
      theySaidYes = false;
    }
  }
  
  if (theySaidYes)
  {
    TextToSpeech.say("please stay near me, I will take a sweet selfie after the tone");

    OneSheeld.delay(5000);

    Buzzer.buzzOn();

    OneSheeld.delay(500);

    Buzzer.buzzOff();

    OneSheeld.delay(500);

    /* Take a photo */
    Camera.frontCapture();

    /* Delay for 5 seconds to give the camera shield enough time for taking and saving the photo */
    OneSheeld.delay(7000);

    theySaidYes =  false;

    TextToSpeech.say("Awesome, I will tweet it now");
    OneSheeld.delay(3000);

    // Facebook.postLastPicture("merry christmas with my sweet friends" , 1 );
    Twitter.tweetLastPicture("merry christmas with my sweet friends" , 0 );
    
    digitalWrite(RELAY , HIGH);
    MusicPlayer.play();
    OneSheeld.delay(18000);

    // dekay before tweeting again
    OneSheeld.delay(10000);
  }
}


/* A function that makes the whole operation of the ultrasonic and returning the detected distance */
int getUltrasonicDistance(void)
{
  /* Variable to save the sound wave travel time in microseconds */
  long duration;

  /* Variable to save the detected distance in cm */
  int distanceReturned;

  /* Clears the TRIG_PIN */
  digitalWrite(TRIG_PIN, LOW);

  /* delay 2 micro seconds */
  delayMicroseconds(2);

  /* Sets the TRIG_PIN on HIGH state for 10 micro seconds */
  digitalWrite(TRIG_PIN, HIGH);

  /* delay 10 micro seconds */
  delayMicroseconds(10);

  /* Sets the TRIG_PIN on LOW state */
  digitalWrite(TRIG_PIN, LOW);

  /* Reads the ECHO_PIN, returns the sound wave travel time in microseconds */
  duration = pulseIn(ECHO_PIN, HIGH);


  /* Calculating the distance */
  distanceReturned = duration * 0.034 / 2;

  /* Returning the detected distance in cm */
  return distanceReturned;
}

Credits

amrmostaafaa
7 projects • 44 followers
Maker, Engineer, dreamer and passionate about technology.
Contact

Comments

Please log in or sign up to comment.