Remote Controlling Arduino Robot Shield

Remote Controlling Arduino Robot Shield © CC0

Have an old controller no longer being used? Re purpose it to control something it was not intended to be used for.

  • 245 views
  • 0 comments
  • 1 respect

Components and supplies

About this project

Received my board of education Arduino robot shield last Friday and the first thing I wanted to try after assembling it was to control it with an IR remote using Ken Shirrifs IR Library.

The motors on the robot are 360 degree servos that are controlled by sending them a digital pulse ranging in duration from 1300 to 1700 microseconds every 20 milliseconds.  The width of the pulse determines the speed and direction they rotate.  1500 would be no motion at all, 1300 full speed counter clockwise and 1700 full speed counter clockwise.  While this is modifying the width of the pulse it is not the same as the PWM functions found in the Arduino library.

When polling for commands from the IR receiver I found that that this particular remote requires me give it at least 175 ms before attempting to read its next transmission.   That, combined with the IR remote being single channel makes for a choppy RC because within 200 ms the servos have already repeated the last command 10 times.

Oh and if you are wondering why no beeping from the Robot it is because the tone function is unable to access TIMER2 because it is being used by the IR Library   The servo library uses TIMER1.

Here is a short video:

Code

Remote Control RobotC/C++
/*
 * Remote control Robot
 *
 */

#include <IRremote.h>
#include <Servo.h> 


int RECV_PIN = 2;

/* this is for the old clarion remote controller I am using
 * the button names correspond with the names on the controller
 * but not with the function I will be using them for.  Hence
 * names like "backbutton" for what will be used to command
 * the robot to turn left
 */
 
const long backbutton = 0x6106C03F;		// Turn Left
const long uparrow = 0x6106D827;		// Forward
const long menu = 0x6106D02F;			// Turn Right
const long leftarrow = 0x61066897;	// Spin Left
const long ok = 0x610610EF;			// pause
const long rightarrow = 0x6106E817;	// Spin Right
const long downarrow = 0x6106B847;	// backwards

IRrecv irrecv(RECV_PIN);
decode_results results;
Servo servoLeft;        // Declare Left Servo
Servo servoRight;       // Declare Right Servo
int lastcommand;


void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  servoLeft.attach(13);
  servoRight.attach(12);
  servoLeft.writeMicroseconds(1500);
  servoRight.writeMicroseconds(1500);
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    if (results.value == backbutton)    // Turn Left
    {
      TurnLeft(20);
    } 
    else if (results.value == uparrow)  // Move Forward, ramp 
    {
      MoveForward(200); 
    }
    else if (results.value == menu)    // Turn Right
    {
      TurnRight(20);
    }
    else if (results.value == leftarrow)  // Spin Left
    {
      SpinLeft(40);
    }
    else if (results.value == ok)   // do nothing
    {
      StayStill();
    }
    else if (results.value == rightarrow)   // Spin right
    {
      SpinRight(40);
    }
    else if (results.value == downarrow)   // move backwards
    {
      MoveBackwards(200);
    }
  } 
  else 
  {
    StayStill();
  }
  irrecv.resume();
  delay(200);
}


void MoveForward(int msTime)
{
  maneuver(100, 100, msTime);
}

void MoveBackwards(int msTime)
{
  maneuver(-100,-100, msTime);
}

void SpinRight(int msTime)
{
  maneuver(100, -100, msTime);
}

void TurnRight(int msTime)
{
  maneuver(100, 0, msTime);
}

void StayStill()
{
  maneuver(0, 0, 20);
}

void SpinLeft(int msTime)
{
  maneuver(-100, 100, msTime);
}
void TurnLeft(int msTime)
{
  maneuver(0, 100, msTime);
}

void maneuver(int speedLeft, int speedRight, int msTime)
{
  // speedLeft, speedRight ranges: Backward  Linear  Stop  Linear   Forward
  //                               -200      -100......0......100       200
  servoLeft.writeMicroseconds(1500 + speedLeft);   // Set Left servo speed
  servoRight.writeMicroseconds(1500 - speedRight); // Set right servo speed
  if(msTime==-1)                                   // if msTime = -1
  {                                  
    servoLeft.detach();                            // Stop servo signals
    servoRight.detach();   
  }
  delay(msTime);                                   // Delay for msTime
}

Comments

Similar projects you might like

Controlling a low-cost robot with two potentiometers

by Pierre Ruffy & Roxane Alexandre

  • 1,372 views
  • 0 comments
  • 1 respect

MeArm Robot Arm - Your Robot - V1.0

Project tutorial by Benjamin Gray

  • 19,326 views
  • 3 comments
  • 35 respects

Controlling A Roomba Robot With Arduino And Android Device

Project tutorial by MJRoBot

  • 11,228 views
  • 4 comments
  • 12 respects

Controlling an Arduino Turret with IR Remote

Project tutorial by Team RobotGeek Projects Team

  • 3,660 views
  • 0 comments
  • 16 respects

Controlling Robot Over Bluetooth Using Xbox Steering Wheel

Project tutorial by Roboro

  • 5,107 views
  • 1 comment
  • 20 respects
Add projectSign up / Login