Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino-Controlled RC Car with Dual Joystick and Crane Servo Mechanism

Image of Arduino-Controlled RC Car with Dual Joystick and Crane Servo Mechanism

Circuit Documentation

Summary of the Circuit

This circuit is designed to control an RC car with two DC motors and a crane mechanism using two joysticks. The car's movement (forward, reverse, left, right) is controlled by the first joystick, while the second joystick manages the crane's servo motors for hoisting and rotation. An LED indicates the car's movement direction, staying on when moving forward and blinking when reversing. The circuit utilizes an Arduino UNO as the central microcontroller to process the joystick inputs and control the motors and servos accordingly.

Component List

L298N DC Motor Driver

  • Description: A motor driver module capable of driving two DC motors.
  • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB

DC Motor (x2)

  • Description: A standard DC motor for driving the RC car.
  • Pins: pin 1, pin 2

Servo (x2)

  • Description: A servo motor for controlling the crane mechanism.
  • Pins: GND, VCC, PWM

Battery 12V

  • Description: A 12V battery to power the motors and the motor driver.
  • Pins: +, -

KY-023 Dual Axis Joystick Module (x2)

  • Description: A joystick module for controlling the RC car and crane.
  • Pins: GND, +5V, VRx, VRy, SW

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0

LED: Two Pin (red)

  • Description: A red LED to indicate the movement direction of the RC car.
  • Pins: cathode, anode

Resistor

  • Description: A resistor to limit current to the LED.
  • Pins: pin1, pin2
  • Properties: Resistance - 200 Ohms

Wiring Details

L298N DC Motor Driver

  • 12V: Connected to the + pin of the 12V battery.
  • GND: Connected to the common ground net.
  • 5V: Connected to the 3.3V pin of the Arduino UNO.
  • ENA, IN1, IN2: Controlled by D5, D4, D3 pins of the Arduino UNO respectively.
  • ENB, IN3, IN4: Controlled by D0, D2, D1 pins of the Arduino UNO respectively.
  • OUT1, OUT2: Connected to the pins of the first DC Motor.
  • OUT3, OUT4: Connected to the pins of the second DC Motor.

DC Motors

  • Motor 1: Connected to OUT1 and OUT2 of the L298N DC Motor Driver.
  • Motor 2: Connected to OUT3 and OUT4 of the L298N DC Motor Driver.

Servos

  • Servo 1: PWM pin controlled by D7 pin of the Arduino UNO.
  • Servo 2: PWM pin controlled by D6 pin of the Arduino UNO.
  • VCC pins connected to the + pin of the 12V battery.
  • GND pins connected to the common ground net.

KY-023 Dual Axis Joystick Modules

  • Joystick 1: VRx and VRy connected to A5 and A4 of the Arduino UNO. SW connected to D13.
  • Joystick 2: VRx and VRy connected to A3 and A2 of the Arduino UNO. SW connected to D12.
  • +5V pins connected to the 3.3V pin of the Arduino UNO.
  • GND pins connected to the common ground net.

LED and Resistor

  • LED anode connected to pin1 of the Resistor.
  • LED cathode connected to the common ground net.
  • Resistor pin2 connected to D8 of the Arduino UNO.

Arduino UNO

  • Digital and analog pins connected as specified in the wiring details above.
  • GND pin connected to the common ground net.
  • 3.3V pin connected to the +5V pins of the joystick modules and the 5V pin of the L298N DC Motor Driver.

Battery 12V

    • pin connected to the 12V pin of the L298N DC Motor Driver and VCC pins of the Servos.
    • pin connected to the common ground net.

Documented Code

/*
 * RC Car with Crane Control
 *
 * This Arduino sketch controls an RC car with two DC motors and a crane
 * mechanism using two joysticks. The first joystick controls the car's
 * movement (forward, reverse, left, right), and the second joystick
 * controls the crane's servo motors for hoisting and rotation. An LED
 * indicates the car's movement direction: it stays on when moving
 * forward and blinks when reversing.
 */

// Pin definitions
const int motorENA = 5;
const int motorIN1 = 4;
const int motorIN2 = 3;
const int motorIN3 = 2;
const int motorIN4 = 1;
const int motorENB = 0;
const int servoPWM1 = 6;
const int servoPWM2 = 7;
const int ledPin = 8;
const int joy1VRx = A5;
const int joy1VRy = A4;
const int joy1SW = 13;
const int joy2VRx = A3;
const int joy2VRy = A2;
const int joy2SW = 12;

void setup() {
  // Initialize motor control pins
  pinMode(motorENA, OUTPUT);
  pinMode(motorIN1, OUTPUT);
  pinMode(motorIN2, OUTPUT);
  pinMode(motorIN3, OUTPUT);
  pinMode(motorIN4, OUTPUT);
  pinMode(motorENB, OUTPUT);
  // Initialize servo control pins
  pinMode(servoPWM1, OUTPUT);
  pinMode(servoPWM2, OUTPUT);
  // Initialize LED pin
  pinMode(ledPin, OUTPUT);
  // Initialize joystick switch pins
  pinMode(joy1SW, INPUT_PULLUP);
  pinMode(joy2SW, INPUT_PULLUP);
}

void loop() {
  // Read joystick values
  int joy1X = analogRead(joy1VRx);
  int joy1Y = analogRead(joy1VRy);
  int joy2X = analogRead(joy2VRx);
  int joy2Y = analogRead(joy2VRy);
  // Control car movement
  controlCar(joy1X, joy1Y);
  // Control crane servos
  controlCrane(joy2X, joy2Y);
}

void controlCar(int x, int y) {
  if (y > 600) { // Forward
    digitalWrite(motorIN1, HIGH);
    digitalWrite(motorIN2, LOW);
    digitalWrite(motorIN3, HIGH);
    digitalWrite(motorIN4, LOW);
    digitalWrite(ledPin, HIGH); // LED on
  } else if (y < 400) { // Reverse
    digitalWrite(motorIN1, LOW);
    digitalWrite(motorIN2, HIGH);
    digitalWrite(motorIN3, LOW);
    digitalWrite(motorIN4, HIGH);
    blinkLED(); // LED blink
  } else if (x > 600) { // Right
    digitalWrite(motorIN1, HIGH);
    digitalWrite(motorIN2, LOW);
    digitalWrite(motorIN3, LOW);
    digitalWrite(motorIN4, HIGH);
  } else if (x < 400) { // Left
    digitalWrite(motorIN1, LOW);
    digitalWrite(motorIN2, HIGH);
    digitalWrite(motorIN3, HIGH);
    digitalWrite(motorIN4, LOW);
  } else { // Stop
    digitalWrite(motorIN1, LOW);
    digitalWrite(motorIN2, LOW);
    digitalWrite(motorIN3, LOW);
    digitalWrite(motorIN4, LOW);
    digitalWrite(ledPin, LOW); // LED off
  }
}

void controlCrane(int x, int y) {
  int servo1Pos = map(x, 0, 1023, 0, 180);
  int servo2Pos = map(y, 0, 1023, 0, 180);
  analogWrite(servoPWM1, servo1Pos);
  analogWrite(servoPWM2, servo2Pos);
}

void blinkLED() {
  digitalWrite(ledPin, HIGH);
  delay(500);
  digitalWrite(ledPin, LOW);
  delay(500);
}

This code is responsible for reading the joystick inputs and controlling the motors and servos based on the joystick positions. It also manages the LED behavior to reflect the car's movement direction.