Nothing is more fun and jovial than a happy Christmas Elf sitting on a gift, waving to you...except watching him lose his head when you catch him being naughty.
The story:
The naughty Elves like to peek inside very personal Christmas gifts.
The naughty elves are also really sneaky.
Once someone gets in his viewing range, he kicks his legs, waves his hand, and acts totally innocent and nonchalant.
Actually, the Elf is sweating bullets on the inside, butterflies in his belly, behaving jittery and nervous.
If you see thru his innocent act and shout at him to behave or startle him, he loses his head...it goes flying.
It's actually pretty funny to see an elf lose composure.
This project is the animatronic Elf.
If you get in proximity of him sitting on the Victoria's Secret box, the PIR activates, he flutter kicks his legs, and he waves to you.
If you yell at him to behave or startle him, the sound sensor triggers , a solenoid activates, and his head is launched and he loses his head.
Watch the action on You Tube and details on the build.
The schematic
The Arduino Code:
#include <Servo.h>
Servo rightLeg; // create servo object to control a servo
Servo leftLeg; // create servo object to control a servo
Servo rightArm; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
int MotionDetected = LOW; // variable to store the PIR value
int SoundDetected = HIGH; // variable to store the sound input, HIGH is NO SOUND
int SolenoidOn = LOW; // variable to store the sound input
int SolenoidOnTime= 400; // time to leave on solenoid trigger high , to give it time to fully extend
int LegSwingTime = 30; // millisec delay time between position reference updates to the servos. 45 degrees/30ms per degree = 1.5 seconds
void setup() {
//yes, all my O.C.D. software friends go bananas when I assign pins to my code rather than making them a confuguration variable
// too bad :-) I do it this way to spite you
leftLeg.attach(9); // attaches the servo on pin 9 to the servo object
rightLeg.attach(10); // attaches the servo on pin 9 to the servo object
rightArm.attach(11); // attaches the servo on pin 9 to the servo object
pinMode(5,INPUT); // sets the digital pin 5 as input for the PIR
pinMode(3,INPUT); // sets the digital pin 3 as input for the sound sensor
pinMode(12,OUTPUT); // sets the digital pin 12 as an output for firing the Solenoid MOSFET
}
void loop() {
MotionDetected = digitalRead(5); // read the input pin of PIR
// check for motion detected, if none, set all servos to home position
if (MotionDetected == HIGH) {
for (pos = 0; pos <= 45; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
leftLeg.write(pos); // tell servo to go to position in variable 'pos'
rightLeg.write(pos); // right side servo is moubted opposite of the lHS servo
rightArm.write(pos);
delay(LegSwingTime); // waits for the servo to reach the position
// every scan check for a sound trigger
SoundDetected = digitalRead(3); // read the input pin of sound module
if (SoundDetected==LOW){ digitalWrite(12,HIGH);delay(SolenoidOnTime);}
else {digitalWrite(12,LOW);}
}
for (pos = 45; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
leftLeg.write(pos); // tell servo to go to position in variable 'pos'
rightLeg.write(pos); // tell servo to go to position in variable 'pos'
rightArm.write(pos);
delay(LegSwingTime); // waits 15ms for the servo to reach the position
// every scan check for a sound trigger
SoundDetected = digitalRead(3); // read the input pin of sound module
if (SoundDetected==LOW){ digitalWrite(12,HIGH);delay(SolenoidOnTime);}
else {digitalWrite(12,LOW);}
}
}
else {
leftLeg.write(0); // tell servo to go to position in variable 'pos'
rightLeg.write(0); // right side servo is moubted opposite of the lHS servo
rightArm.write(0);
digitalWrite(12,LOW); // reset and ensure the head launch solenoid is off
}
}
Top Comments