DIY IR Remote controlled servo. - RC Groups
Thread Tools
Mar 03, 2011, 04:31 PM
Registered User

DIY IR Remote controlled servo.

I thought I would share this project I recently completed. It allows you to control a servo with an IR remote control.

Right now it is being used to simply remotely press a camera shutter button, but it can easily be modified to perform all sorts of other RC related tasks, or add a second servo and make an rc vehicle, or pan tilt setup, or whatever you want. No need to get out your expensive flight TX and RX, when you only need to control 1 or 2 servos.

Remote controlled finger. Give any camera remote shutter capability, and laser. (1 min 50 sec)

I was a complete arduino newbie before starting this project, and had run into lots of problems getting the coding bugs out, especially the syntax of IR code which was not too well documented online. So I am sharing my code here so that anybody else trying this can have a good example to go off of.

/* 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 =;    //default servo positon 1
  position2 =;   //default servo position 2
  position3 =;  //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:    
      current = position1;
    case 16736925:    
      current = position2;
    case 16769565:    
      current = position3;
    case 16761405:
      ++current;                //moves servo 1 degrees
      if (current > 179) current = 179;  //this makes sure the current variable doesn't exceed the servo range
    case 16748655:
      if (current < 0) current = 0;  //makes sure variable doesn't drop below 0
    case 16712445:
      current += 10;  //moves servo 10 degrees
      if (current > 179) current = 179;
    case 16754775:
      current -= 10;
      if (current < 0) current = 0;
    case 16720605:    
      myservo.write(179);  //moves servo all the way to 179
      current = 179;
    case 16769055:    
      current = 0;
    case 16738455:    
      position1 = current;  //stores current position as servo position 1
      EEPROM.write(1, position1);  //writes position 1 to eeprom address 1
    case 16750695:    
      position2 = current;  //stores current position as servo position 2
      EEPROM.write(2, position2);  //writes position 2 to eeprom address 2
    case 16756815:    
      position3 = current;  //stores current position as servo position 3
      EEPROM.write(3, position3);  //writes position 3 to eeprom  address 3
    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
      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;
irrecv.resume(); // Receive the next value
Sign up now
to remove ads between posts

Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
Gallery Remote Controlled RTP mrexcel Scratchbuilt Indoor and Micro Models 2 Oct 17, 2010 10:19 AM
Question Remote controlled tower cranes Krillo Trader Talk 1 Oct 04, 2010 08:19 AM
Sold Scorpion IR Receiver and IR Remote Control - $10 shipped dswitkin Aircraft - Electric - Power Systems (FS/W) 2 Aug 30, 2009 10:20 PM
Discussion Cheap IR controlled IR Battle Tanks modfly RC Tanks 0 Dec 26, 2008 11:38 PM
Discussion remote controlled servo tester design? cmulder DIY Electronics 9 Jun 25, 2007 10:19 PM