Another thing that your remote can control is a servo motor. You can use these motors to turn and move static Halloween props to create your own DIY animated Halloween props. To control a servo, connect the output wires from the servo to the 5V pin, GND pin, and a digital pin on the Arduino (based on the color code of the wires). Connect your servo to a prop (such as a skull) and attach it to a stand to hold it in place. Then write some code to turn on the servo when the IR receiver detects the signal. Here is a simple example.
#include
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
int inPin = 2;
int val = 0; // variable to store the value read
void setup() {
Serial.begin(9600); // setup serial
pinMode(inPin, INPUT);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
val = digitalRead(inPin);
Serial.println(val); // debug value
if (val == LOW) {
delay(1000);
for (pos = 30; pos = 30; pos -= 1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
}