RF remote control robot for school project

Hello I am a 8th grade student and I like working with Arduino so for my school project I decided to make a remote control car with RF and a Husky lens 2. I am having trouble coding the RF and huskgylens to work with my robot so I made sure it worked first and it could go forwards and backwards fine, but then when I tried to use a IR remote it did not work. I am using 2 tt motor driven by a 9v battery through a l293D Please help.

RF and IR are not the same thing. So you need to give some more details.

It might help if you showed a schematic / wiring diagram (you can drag an image into a reply) and your code (using code tags as described in https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966#posting-code-and-common-code-problems.

Welcome to the forum

Please post your best effort at writing the test sketch, using code tags when you do, and describe the problems that you have

Please post a schematic of your project showing how each of the components of it are connected and powered. A 'photo of a hand drawn circuit diagram is good enough

To post images etc. you need trust level 1, you can get there by:

  • Entering at least 5 topics
  • Reading at least 30 posts
  • Spend a total of 10 minutes reading posts

Users at trust level 1 can...

  • Use all core Discourse functions; all new user restrictions are removed
  • Send PMs
  • Upload images and attachments

I am currently using this code for IR before I try RF but it is not working

#include <IRremote.h>

// Motor 1
const int motor1Pin1 = 8;
const int motor1Pin2 = 7;
const int enable1Pin = 9;

// Motor 2
const int motor2Pin1 = 5;
const int motor2Pin2 = 4;
const int enable2Pin = 3;

// IR Receiver
const int RECV_PIN = 6;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(enable1Pin, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);
  pinMode(enable2Pin, OUTPUT);

  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    unsigned long value = results.value;
    
    // Replace hex codes with those from your remote
    if (value == 0xFF18E7) { // Forward
      moveForward();
    } else if (value == 0xFF4AB5) { // Backward
      moveBackward();
    } else if (value == 0xFF38C7) { // Stop
      stopMotors();
    }
    
    irrecv.resume(); // Receive the next value
  }
}

void moveForward() {
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  analogWrite(enable1Pin, 200); // Speed
  
  digitalWrite(motor2Pin1, HIGH);
  digitalWrite(motor2Pin2, LOW);
  analogWrite(enable2Pin, 200);
}

void moveBackward() {
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(enable1Pin, 150);

  digitalWrite(motor2Pin1, LOW);
  digitalWrite(motor2Pin2, HIGH);
  analogWrite(enable2Pin, 150);
}

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

More details needed.

Add some Serial.print()s to see what, if anything, is being received. What are you using to transmit the IR ? Which Arduino board are you using ?

Is the battery a PP3 by any chance ? They are designed for use by low current devices. Have you tried measuring its voltage whilst under load ?

The IR receiver seems to be working, and the light turns on, but the motors do not turn on. The battery I am using is an Amazon Basics 9V battery.

As I suspected, a PP3

Totally unsuited to power the car

Have you measured its voltage under load ?

I have not, no.
What battery should I use

You could still use the 9v battery, but you would need at least 3 of them in parallel to provide the needed current. OR if you have time, get yourself a 9.6V rechargeable battery pack like this HERE

You can use that battery pack alone to power the whole project or use a separate 9V for just the arduino. Just make sure if you go with the separate batteries, that the ground wires are connected.

You are using an old library header. Read the warning here: Arduino-IRremote/src/IRremote.h at master · Arduino-IRremote/Arduino-IRremote · GitHub

The new one is IRremote.hpp and it has changed the call to decode to: if (IrReceiver.decode()) (removing the ampersand)

Could I use a rechargeable lithium polymer power bank, with these specs?
Input: DC 5.0V/2.0A · Output: DC 5.0V/2.1A · Capacity: 3.7V/3000mAh.

Never put batteries in parallel.

The capacity spec makes no sense.
Most people use two 18650 batteries in series to power the motors.