In this post you are going to learn about how to build an Arduino wireless control robot car. We will build both transmitter and receive.

In this post you are going to learn about how to build an Arduino wireless control robot car. We will build both the transmitter and receiver sides.

The transmitter side will include an Arduino nano, joystick module and NRF24L01 to send the data wirelessly. The receiver side will include Arduino nano, NRF24L01 to receive the data and L293D motor driver IC to control the motors. Both the transmitter and receiver circuits will be powered by 9V batteries.

Components Required

The components you are going to require for this project are as follows

Transmitter side

  • Arduino Nano
  • Joystick Module
  • NRF24L01
  • 100uf capacitor
  • 3 pin Slide Switch
  • 2 pin terminal block
  • 9V battery

Receiver side

  • Arduino Nano
  • NRF24L01
  • 100uf capacitor
  • 0.1uf Capacitor
  • 10uf capacitor
  • 3 pin Slide Switch
  • 2 pin terminal blocks (3 pieces)
  • L293D Motor Driver IC
  • 9V battery

Circuit Diagram

The main part of both transmitter and receiver circuits is Arduino nano which is powered by the 9V battery. Then we have got NRF24L01 module on both sides to communicate wirelessly.

Joystick module on the transmitter side will be used to get the x and y values that will be sent to the receiver side and will be used to control the motors. L293D motor driver IC on the receiver side will also get power from 9v power supply and will control the motors.

Using the above circuit diagram, you can make the circuit on breadboard to make sure everything works how you want it to.

PCB Design

After making sure everything works fine on the breadboard, I have designed the PCB on EasyEDA. EasyEDA is an open-source online PCB Design Tool.

Here’s a link to the PCB design of this project. After designing the PCB’s, I generated the Gerber files needed for manufacturing of PCB’s.

You can download the Gerber files through following links

Ordering the PCBs

Now we have got the PCB design and it’s time to order the PCB’s. For that, you just have to go to JLCPCB.com, and click on “QUOTE NOW” button.

JLCPCB are also sponsor of this project. JLCPCB (ShenzhenJLC Electronics Co., Ltd.), is the largest PCB prototype enterprise in Chinaand a high-tech manufacturer specializing in quick PCB prototype and small-batch PCB production. You can order a minimum of 5 PCBs for just $2.

To get the PCB manufactured, upload the gerber file you downloaded in the last step. Upload the.zip file or you can also drag and drop the gerber files.

After uploading the zip file, you’ll see a success message at the bottom if the file is successfully uploaded.

You can review the PCB in the Gerber viewer to make sure everything is good. You can view both top and bottom of the PCB.

After making sure our PCB looks good, we can now place the order at a reasonable price. You can order 5 PCBs for just $2 but if it’s your first order then you can get 10 PCBs for $2.

To place the order, click on “SAVETO CART” button.

My PCBs took 2 days to get manufactured and arrived within a week using DHL delivery option. PCBs were well packed and the quality was really good.

After assembling everything and connecting the motors to it, here is how it looks like.

Code

Now let’s move on the code side.

Transmitter Code

First, we need to include the SPI and RF24 library for wireless communication. Then we need to define the digital pins for NRF24L01 module and analog pins for joystick module. After that we need to define radio object, communication address for it and an array to store joystick module values in it.

In the setup function, we need to initialize the serial and radio communication.

In the loop function, we first read the values from the joystick module and stored them in the array. After that, using the radio.write() function we will send that message to the receiver. The first argument in this function is the message and the second argument is the number of bytes present in that message.

The radio.write() function returns a bool and it is true then it means that the data reached the receiver and if it returns false, data has been lost.

Here is the complete Transmitter Code.

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

const int pinCE = 7;
const int pinCSN = 8;
RF24 radio(pinCE, pinCSN);

int Array[4];
const uint64_t pipe = 0xF0F0F0F0E1LL;

const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output

void setup()
{
  Serial.begin(9600);
  // Define the radio communication
  radio.begin();
  radio.setAutoAck(false);
  radio.enableAckPayload();
  radio.setRetries(5, 15);
  radio.openWritingPipe(pipe);
  radio.stopListening();
  radio.printDetails();
}

void loop()
{

  Array[0] = analogRead(X_pin);
  Array[1] = analogRead(Y_pin);

  Serial.println("Now sending data... ");

  if (!radio.write( &Array, sizeof(Array))) {
    Serial.println("delivery failed");
    Serial.println();
  }
  else {
    Serial.println("Send successful.");
    Serial.println();
  }
}
    

Receiver Code

On the receiver side, we also need to include the SPI and RF24 libraries for wireless communication. Then we need to define the digital pins for NRF24L01 module and l293d motor driver IC and some variables.  After that we need to define radio object, communication address for it and an array to store incoming values in it.

In the setup function, we need to initialize the serial and radio communication. Then we need to define some pins of L293D as output pins.

In the loop function, we first check if some information is available or not. If it will be there then we will store it in variables. After that we will control motors according to these values.

Here is the complete Receiver Code.

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

const int pinCE = 7;
const int pinCSN = 8;
RF24 wirelessSPI(pinCE, pinCSN);

int gotArray[4];
const uint64_t pipe = 0xF0F0F0F0E1LL;

//L293D
//Motor A
const int motorPin1  = 5;  // Pin 14 of L293
const int motorPin2  = 6;  // Pin 10 of L293
//Motor B
const int motorPin3  = 4; // Pin  7 of L293
const int motorPin4  = 3;  // Pin  2 of L293

int X_value;
int Y_value;

void setup()
{
  Serial.begin(9600);
  wirelessSPI.begin();
  wirelessSPI.setAutoAck(false);
  wirelessSPI.enableAckPayload();
  wirelessSPI.setRetries(5, 15);
  wirelessSPI.openReadingPipe(1, pipe);
  wirelessSPI.startListening();
  wirelessSPI.printDetails();

  //Set pins as outputs
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
}

void loop()
{
  while (wirelessSPI.available()) {
    wirelessSPI.read( &gotArray, sizeof(gotArray) );
    X_value = gotArray[0];
    Y_value = gotArray[1];
    Serial.println("Recieved array:");
    Serial.println(X_value);
    Serial.println(Y_value);
    Serial.println();
  }
  if (X_value > 450 && X_value < 650 && Y_value > 450 && Y_value < 650) {
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, LOW);
  }

  else if (Y_value > 1000 ) {
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    digitalWrite(motorPin3, HIGH);
    digitalWrite(motorPin4, LOW);
  }

  else if (Y_value < 100 ) {
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
    digitalWrite(motorPin3, LOW);
    digitalWrite(motorPin4, HIGH);
  }

  else if (X_value > 1000) {
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
  }
  else if (X_value < 100) {
    digitalWrite(motorPin3, HIGH);
    digitalWrite(motorPin4, LOW);
  }
  delay(10);
}
    

Video

For any questions, feel free to ask in the comment section.

Aqib _
For Custom Projects, hire me at https://www.freelancer.pk/u/Muhammadaqibdutt