How to make an NRF24L01-controlled car using Arduino | NRF24L01 RC Car

How to make an NRF24L01-controlled car using Arduino | NRF24L01 RC Car

Hello and welcome back. In this project, we will learn how to make an NRF24L01-controlled car using Arduino. For that, we need two Arduino boards. I used an Arduino Nano board for the receiver and an Arduino Pro Mini board for the transmitter side in this project. The car can be controlled forward, backward, left, and right using a joystick module, which makes it very easy to drive. Specifically, I also added headlights to this car. Therefore, you can easily control it in a dark environment. If you want to know more details about the NRF24L01 module, please use this link.

Also, I designed two PCBs with JLCPCB for this project, one for the car chassis and one for the transmitter. Therefore, we can easily assemble this project. For the power supply, I used a 9V battery for the transmitter and two Li-ion batteries for the car. Also, this project is a great way to understand how wireless communication works with the NRF24L01 module.

Ok, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, let’s order PCBs for this project.

  • Click the “Instant Quote” button and upload the Gerber files, which you can download from the links below.
  • Car chassis Gerber file – Download
  • Transmitter Gerber file – Download
  • For this project, I ordered five black PCBs for the transmitter and five blue PCBs for the car chassis. After that, select the build time and shipping method. Finally, click “Save to Cart” and complete the payment.

Step 3

Thirdly, unbox the PCB package.

Step 4

After that, carefully solder the components to the car chassis and transmitter boards.

Step 5

After that, connect the wheels to the motors and mount them on the bottom of the PCB chassis.

Step 6

Next, pass the wires through the holes and connect them to the motor terminals. After that, install the caster wheel at the back side of the chassis.

Step 7

Afterward, install the battery holder and connect it to the DC power port.

Step 8

Now, connect the L293D motor driver IC, Arduino Nano board, and NRF24L01 module to the PCB car chassis. Then, connect the Arduino Pro Mini board, joystick module, and NRF24L01 module to the transmitter PCB.

Step 9

Afterward, connect the Arduino Nano board to your computer. Then, copy and paste the following receiver code into the Arduino IDE.

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

// === RF Setup ===
RF24 radio(9, 8);  // CE, CSN
const byte address[6] = "00001";

// === Motor pins ===
#define ENA 5
#define ENB 6
#define IN1 2
#define IN2 3
#define IN3 4
#define IN4 7

// === LED pins ===
#define FLED1 A0  // Headlights
#define FLED2 A1
#define BLED1 A2  // Brake light
#define BLED2 A3

// === Data structure from transmitter ===
struct Data {
  int VRx;  // Forward / Backward
  int VRy;  // Left / Right
  bool SW;  // Joystick button
};
Data data;

// === States ===
bool headlightsOn = false;
bool lastButtonState = false;

void setup() {
  Serial.begin(9600);

  // RF setup
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_LOW);
  radio.startListening();

  // Motor pins
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);

  // LEDs
  pinMode(FLED1, OUTPUT);
  pinMode(FLED2, OUTPUT);
  pinMode(BLED1, OUTPUT);
  pinMode(BLED2, OUTPUT);
}

void loop() {
  if (radio.available()) {
    radio.read(&data, sizeof(data));

    Serial.print("VRx: ");
    Serial.print(data.VRx);
    Serial.print(" | VRy: ");
    Serial.print(data.VRy);
    Serial.print(" | SW: ");
    Serial.println(data.SW);

    // === Toggle headlights on button press ===
    if (data.SW && !lastButtonState) {
      headlightsOn = !headlightsOn;
      delay(200); // debounce
    }
    lastButtonState = data.SW;

    digitalWrite(FLED1, headlightsOn ? HIGH : LOW);
    digitalWrite(FLED2, headlightsOn ? HIGH : LOW);

    // === Car movement ===
    handleMovement(data.VRx, data.VRy);

    // === Brake lights ===
    bool stoppedX = (data.VRx > 470 && data.VRx < 550);
    bool stoppedY = (data.VRy > 470 && data.VRy < 550);
    if (stoppedX && stoppedY) {
      digitalWrite(BLED1, HIGH);
      digitalWrite(BLED2, HIGH);
    } else {
      digitalWrite(BLED1, LOW);
      digitalWrite(BLED2, LOW);
    }
  }
}

// === Movement control ===
void handleMovement(int forwardBack, int leftRight) {
  int deadZone = 50;
  int center = 512; // both axes center

  // Speed based on distance from center
  int speedX = map(abs(forwardBack - center), 0, 512, 0, 255);
  int speedY = map(abs(leftRight - center), 0, 512, 0, 255);

  speedX = constrain(speedX, 0, 255);
  speedY = constrain(speedY, 0, 255);

  // Forward/backward
  if (forwardBack > center + deadZone) {
    analogWrite(ENA, speedX);
    analogWrite(ENB, speedX);
    Forward();
  } else if (forwardBack < center - deadZone) {
    analogWrite(ENA, speedX);
    analogWrite(ENB, speedX);
    Backward();
  }
  // Left/right treated same as forward/backward
  else if (leftRight > center + deadZone) {
    analogWrite(ENA, speedY);
    analogWrite(ENB, speedY);
    Left();
  } else if (leftRight < center - deadZone) {
    analogWrite(ENA, speedY);
    analogWrite(ENB, speedY);
    Right();
  } else {
    Stop();
  }
}

// === Motor controls ===
void Forward() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}

void Backward() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
}

void Left() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
}

void Right() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}

void Stop() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
}
  • Now, download the nRF24L01 library from the Library Manager in the Arduino IDE. To do this, go to Sketch → Include Library → Manage Libraries, then search for nRF24L01 and install the RF24 library.
  • Then, select the correct board and port in the Arduino IDE. After that, click the Upload button to upload the code to your Arduino Nano.

Step 10

Now, let’s set up the transmitter Arduino Pro Mini board to upload the program. For this, I used an Arduino UNO board as the programmer, but you can use another programmer if you prefer. First, connect the Arduino Pro Mini board to the Arduino UNO board. Then, connect the Arduino UNO board to the computer.

  • VCC –> 5v
  • GND –> GND
  • TX –> TX
  • RX –> Rx
  • Next, open an empty sketch in the Arduino IDE. Then, select the Arduino UNO board and the correct port. After that, click the Upload button to upload the program.

Step 11

Afterward, copy and paste the following program into the Arduino IDE.

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

RF24 radio(9, 8);  // CE, CSN
const byte address[6] = "00001";

// Define struct to send all data together
struct Data {
  int VRx;
  int VRy;
  bool SW;
};
Data data;

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_LOW);
  radio.stopListening();

  pinMode(2, INPUT_PULLUP);  // Joystick button
}

void loop() {
  data.VRx = analogRead(A0);
  data.VRy = analogRead(A1);
  data.SW = !digitalRead(2);  // Active LOW

  radio.write(&data, sizeof(data));  // Send everything at once

  Serial.print("Sent VRx: ");
  Serial.print(data.VRx);
  Serial.print(" | VRy: ");
  Serial.print(data.VRy);
  Serial.print(" | SW: ");
  Serial.println(data.SW);

  delay(100);
}
  • Now, select the Arduino Pro Mini board and the correct port. After that, click the Upload button to upload the program. While the IDE is displaying the uploading process, press the reset button on the Pro Mini board.

Step 12

After that, remove the Arduino UNO board and connect a 9V battery to the transmitter. Also, insert the batteries into the car.

Now, you can control the car however you like. Enjoy this project! The full video guide is below. We hope to see you in the next project. Have a great day!

How to make an NRF24L01-controlled car using Arduino | NRF24L01 RC Car

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *