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

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

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

HC-SR04 Ultrasonic Sensor

LM78xx Voltage Regulator

KY-023 Dual Axis Joystick Module

Arduino UNO

12v 7ah Battery

2 Channel Relay Module

Wiring Details

DC Motor

HC-SR04 Ultrasonic Sensor

LM78xx Voltage Regulator

KY-023 Dual Axis Joystick Module

Arduino UNO

12v 7ah Battery

2 Channel Relay Module

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.