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

Arduino UNO Controlled Robotic Vehicle with Ultrasonic Obstacle Detection and Joystick Operation

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Robotic Vehicle with Ultrasonic Obstacle Detection and Joystick Operation

Circuit Documentation

Summary

This circuit is designed to interface an Arduino UNO with a variety of components including a KY-023 Dual Axis Joystick Module, an HC-SR04 Ultrasonic Sensor, a 4-channel relay module, two DC Motors, two LEDs (red and yellow), a Piezo Speaker, and two resistors. The circuit is powered by a 12V Battery and the Arduino UNO's 5V output. The primary functions of this circuit include distance measurement, motor control via joystick input, visual indicators through LEDs, and audio feedback using a Piezo Speaker.

Component List

Arduino UNO

A microcontroller board based on the ATmega328P. It has 14 digital input/output pins, 6 analog inputs, a USB connection, a power jack, an ICSP header, and a reset button.

12V Battery

Provides the power source for the relay module and the DC Motors.

KY-023 Dual Axis Joystick Module

A joystick controller that provides two analog outputs corresponding to the X and Y axes and a digital output for the joystick switch.

HC-SR04 Ultrasonic Sensor

An ultrasonic distance sensor that can measure distances from 2cm to 400cm with an accuracy of 3mm.

4-channel Relay Module

Allows for control of high-power devices using low-power signals from the Arduino. It has four relays that can be individually controlled.

DC Motor (x2)

Electric motors that convert electrical energy into mechanical energy.

LED: Two Pin (red)

A red light-emitting diode that emits red light when a forward current passes through it.

LED: Two Pin (yellow)

A yellow light-emitting diode that emits yellow light when a forward current passes through it.

Piezo Speaker

An electronic device that can generate sound when an electrical signal is applied to it.

Resistor (200 Ohms) (x2)

A passive two-terminal electrical component that implements electrical resistance as a circuit element.

Wiring Details

Arduino UNO

12V Battery

KY-023 Dual Axis Joystick Module

HC-SR04 Ultrasonic Sensor

4-channel Relay Module

DC Motors

LEDs (Red and Yellow)

Piezo Speaker

Resistor (200 Ohms)

Documented Code

// Define pin connections
const int trigPin = 9;
const int echoPin = 10;
const int joystickXPin = A0;
const int joystickYPin = A1;
const int relay1Pin = 2;
const int relay2Pin = 3;
const int relay3Pin = 4;
const int relay4Pin = 5;
const int redLEDPin = 8;
const int yellowLEDPin = 7;
const int piezoPin = 11;

// Variables for ultrasonic sensor
long duration;
int distance;

void setup() {
  // Initialize pins
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(relay1Pin, OUTPUT);
  pinMode(relay2Pin, OUTPUT);
  pinMode(relay3Pin, OUTPUT);
  pinMode(relay4Pin, OUTPUT);
  pinMode(redLEDPin, OUTPUT);
  pinMode(yellowLEDPin, OUTPUT);
  pinMode(piezoPin, OUTPUT);

  // Initialize relay to be off
  digitalWrite(relay1Pin, HIGH);
  digitalWrite(relay2Pin, HIGH);
  digitalWrite(relay3Pin, HIGH);
  digitalWrite(relay4Pin, HIGH);
}

void loop() {
  // Read distance from ultrasonic sensor
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;

  // Read joystick position
  int joystickX = analogRead(joystickXPin);
  int joystickY = analogRead(joystickYPin);

  // Control motors via relay based on joystick position
  if (joystickX > 512) { // Assuming center position is 512
    digitalWrite(relay1Pin, LOW); // Turn on motor 1
  } else {
    digitalWrite(relay1Pin, HIGH); // Turn off motor 1
  }

  if (joystickY > 512) {
    digitalWrite(relay3Pin, LOW); // Turn on motor 2
  } else {
    digitalWrite(relay3Pin, HIGH); // Turn off motor 2
  }

  // Control LEDs based on distance
  if (distance < 10) {
    digitalWrite(redLEDPin, HIGH);
    digitalWrite(yellowLEDPin, LOW);
  } else if (distance < 20) {
    digitalWrite(redLEDPin, LOW);
    digitalWrite(yellowLEDPin, HIGH);
  } else {
    digitalWrite(redLEDPin, LOW);
    digitalWrite(yellowLEDPin, LOW);
  }

  // Play a sound if an object is very close
  if (distance < 5) {
    tone(piezoPin, 1000); // Play 1kHz tone
    delay(100); // for 100ms
    noTone(piezoPin);
  }

  // Add a short delay before the next loop iteration
  delay(100);
}

This code is designed to run on the Arduino UNO and controls the various components based on sensor inputs and provides feedback through LEDs and a Piezo Speaker.