IR sensor doesn't receive updated commands

Our robot (driven by Arduino UNO) is controlled by a remote control. The remote control is programmed correctly and the robot follows its commands. However, since the robot is dragging a heavy load, it can't always execute the command (such as turning). When the robot doesn't execute the command, the remote control stops controlling the robot's movements and the programmed STOP button on the remote stops working.
Edit: Some more context:
We are using an Arduino UNO connected to a dbh01c motor driver that is itself connected to 2*[12V, 7Ah] batteries to drive two 24V DC motors.
This is the code used:

#include <IRremote.h>
int RECV_PIN = 13;
IRrecv irrecv(RECV_PIN);
decode_results results;

//chassis motor
int IN1_A = 8;
int IN2_A = 7;
int EN_A= 6;
int IN1_B = 2;
int IN2_B = 12;
int EN_B= 5;

//blade motor
int in1 = 10;
int in2 = 11;
int enA = 9;

void setup()
{

  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver

pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(enA, OUTPUT);

pinMode (EN_A, OUTPUT);
pinMode (IN1_A, OUTPUT);
pinMode (IN2_A, OUTPUT);
pinMode (EN_B, OUTPUT);
pinMode (IN1_B, OUTPUT);
pinMode (IN2_B, OUTPUT);
}


void loop()
{

  if (irrecv.decode(&results))
    {
      Serial.println(results.value, HEX);
      irrecv.resume(); // Receive the next value
    } 
    if (results.value==0x1E108) 
    {
      Forward();
    }
  if (results.value==0x9E108) 
    {
      Backward();
    }
  if (results.value==0xDE108 ) 
    {
      Right();
    }
  if (results.value==0x5E108 )
    {
      Left();
    }
  if (results.value==0x540A) 
    {
      Stop();
    }
      
    if (results.value==0x240A) {
     BladeStart();
 }  

   if (results.value==0x640A) {
     BladeStop();
 }  
    if (results.value==0xA90) {
     BladeStop();
 }  
 } 

void Forward()
{
  digitalWrite (IN1_A, LOW);
  digitalWrite (IN1_B, LOW);
  digitalWrite (IN2_A, HIGH);    
  digitalWrite (IN2_B, HIGH);

  analogWrite(EN_A, 200);
  analogWrite(EN_B, 200);

}

void Backward()
{
  digitalWrite (IN1_A, HIGH);
  digitalWrite (IN1_B, HIGH);
  digitalWrite (IN2_A, LOW);    
  digitalWrite (IN2_B, LOW);
  analogWrite(EN_A,150);
  analogWrite(EN_B,150);


}

void Left()
{
  digitalWrite (IN1_A, LOW);
  digitalWrite (IN1_B, HIGH);
  digitalWrite (IN2_A, HIGH);    
  digitalWrite (IN2_B, LOW);

  analogWrite(EN_A, 150);
  analogWrite(EN_B, 180);
  delay(800);
  analogWrite(EN_A, 0);
  analogWrite(EN_B, 0); 
}

void Right()
{
  digitalWrite (IN1_A, HIGH);
  digitalWrite (IN1_B, LOW);
  digitalWrite (IN2_A, LOW);    
  digitalWrite (IN2_B, HIGH);

  analogWrite(EN_A, 150);
  analogWrite(EN_B, 180);
  delay(1000);
  analogWrite(EN_A, 0);
  analogWrite(EN_B, 0);
}

void Stop()
{
  analogWrite(EN_A,0);
  analogWrite(EN_B,0);  
  analogWrite(enA, 0);
}

void BladeStart()
{
  analogWrite(enA, 70);
 	digitalWrite(in1, HIGH);
	digitalWrite(in2, LOW);
  
}

void BladeStop()
{
  analogWrite(enA, 0);
}

void SlowStop()
{
  for (int i=200; i>=0;i--)
  {
    analogWrite(EN_A,i);
    analogWrite(EN_B,i); 
    delay(20); 
  }
}

The bug is in line 42 of your code.

That's the best answer you can get until you show your code.

Ok, but you should provide more information, please:

  1. post a diagram of the project, complete with power supply kind and connections
  2. post links of your exact motors brand and version
  3. show us the code (put it inside "code" tags)
  4. define "heavy load"

Sounds like you are using blocking code. That is to say that in executing your robot's tasks, the IR input is ignored. Consider how you could change this by polling the sensor mid-task. Check out using millis() to time your events.

Also, post your code for any meaningful help.

Code added to original question

Thanks for the suggestion! Code added to original question.

First, you have a pretty bad code indentation and this makes the code not very easy to be read, and is source of mistakes. So you simply need to press Ctrl-T and the IDE will do it for you.

Said that, I suspect the indentation is the main cause of this malfunction. You have this "if":

  if (irrecv.decode(&results))
    {
      Serial.println(results.value, HEX);
      irrecv.resume(); // Receive the next value
    } 

It means "if a signal has been received, decode it and enter the if block". So it correctly show, the value and waits for another signal. But nothing more.
So all the next "if(results.value == ..." are always executed, even if no other signals will be received. Moreover, I suspect the "irrecv.resume()" statement could reset the receiver buffer.

When you receive a new IR signal/packet, you must process it inside the curly brackets of the first if()! Like this:

void loop()
{
  if (irrecv.decode(&results))
  { 
    Serial.println(results.value, HEX);
    if (results.value == 0x1E108)
    {
      Forward();
    }
    if (results.value == 0x9E108)
    {
      Backward();
    }
    if (results.value == 0xDE108 )
    {
      Right();
    }
    if (results.value == 0x5E108 )
    {
      Left();
    }
    if (results.value == 0x540A)
    {
      Stop();
    }

    if (results.value == 0x240A) {
      BladeStart();
    }

    if (results.value == 0x640A) {
      BladeStop();
    }
    if (results.value == 0xA90) {
      BladeStop();
    }
    irrecv.resume(); // <--- THIS AT THE END!
  } // <--- MOVE HERE THE CLOSE CURLY BRACKET
}

There are some other possible changes to improve the robot's responsiveness (e.g. getting rid of delays and using millis() with a "finite state machine" approach), but for now it's enough :wink:

Thank you for your suggestions! We implemented them.
When we press one button on the remote control, the IR receiver takes one input and then any other button pressed afterwards give random code on the serial monitor. So only the first button pressed works when the whole circuit is connected: the motors are connected to the batteries (Lead Acid 12V).

But when the circuit is disconnected and I’m only working with the IR receiver circuit (arduino- breadboard- IR receiver) it works fine (the serial monitor shows the correct codes when we press buttons on the remote control). What could be the source of this?

The motors may cause EMP with unpredictable results. Weak breadboard connections also can cause trouble.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.