I can't figure out how to get my IR to tell my robot to drive.

Hello
I have built a robot using a H bridge and I can’t figure out how to control it using my remote.

#include <IRremote.h>
#include <IRremoteInt.h>



int IRpin = 9;  // pin for the IR sensor
IRrecv irrecv(IRpin);
decode_results results;





int enableA = 11;
int pinA1 = 6;
int pinA2 = 5;

int enableB = 10;
int pinB1 = 4;
int pinB2 = 3;



long inches;//ultrasonic

void setup() {
  pinMode(enableA, OUTPUT);
  pinMode(pinA1, OUTPUT);
  pinMode(pinA2, OUTPUT);

  pinMode(enableB, OUTPUT);
  pinMode(pinB1, OUTPUT);
  pinMode(pinB2, OUTPUT);

  Serial.begin(9600);
  irrecv.enableIRIn();
}

//enable motors
void motorAOn()
{
  digitalWrite(enableA, HIGH);
}

void motorBOn()
{
  digitalWrite(enableB, HIGH);
}

//disable motors
void motorAOff()
{
  digitalWrite(enableB, LOW);
}

void motorBOff()
{
  digitalWrite(enableA, LOW);
}

//motor A controls
void motorAForward()
{
  digitalWrite(pinA1, HIGH);
  digitalWrite(pinA2, LOW);
}

void motorABackward()
{
  digitalWrite(pinA1, LOW);
  digitalWrite(pinA2, HIGH);
}

//motor B controls
void motorBForward()
{
  digitalWrite(pinB1, HIGH);
  digitalWrite(pinB2, LOW);
}

void motorBBackward()
{
  digitalWrite(pinB1, LOW);
  digitalWrite(pinB2, HIGH);
}

//coasting and braking
void motorACoast()
{
  digitalWrite(pinA1, LOW);
  digitalWrite(pinA2, LOW);
}

void motorABrake()
{
  digitalWrite(pinA1, HIGH);
  digitalWrite(pinA2, HIGH);
}

void motorBCoast()
{
  digitalWrite(pinB1, LOW);
  digitalWrite(pinB2, LOW);
}

void motorBBrake()
{
  digitalWrite(pinB1, HIGH);
  digitalWrite(pinB2, HIGH);
}
//Define high-level H-bridge commands
void enableMotors()
{
  motorAOn();
  motorBOn();
}

void disableMotors()
{
  motorAOff();
  motorBOff();
}

void forward(int time)
{
  motorAForward();
  motorBForward();
  delay(time);
}

void backward(int time)
{
  motorABackward();
  motorBBackward();
  delay(time);
}

void turnLeft(int time)
{
  motorABackward();
  motorBForward();
  delay(time);
}

void turnRight(int time)
{
  motorAForward();
  motorBBackward();
  delay(time);
}

void coast(int time)
{
  motorACoast();
  motorBCoast();
  delay(time);
}

void brake(int time)
{
  motorABrake();
  motorBBrake();
  delay(time);
}
//Define low-level H-bridge commands



void loop() {

 
  analogWrite(enableA, 200);
  analogWrite(enableB, 200);



  if (results.value == 0xFF18E7) { 
    analogWrite(enableA, 255);
    analogWrite(enableB, 255);
    forward(1);
    delay(100);
  }

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

When I upload the code above a press 2 on my remote(IR code: FF18E7)My Robot does nothing.
If anyone could help it would be greatly appreciated.

Hi,
One thing at a time...

Does the IR remote receiver receive your signals as you expect? Try the first code example HERE.

There is an example of code running a robot with IR Remote HERE

I have a code that receives the signal and prints it to the serial monitor so I know for sure a signal is going to the robot and it is being read.

#include <IRremote.h>
#include <IRremoteInt.h>


int RECV_PIN = 9;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); 
}

void loop()
{
  if (irrecv.decode(&results))
    {
     Serial.println(results.value, HEX);
     irrecv.resume();
    }
}

You have this line in the test code and not in the other, so your test code is actually reading the ir, and the motor driver code isn't.

 if (irrecv.decode(&results))

So I have just changed the code but it still doesn't work.

void loop() {

  
  analogWrite(enableA, 200);
  analogWrite(enableB, 200);

if (irrecv.decode(&results)){

  if (results.value == 0xFF18E7) { 
    analogWrite(enableA, 255);
    analogWrite(enableB, 255);
    digitalWrite(pinA1, HIGH);
    digitalWrite(pinA2, LOW);
    digitalWrite(pinB1, HIGH);
    digitalWrite(pinB2, LOW);
    delay(100);
  }
  irrecv.resume(); 
}
  
}

Put a serial print in there then, and see if the code's being received.

I also note that in your test code, and an old similar sketch of mine that worked, the irrecv.resume() is at the top not at the end, but I'm not sure if that's significant?

I put the serial print in and i just found that for some odd reason what the arduino is receiving is different in each code when i pressed the button.Thanks for you help.

Ah ok.... some protocols do that. I think it's to do with differentiating repeat presses or something.

I found in mine for example, that I needed lines like these, once I found out what was being sent:

if (results.value == 3148 || results.value == 1100) { 
...
if (results.value == 1041 || results.value == 3089) {
...
if (results.value == 1040 || results.value == 3088) {

What do || mean??

Boothy920Q:
What do || mean??

OR

@Boothy920Q
You might benefit from reviewing items on this page.

https://www.arduino.cc/en/Reference/HomePage

.

Thank you