Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

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

View and Edit Project In Cirkit DesignerImage 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

DC Motor (x2)

Servo (x2)

Battery 12V

KY-023 Dual Axis Joystick Module (x2)

Arduino UNO

LED: Two Pin (red)

Resistor

Wiring Details

L298N DC Motor Driver

DC Motors

Servos

KY-023 Dual Axis Joystick Modules

LED and Resistor

Arduino UNO

Battery 12V

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.