On infrared remote control of a robot.

Hi Arduino community!

I am new to Arduino, and have been using mine for the past few days, I have build a simple three wheeled robot and am now attempting to control it with an IR remote.

I am using the IR library from the playground, and I got it to work, my only problem is I want the robot to stop doing what it is doing, say going forwards, turning, whatever when I release the button.

Funny thing is at one point I had the IR sensor in such a position that it was picking up random garbage data, so it did what I wanted, when I held down the button, the motor stayed on, when I let go, it stopped, but I had to move the sensor and I can't replicate this effect.

Any Ideas would be much appreciated.
Anybodysguess

anybodysguess:
Any Ideas would be much appreciated.

Ummm. Put the sensor back in the position in which it worked?

I mean what do you want us to say here?

Put the sensor back in the position in which it worked?

In that position the sensor faced forwards, away from the remote, so it didn't work.

And this is not an ideal solution because the sensor isn't "supposed" to output garbage data like that, it has a built in modulator and only "talks" to the Arduino when it gets a signal from the remote.

I was wondering if there was a code solution that could make it work, the remote sends the same code over and over while the button is pressed, very fast. So is there a way to see if a code is constantly being broadcast, and keep going forwards, or right or left, but stop going in that direction when that signal is no longer being broadcast?

I would even be open to a hardware solution IE put a ir led on the arduino and have it feed it's own low powered signal into the IR sensor, with a high enough resistor that the remote easily over rides its signal, but I don't think the arduino can transmit IR and receive IR at the same time.

anybodysguess:
Hi Arduino community!

I am new to Arduino, and have been using mine for the past few days, I have build a simple three wheeled robot and am now attempting to control it with an IR remote.

yep... follow me ! :slight_smile:

anybodysguess:
I am using the IR library from the playground,

is that the Ken Shiriff library - it's meant to be simple and easy to use, but it also reads "random garbage data" - i wondered whether it was a "cheap remote" but i learned it was valid transmission.

if you want to get into more "raw" code; try this good tutorial from adafruit;

that really helped me to understand the basics of IR-signals.

anybodysguess:
and I got it to work, my only problem is I want the robot to stop doing what it is doing, say going forwards, turning, whatever when I release the button.

that sounds like an issue of how you are making the command after receiving the "remote signal" - you need to post your code *use the CODE tags ; so that people can then comment on it.

My code is very simple, and probably the wrong way to code :astonished: but I've only been doing this for a couple of days, before that a couple of years ago I did some batch programming, but that's it.

And yes it's Ken Shiriff library. It works very well for me, I'm controlling my Arduino with a RCA universal remote, programmed to "sony" codes. I don't really have any problems with it, I just want to figure out how to make my robot stop when I let go of the forwards key, and I can't see any way to "listen" to see if the remote is still transmitting.

#include <IRremote.h>
 
int RECV_PIN = 11;
int ledPin =  13;
int right = 5;
int left = 6;
int motorPin = 9;
 
IRrecv irrecv(RECV_PIN);
 
decode_results results;
 
void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  
  pinMode(ledPin, OUTPUT);
  
  pinMode (motorPin, OUTPUT);
  
  pinMode (left, OUTPUT);
  
  pinMode (right, OUTPUT);
}
 
void loop() {
 
  if (irrecv.decode(&results)) {
    Serial.println(results.value, DEC);
  
  
    
    if(results.value == 144) 
    {
      digitalWrite(motorPin, HIGH);  // turn motor on
      digitalWrite(left, LOW);
      digitalWrite(right, LOW);
    }
      
      
       if(results.value == 1168)
      { 
        digitalWrite(left, LOW);
        delay(50);
        digitalWrite(right, HIGH); 
      }
          if(results.value == 3216)
      {    
            digitalWrite(right, LOW);
            delay(50);
            digitalWrite(left, HIGH);
      }     
      
      
       if(results.value == 2192)
      {    
        digitalWrite(motorPin, LOW);    
        digitalWrite(right, LOW);
        digitalWrite(left, LOW);
      }     
    
  
  

     
  
    irrecv.resume(); // Receive the next value
  }
}

anybodysguess:
...
...
I just want to figure out how to make my robot stop when I let go of the forwards key, and I can't see any way to "listen" to see if the remote is still transmitting.
...

that would be an issue with the way the code is written.

when i first started, to make it simple - i just used a delay(1000); and then issued a stop command.
but then you'd have to keep pressing the button every second or so.

i haven't used that library extensively, but i recall getting that "random garbage data" you mentioned, it was other HEX codes, aside from the one you want, as well as some "FFFFFF"s , right ? those are actually the codes/data that tell you the button is still being pressed - you could adjust your code to work to that.

actually, even simpler would be to assign a "stop" command to another button on the remote.
you don't have to keep the button pressed for the robot to move forwards(etc) right ?