bruno_opaiva
Published © GPL3+

RC Car with laser turret!

Arduino RC car, using a joystick shield and NRF24l01 modules.

IntermediateFull instructions provided882
RC Car with laser turret!

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
Car microcontroller
×1
Arduino UNO
Arduino UNO
Remote control controler
×1
Funduino Joystick Shield V1.A
Shield to Arduino Uno (RC)
×1
nRF24 Module (Generic)
NRF24L01+ module
×2
DC Motor, 12 V
DC Motor, 12 V
Move the car
×4
Plastic wheel for motor
Wheels for motors
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
Turret
×2
Laser diode module
Laser
×1
4.2v 18650 Batteries
Power source
×4
Battery Holder, 18650 x 2
Battery Holder, 18650 x 2
Hold 18650 batteries
×2
USB-A to B Cable
USB-A to B Cable
To upload the program to Arduino Uno
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
To upload the program to Arduino Nano
×1
Jumper wires (generic)
Jumper wires (generic)
×6
Male/Female Jumper Wires
Male/Female Jumper Wires
×15

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Breadboard, 170 Pin
Breadboard, 170 Pin

Story

Read more

Schematics

Transmitter circuit

Connections of joystick shield on Arduino. Battery connection.

Receiver Circuit

Circuit of the RC car.

Code

Transmitter code

C/C++
Transmitter code for the project
//Include Libraries
#include <nRF24L01.h>
#include <RF24.h>
#include <SPI.h>
//Creates objects
#define A 2
#define B 3
#define C 4
#define D 5
#define E 6
int X = A0;
int Y = A1;

RF24 radio(9, 10);
const uint64_t pipe = 0xE6E6E6E6E6E6;
char msg[20] = "";

void setup() {
  //Define buttons of the shield as Input
  pinMode(A, INPUT);
  pinMode(B, INPUT);
  pinMode(C, INPUT);
  pinMode(D, INPUT);
  pinMode(E, INPUT);
  digitalWrite(A, HIGH);
  digitalWrite(B, HIGH);
  digitalWrite(C, HIGH);
  digitalWrite(D, HIGH);
  digitalWrite(E, HIGH);
  //Starts the RF module
  radio.begin();
  radio.openWritingPipe(pipe);
}

void loop() {

  if (digitalRead(A) == LOW) { //Moves the turret pointer up
    char msg[] = "up";
    radio.write(&msg, sizeof(msg));
  }
  if (digitalRead(C) == LOW) { //Moves the turret pointer down
    char msg[] = "down";
    radio.write(&msg, sizeof(msg));
  }
  if (digitalRead(B) == LOW) { //Moves the turret to left
    char msg[] = "leftturret";
    radio.write(&msg, sizeof(msg));
  }
  if (digitalRead(D) == LOW) { //Moves the turret to right
    char msg[] = "rightturret";
    radio.write(&msg, sizeof(msg));
  }
  if (digitalRead(E) == LOW) { //Shots
    char msg[] = "shot";
    radio.write(&msg, sizeof(msg));
  }
  if (analogRead(X) < 450) { //Turn left
    char msg[] = "left";
    radio.write(&msg, sizeof(msg));
  }
  if (analogRead(X) > 550) { //Turn right
    char msg[] = "right";
    radio.write(&msg, sizeof(msg));
  }
  if (analogRead(Y) > 550) { //Go forward
    char msg[] = "forward";
    radio.write(&msg, sizeof(msg));
  }
  if (analogRead(Y) < 450) { //Go backward
    char msg[] = "backward";
    radio.write(&msg, sizeof(msg));
  }
  else { //Nothing happens
    char msg[] = "analgobut";
    radio.write(&msg, sizeof(msg));
  }
}

Receiver Code

C/C++
Receiver code for the project
//include libraries
#include <nRF24L01.h>
#include <RF24.h>
#include <SPI.h>
#include <Servo.h>
//Create objects
int RightMotorF = 2;
int RightMotorB = 3;
int LeftMotorF = 4;
int LeftMotorB = 5;
int laser = 8;
Servo turret1;
Servo turret2;
int pos1 = 90;
int pos2 = 90;
RF24 radio(9, 10);
const uint64_t pipe = 0xE6E6E6E6E6E6;
char data[20] = "";

void setup() {
  //Starts thee RF module
  radio.begin();
  radio.openReadingPipe(1, pipe);
  radio.startListening();
  //Servo motor pins
  turret1.attach(6);
  turret2.attach(7);
  //Define motor pins as output
  pinMode(RightMotorB, OUTPUT);
  pinMode(LeftMotorB, OUTPUT);
  pinMode(RightMotorF, OUTPUT);
  pinMode(LeftMotorF, OUTPUT);
  //Define laser as output
  pinMode(laser, OUTPUT);
}
void loop() {
  String msg = "";
  if ( radio.available() )
  {
    radio.read( data, sizeof(data) );
    Serial.println(data);
    msg = data;

    if (msg == "forward") //Go forward
    {
      digitalWrite(RightMotorB, HIGH);
      digitalWrite(LeftMotorB, HIGH);
      digitalWrite(RightMotorF, LOW);
      digitalWrite(LeftMotorF, LOW);

    }
    else if (msg == "backward") //Go backward
    {
      digitalWrite(RightMotorB, LOW);
      digitalWrite(LeftMotorB, LOW);
      digitalWrite(RightMotorF, HIGH);
      digitalWrite(LeftMotorF, HIGH);
    }
    else if (msg == "left") //Turn left
    {
      digitalWrite(RightMotorB, LOW);
      digitalWrite(LeftMotorB, HIGH);
      digitalWrite(RightMotorF, LOW);
      digitalWrite(LeftMotorF, LOW);
    }
    else if (msg == "right") //Turn right
    {
      digitalWrite(RightMotorB, HIGH);
      digitalWrite(LeftMotorB, LOW);
      digitalWrite(RightMotorF, LOW);
      digitalWrite(LeftMotorF, LOW);
    }
    else if (msg == "rightturret") //Turret base turn right
    {
      pos1++;
    }
    else if (msg == "leftturret") { //Turret base turn left
      pos1--;
    }
    else if (msg == "up") //Turret pointer go up
    {
      pos2++;
    }
    else if (msg == "down") {//Turret pointer go down
      pos2--;
    }
    else if (msg == "shot") { //Shots laser 
      digitalWrite(laser, HIGH);
      delay(50);
      digitalWrite(laser, LOW);
      delay(50);
    }
    else if (msg == "analgobut") //If nothing happens
    {
      digitalWrite(RightMotorB, LOW);
      digitalWrite(LeftMotorB, LOW);
      digitalWrite(RightMotorF, LOW);
      digitalWrite(LeftMotorF, LOW);
    }
    //Motors follow the position value
    turret1.write(pos1);
    turret2.write(pos2);
  }
}

Credits

bruno_opaiva

bruno_opaiva

6 projects • 4 followers

Comments