I built this awhile ago, and posted a video on youtube, and many have asked for details. I don't have time at the moment to do a detailed and complete writeup, but I thought I'd at least share some info. I'm sure there are other more detailed tutorials out there to for similar projects to help with any missing info.
The video is here
You can read the notes in the code to help figure out which pins to connect the various components to. The code uses the "Switch case" function, which you can read more about on the arduino code reference page. You will need to substitute the correct variables from your own IR remote, into each case statement (example, one of my case statements was 16753245 , you will need to substitute your own proper value). To find out what values to use, you need to find out what value your remote is producing for each button. You can either search online for an IR example sketch to use to capture the values, or you could likely just temporarily modify my code with a couple of well placed serial print commands to print the output and figure out the correct value for each button.
The plastic parts were made out of Instamorph plastic, servo is a cheap 9g servo, laser reciever is a cds photocell which was hot glued inside a shroud made from a black drinking straw. Metal parts were piano wire, pushrod connectors, and the shaft from a rivet. IR reciever is labeled 9744S. Remote has a label YK-001. Maybe if you find the exact same remote, and IR reciever, you might be able to save time and use my code exactly as is, without figuring out your own values (not for sure, but maybe).
/* Note, first time run, with no values stored in EEPROM might be a bit buggy,
as soon as values are stored, will work fine */
#include <IRremote.h>
#include <Servo.h>
#include <EEPROM.h>
int RECV_PIN = 11; //ir reciever hooked on pin 11 through 220ohm resistor
Servo myservo; // create servo object to control a servo
int position1; //servo position 1
int position2; //servo position 2
int position3; //servo position 3
int codeValue; //the code from the remote
int current; //keeps track of current servo position
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
position1 = EEPROM.read(1); //default servo positon 1
position2 = EEPROM.read(2); //default servo position 2
position3 = EEPROM.read(3); //default servo position 3
irrecv.enableIRIn(); // Start the receiver
myservo.attach(9); // attaches the servo on pin 9
myservo.write(position1); //start the servo out at position 1
current = position1;
}
void loop() {
if (irrecv.decode(&results)) {
codeValue = results.value;
switch (codeValue) {
case 16753245:
myservo.write(position1);
current = position1;
break;
case 16736925:
myservo.write(position2);
current = position2;
break;
case 16769565:
myservo.write(position3);
current = position3;
break;
case 16761405:
++current; //moves servo 1 degrees
if (current > 179) current = 179; //this makes sure the current variable doesn't exceed the servo range
myservo.write(current);
break;
case 16748655:
--current;
if (current < 0) current = 0; //makes sure variable doesn't drop below 0
myservo.write(current);
break;
case 16712445:
current += 10; //moves servo 10 degrees
if (current > 179) current = 179;
myservo.write(current);
break;
case 16754775:
current -= 10;
if (current < 0) current = 0;
myservo.write(current);
break;
case 16720605:
myservo.write(179); //moves servo all the way to 179
current = 179;
break;
case 16769055:
myservo.write(0);
current = 0;
break;
case 16738455:
position1 = current; //stores current position as servo position 1
EEPROM.write(1, position1); //writes position 1 to eeprom address 1
break;
case 16750695:
position2 = current; //stores current position as servo position 2
EEPROM.write(2, position2); //writes position 2 to eeprom address 2
break;
case 16756815:
position3 = current; //stores current position as servo position 3
EEPROM.write(3, position3); //writes position 3 to eeprom address 3
break;
case 16724175: //this is for the laser sensor
int sensorValue = analogRead(A0); //cds photocell hooked to analog 0, has 10k pulldown resistor to ground
while (sensorValue > 950) { //value can be adjusted, 950 very sensitive for my conditions
digitalWrite(13, HIGH); //status light, led on means laser is armed
sensorValue = analogRead(A0); //reads sensor value again for the loop
}
myservo.write(position3);
current = position3;
digitalWrite(13, LOW); //turns led off to indicate status that servo was activated.
delay(1000); //delay just for good measure, holds servo for a second
myservo.write(position1); //moves servo back to position 1
current = position1;
break;
}
irrecv.resume(); // Receive the next value
}
}