Aqib
Published

Arduino Wireless Control Robot Car

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.

BeginnerFull instructions provided2 hours997
Arduino Wireless Control Robot Car

Story

Read more

Schematics

Arduino wireless control robot car circuit diagram

Code

Code snippet #1

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

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

RF24 radio(pinCE, pinCSN);
const uint64_t pipe = 0xF0F0F0F0E1LL;

int Array[4];

Code snippet #10

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

const int pinCE = 7;
const int pinCSN = 8;

//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;

RF24 radio(pinCE, pinCSN);

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

Code snippet #11

Plain text
void setup()
{
  Serial.begin(9600);
  // Define the radio communication
  radio.begin();
  radio.setAutoAck(false);
  radio.enableAckPayload();
  radio.setRetries(5, 15);
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  radio.printDetails();

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

Code snippet #12

Plain text
void setup()
{
  Serial.begin(9600);
  // Define the radio communication
  radio.begin();
  radio.setAutoAck(false);
  radio.enableAckPayload();
  radio.setRetries(5, 15);
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  radio.printDetails();

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

Code snippet #13

Plain text
void loop()
{
  while (radio.available()) {
    radio.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);
}

Code snippet #14

Plain text
void loop()
{
  while (radio.available()) {
    radio.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);
}

Code snippet #15

Plain text
#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);
}

Code snippet #16

Plain text
#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);
}

Code snippet #2

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

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

RF24 radio(pinCE, pinCSN);
const uint64_t pipe = 0xF0F0F0F0E1LL;

int Array[4];

Code snippet #3

Plain text
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();
}

Code snippet #4

Plain text
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();
}

Code snippet #5

Plain text
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();
  }
}

Code snippet #6

Plain text
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();
  }
}

Code snippet #7

Plain text
#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();
  }
}

Code snippet #8

Plain text
#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();
  }
}

Code snippet #9

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

const int pinCE = 7;
const int pinCSN = 8;

//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;

RF24 radio(pinCE, pinCSN);

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

Credits

Aqib

Aqib

23 projects • 0 followers

Comments