TSOP giving different outputs for two similar codes.

Hello guys, I was trying to make a remote controlled bot using tata-sky dth remote,TSOP1738, l293dic arduino uno.

Initially I loaded the arduino library and ran the recdemo() to note all the outputs of the corresponding buttons of the remote. ie. the values obtained were :-88,89,90,91 for forward,left,right,back (in integer).

then i connected all the motor pins and used a simple if-else-if condition for basic movements of the bot, based on the input values i obtained above.

addition to that i also had set a print command to print the value i obtain on pressing the buttons while operating the bot.

Surprisingly, the value starts at 88 ie. forward (when i press forward) , then garbage values are printed even if i press the same button. Other values i obtained from recdemo() are not even occurring again.

I have no idea, what is happening, here is the code and screenshots.

ps:- I am confident these are not ir rays from outside, as no output is printed on no application of remote.

recdemo code:-

/*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

int RECV_PIN = 3;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    int r=results.value;
    Serial.println(r);
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}

rc controlled bot code:-

/*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

int motor1Pin1 = 9;    
int motor1Pin2 = 8;    
int irpin=4;
int motor2Pin1 = 11;    
int motor2Pin2 = 12;


int RECV_PIN = 3;

IRrecv irrecv(RECV_PIN);

decode_results results;



void left(){
  digitalWrite(motor1Pin1, LOW);   
    digitalWrite(motor1Pin2, HIGH);  
    
 
    digitalWrite(motor2Pin1,LOW);  
    digitalWrite(motor2Pin2, HIGH);
}

void back(){

  digitalWrite(motor1Pin1, HIGH);   
    digitalWrite(motor1Pin2, LOW);  
    
 
    digitalWrite(motor2Pin1, LOW);  
    digitalWrite(motor2Pin2, HIGH);
}

void forward(){
  digitalWrite(motor1Pin1, LOW);   
    digitalWrite(motor1Pin2, HIGH);  
    
 
    digitalWrite(motor2Pin1, HIGH);  
    digitalWrite(motor2Pin2, LOW); 
}

void right(){
  digitalWrite(motor1Pin1, HIGH);   
    digitalWrite(motor1Pin2, LOW);  
    
 
    digitalWrite(motor2Pin1,HIGH);  
    digitalWrite(motor2Pin2, LOW);
}





void setup()
{
  Serial.begin(9600);
  pinMode(irpin,INPUT);
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
   pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
 
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    int r=results.value;
    Serial.println(r);
    if(r==88){
      forward();
    Serial.println("forward");
    }
    
    
    else if(r==91){
      right();
    
    Serial.println("right");
    }
    else if(r==89){
      back();
    
    Serial.println("back");
    }
    else if(r==90){
      left();
    
    Serial.println("left");
    }
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}

You are not clear on what type of remote control you have. If the Sky remote is similar to the FoxTel remote here in Australia, then this blog post may be relevant for you.

I would imagine that when the motors are running you are getting some interference that causes the erroneous readings.

The supply voltage to the Arduino might fall when the motors are running. How do you have the motors connected?

How are you powering the Arduino/motors?

You should not be powering the Arduino from the motor supply, that will be anything but clean and
stable. One supply for motors, one for logic, is usually needed unless you have carefully designed
filtering on the power and a supply that doesn’t bat an eyelid under motor stall current conditions.