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

Arduino-Controlled Robotic Vehicle with Ultrasonic Obstacle Detection and Joystick Navigation

Image of Arduino-Controlled Robotic Vehicle with Ultrasonic Obstacle Detection and Joystick Navigation

Circuit Documentation

Summary of the Circuit

This circuit is designed to control a pair of DC motors using an Arduino UNO microcontroller in conjunction with a 2-channel relay module. The control input is provided by a KY-023 Dual Axis Joystick Module. An HC-SR04 Ultrasonic Sensor is included for distance measurement, which can be used for obstacle detection or distance-based control logic. The circuit is powered by a 12V 7Ah battery, and a LM78xx Voltage Regulator is used to step down the voltage to 5V required by the Arduino UNO and other 5V components.

Component List

DC Motor

  • Description: Electric motor that converts DC electrical power into mechanical rotation.
  • Purpose: To provide motion to the system, controlled by the relay module.

HC-SR04 Ultrasonic Sensor

  • Description: A sensor that measures distance by emitting ultrasonic waves and measuring the time taken for the echo to return.
  • Purpose: To detect obstacles or measure the distance from an object.

LM78xx Voltage Regulator

  • Description: A voltage regulator that outputs a stable 5V from a higher voltage input.
  • Purpose: To provide a regulated 5V supply to the 5V components in the circuit.

KY-023 Dual Axis Joystick Module

  • Description: A module that provides two analog outputs corresponding to the X and Y positions of the joystick.
  • Purpose: To serve as a user input device for controlling the motion of the DC motors.

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P, with digital and analog I/O pins.
  • Purpose: To process input signals and control other components in the circuit.

12v 7ah Battery

  • Description: A rechargeable battery providing a 12V output.
  • Purpose: To supply power to the circuit.

2 Channel Relay Module

  • Description: A module with two independent relays that can control high power devices.
  • Purpose: To switch the DC motors on and off, allowing for motor control by the Arduino.

Wiring Details

DC Motor

  • Wiring:
    • pin 1 of both motors connected to N.O. 1 and N.O. 2 on the relay module.
    • pin 2 of both motors connected to N.O. 2 on the relay module.

HC-SR04 Ultrasonic Sensor

  • Wiring:
    • VCC connected to 5V on the Arduino UNO.
    • GND connected to GND on the Arduino UNO.
    • TRIG connected to D2 on the Arduino UNO.
    • ECHO connected to D3 on the Arduino UNO.

LM78xx Voltage Regulator

  • Wiring:
    • Input connected to 12v + on the battery.
    • GND connected to 12v - on the battery.
    • Output providing 5V to the Arduino UNO and other 5V components.

KY-023 Dual Axis Joystick Module

  • Wiring:
    • GND connected to GND on the Arduino UNO.
    • +5V connected to 5V on the Arduino UNO.
    • VRx connected to A0 on the Arduino UNO.
    • VRy connected to A1 on the Arduino UNO.

Arduino UNO

  • Wiring:
    • 5V and GND pins used to distribute power to other 5V components.
    • Analog pins A0 and A1 connected to the joystick module.
    • Digital pins D2 and D3 connected to the ultrasonic sensor.
    • Digital pins D4, D5, D6, and D7 connected to the relay module inputs.

12v 7ah Battery

  • Wiring:
    • 12v + connected to the voltage regulator input and COM 1 and COM 2 on the relay module.
    • 12v - connected to the voltage regulator ground and VCC- (GND) on the relay module.

2 Channel Relay Module

  • Wiring:
    • VCC+ connected to 5V on the Arduino UNO.
    • VCC- (GND) connected to GND on the Arduino UNO.
    • IN 1 and IN 2 controlled by digital pins D4, D5, D6, and D7 on the Arduino UNO.

Documented Code

Code for Arduino UNO

// Define pins for joystick
const int joystickX = A0;    // Analog pin for joystick X-axis
const int joystickY = A1;    // Analog pin for joystick Y-axis

// Define pins for relay module
const int relayPin1 = 5;     // Relay pin 1 (controls Motor 1)
const int relayPin2 = 6;     // Relay pin 2 (controls Motor 2)

void setup() {
  // Initialize joystick pins as input
  pinMode(joystickX, INPUT);
  pinMode(joystickY, INPUT);
  
  // Initialize relay pins as output
  pinMode(relayPin1, OUTPUT);
  pinMode(relayPin2, OUTPUT);
}

void loop() {
  int xValue = analogRead(joystickX); // Read joystick X value
  int yValue = analogRead(joystickY); // Read joystick Y value

  // Map the joystick values to motor control logic
  if (yValue < 400) {
    // Move forward
    digitalWrite(relayPin1, HIGH);
    digitalWrite(relayPin2, HIGH);
  } else if (yValue > 600) {
    // Move backward
    digitalWrite(relayPin1, LOW);
    digitalWrite(relayPin2, LOW);
  } else if (xValue < 400) {
    // Turn left
    digitalWrite(relayPin1, LOW);
    digitalWrite(relayPin2, HIGH);
  } else if (xValue > 600) {
    // Turn right
    digitalWrite(relayPin1, HIGH);
    digitalWrite(relayPin2, LOW);
  } else {
    // Stop
    digitalWrite(relayPin1, LOW);
    digitalWrite(relayPin2, LOW);
  }

  delay(100); // Delay for stability
}

This code snippet is responsible for reading the joystick's analog values and mapping them to control the DC motors via the relay module. The joystick's Y-axis controls forward and backward motion, while the X-axis controls left and right turns. The motors are stopped when the joystick is in the neutral position.