Arduino Remote Controlled Tank with WiFi Camera (nRF24L+ / R...



In this tutorial we will learn to build a remote controlled car / tank. We will also add a WiFi camera to make the Tank more equipped. We will use the nRF24L+ module for remote control. With this tutorial, you can learn motor control with the joystick, remote motor control and motor control with the nRF24L01.

If you want, you can make this project with WiFi controlled using NodeMCU.

=======================

Required Hardware:

Arduino Uno R3 - https://goo.gl/Rqc5w2
Arduino Nano - https://goo.gl/9ZDDyw
nRF24L01 - https://goo.gl/M6fIIx
nRF24L Adapter - https://goo.gl/UWQtWy
L298N Motor - https://goo.gl/Ucvx6J
Joystick - https://goo.gl/UVr8tY
Tank Chassis - https://goo.gl/IPGy2z
Breadboard - https://goo.gl/08nnr1
Acrylic Sheet - https://goo.gl/fb9JWe
Jumper/Wires - https://goo.gl/n5ljN3
Battery Plug - https://goo.gl/aBKusM
Battery 9V - https://goo.gl/Blc0BP

Optional (If you want to add Camera)

Mini WiFi CCTV IP Camera - https://goo.gl/qPJXgQ
Mini Sg90 Servo - https://goo.gl/jQJZlG
Potentiometer - https://goo.gl/MPwcEM

=======================

Also Recommended other Hardwares:

Lipo Battery - https://goo.gl/2JZnmg
nRF24L Antenna - https://goo.gl/hZJCNM
FPV Camera - https://goo.gl/9UM8WO
FPV Goggles - https://goo.gl/fw6c1y

=======================

Tutorials about using the nRF24L+ library

https://youtu.be/oIobOWXOJJg
https://youtu.be/5z5evInThP4

=======================

Get the nRF24L+ Library

https://goo.gl/z8uy2d

=======================

Code of the Receiver (Tank)
/*
---- Receiver Code ----
Mert Arduino Tutorial & Projects (YouTube)
Please Subscribe for Support
*/

#include <Servo.h>    //the library which helps us to control the servo motor
#include <SPI.h>      //the communication interface with the modem
#include "RF24.h"     //the library which helps us to control the radio modem (nRF24L)

//define our L298N control pins
//Motor A
const int RightMotorForward = 2;    // IN1
const int RightMotorBackward = 3;   // IN2
//Motor B
const int LeftMotorForward = 4;     // IN3
const int LeftMotorBackward = 6;    // IN4

//define the servo name
Servo myServo;


RF24 radio(5,10);     /*This object represents a modem connected to the Arduino. 
                      Arguments 5 and 10 are a digital pin numbers to which signals 
                      CE and CSN are connected.*/

const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem,that will receive data from the Arduino.

int data[1];


void setup(){
  pinMode(RightMotorForward, OUTPUT);
  pinMode(LeftMotorForward, OUTPUT);
  pinMode(LeftMotorBackward, OUTPUT);
  pinMode(RightMotorBackward, OUTPUT);

  //define the servo input pins
  myServo.attach(14); //A0
  
  radio.begin();                    //it activates the modem.
  radio.openReadingPipe(1, pipe);   //determines the address of our modem which receive data.
  radio.startListening();           //enable receiving data via modem
  }

void loop(){
  if(radio.available()){
    radio.read(data, 1);
    
    if(data[0] < 11 && data[0] > 6){
    // This is backward
    // Set a Motor A backward
    digitalWrite(RightMotorForward, LOW);
    digitalWrite(RightMotorBackward, HIGH);
    // Set a Motor B backward
    digitalWrite(LeftMotorForward, LOW);
    digitalWrite(LeftMotorBackward, HIGH);
    }
    if(data[0] > -1 && data[0] < 4){
    // This is forward
    // Set a Motor A forward
    digitalWrite(RightMotorForward, HIGH);
    digitalWrite(RightMotorBackward, LOW);
    // Set a Motor B forward
    digitalWrite(LeftMotorForward, HIGH);
    digitalWrite(LeftMotorBackward, LOW);
    }
    if (data[0] == 5){
    // Stop Motors
    digitalWrite(RightMotorForward, LOW);
    digitalWrite(RightMotorBackward, LOW);
    digitalWrite(LeftMotorForward, LOW);
    digitalWrite(LeftMotorBackward, LOW);
    }
    // This is Backward
    // Set a Motor A Backward
    if(data[0] < 21 && data[0] > 16){
    digitalWrite(RightMotorForward, HIGH);
    digitalWrite(RightMotorBackward, LOW);
    // Set a Motor B Backward
    digitalWrite(LeftMotorForward, LOW);
    digitalWrite(LeftMotorBackward, HIGH);
    }
    // Turn Right
    if(data[0] > 10 && data[0] < 14){
    digitalWrite(RightMotorForward, LOW);
    digitalWrite(RightMotorBackward, HIGH);
    digitalWrite(LeftMotorForward, HIGH);
    digitalWrite(LeftMotorBackward, LOW);
    }
    // Turn Left
    if(data[0] == 15){
    digitalWrite(RightMotorForward, LOW);
    digitalWrite(RightMotorBackward, LOW);
    digitalWrite(LeftMotorForward, LOW);
    digitalWrite(LeftMotorBackward, LOW);
    }
    // for the servo motor
    if(data[0] < 31 && data[0] > 21){
      int potValue = data[0];
      int potPos = map(potValue, 21, 30, 10, 170);
      myServo.write(potPos); 
    }
  }
}
Code of the Transmitter (Remote Controller)
/*
---- Transmitter Code ----
Mert Arduino Tutorial & Projects (YouTube)
Please Subscribe for Support
*/

#include <SPI.h>                      //the communication interface with the modem
#include "RF24.h"                     //the library which helps us to control the radio modem

//define the input pins
int x_axis = A0;
int y_axis = A1;
int potPin = A2;

//define variable values
int xValue;
int yValue;
int potValue;


int data[1];

RF24 radio(5,10);                     //5 and 10 are a digital pin numbers to which signals CE and CSN are connected.
                                      
const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem, that will receive data from Arduino.


void setup(void){
  Serial.begin(9600);
  radio.begin();                      //it activates the modem.
  radio.openWritingPipe(pipe);        //sets the address of the receiver to which the program will send data.
}

void loop(){
  
  //Send X-axis data
  xValue = analogRead(x_axis);
  xValue = map(xValue, 0, 1023, 0, 10);
  data[0] = xValue;
  radio.write(data, 1); 
  
  //Send Y-axis data
  yValue = analogRead(y_axis);
  yValue = map(yValue, 0, 1023, 11, 20);
  data[0] = yValue;
  radio.write(data, 1);
  
  //Send Potentiometer data
  potValue = analogRead(potPin);
  potValue = map(potValue, 0, 1023, 21, 30);
  data[0] = potValue;
  radio.write(data, 1);
}