Ir wont work with l293d

Hi everyone, I am currently making an rc car that will be controlled by a radio rc controller that I made, I am testing it with an IR remote and receiver but, the receiver will only receive one value than just stop all together.

I have:
-checked my wiring
-commented out everything about the motors than tested (the ir works when I do this)
-checked if the motors are working(they are)
-checked if the motor driver is working
-checked if my receiver code is correct(it is)
So now after all this testing I have come to the conclusion that something is blocking the code somewhere, but I cant find where. Please tell me your thoughts and please tell me if i'm being an idiot and its super obvious.

Here's the code!

#include <AFMotor.h>
#include <IRremote.h>
AF_DCMotor m1(1);
AF_DCMotor m2(2);
int rp = 6;

IRrecv ir(rp);

decode_results results;

void setup() {
IrReceiver.enableIRIn();
Serial.begin(9600);
m1.setSpeed(0);
m2.setSpeed(0);
}

void loop() {
if(ir.decode(&results))
{
ir.resume();
}
Serial.println(results.value);
delay(250);

uint8_t i;
if(results.value == 16748655 ){
Serial.println("Motor 1 FORWARD 100% speed");
m1.run(FORWARD);
m1.setSpeed(speed(100));
delay(3000);
}
if(results.value == 16748655 ){
Serial.println("Motor 2 FORWARD 100% speed");
m1.run(FORWARD);
m1.setSpeed(speed(100));
delay(3000);
Serial.println("Motor 2 FORWARD 100% speed");
m2.run(FORWARD);
m2.setSpeed(speed(100));
delay(3000);
}

if(results.value == 4294967295){
m1.run(RELEASE);
Serial.println("M1 RELEASE");
delay(3000);

m2.run(RELEASE);

Serial.println("M2 RELEASE");
delay(3000);
}

if(results.value == 16769055){
Serial.println("Motor 1 FORWARD 100% speed");
m2.run(FORWARD);
m2.setSpeed(speed(100));
delay(3000);
}
else{
Serial.println(results.value);
delay(250);
}
int speed(int b)
{
return map(b, 0, 100, 0, 255);

}
Here's a photo of my setup!
IMG_0778
Here's a pic of what happens with the serial monitor
image
This will happen but than no other values are printed.

Thanks - Luke

Shouldn't you have made a copy of results.value here?

Please remember to use code tags when posting code

What do you mean by make a copy of results.value?

Use some example code to see if the IR system even works. If it does, modify it to work with your car.

I did a project using these exact same building blocks (IR and an L293D) a while ago, but I don't really remember the exact code, and it's probably wiped from my HDD. In any case, this is what I did, and it worked for me.

Thank you @IceChes, I got the ir to work by following your suggestion, now I can’t figure out how to get the motors to work with it,
Suggestions please(now I’m very fearful for the problems that will come with using my radio etc controller :))

By making a copy, I mean a variable containing the value of results.value, because every time you call the decode function (every time through loop ()) , you run the risk of changing the value of results.value.

You have to break the task into manageable bits: for example

receive a code
decode it (choose an action)
perform the chosen action
.....
I know it sounds trivial, but most people need practice doing this kind of breakdown because they don't need to do it in their everyday lives.

Press buttons on the controller. Log what they output on serial. Then use IF statements like this:

if (results.value = buttoncode){ //results.value is the button code from the controller, buttoncode would be a fixed number matching your desired button code.
 digitalWrite(L293D_PIN_1, 1);
 digitalWrite(L293D_PIN_2, 0);
 digitalWrite(L293D_PIN_3, 1);
 digitalWrite(L293D_PIN_4, 0);
}
else{
 digitalWrite(L293D_PIN_1, 1);
 digitalWrite(L293D_PIN_2, 1);
 digitalWrite(L293D_PIN_3, 1);
 digitalWrite(L293D_PIN_4, 1);
}

...and study the IR examples closely. Guaranteed you will find the same logic in most of them. If I were you, I would stick with the library you've already used in your first post, just get to know it better. It's better then re-creating all the work done by the library, line by line.

Oops.

Did I mess up syntax? I might have.

No, the syntax was fine.
You messed up the semantics.

1 Like

Thank you sooooo much I haven’t tried this yet buuuut it makes sense and I think it will work!