HobbyKing.com New Products Flash Sale
Reply
Thread Tools
Old Mar 03, 2011, 03:31 PM
Registered User
Joined Jan 2010
495 Posts
Discussion
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.

Code:
/* 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
}
}
carl1864 is online now Find More Posts by carl1864
Reply With Quote
Sign up now
to remove ads between posts
Reply


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 09:19 AM
Question Remote controlled tower cranes Krillo Trader Talk 1 Oct 04, 2010 07:19 AM
Sold Scorpion IR Receiver and IR Remote Control - $10 shipped dswitkin Aircraft - Electric - Power Systems (FS/W) 2 Aug 30, 2009 09:20 PM
Discussion Cheap IR controlled IR Battle Tanks modfly RC Tanks 0 Dec 26, 2008 10:38 PM
Discussion remote controlled servo tester design? cmulder DIY Electronics 9 Jun 25, 2007 09:19 PM