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

Arduino-Controlled Robotic Vehicle with Bluetooth Interface and Obstacle Avoidance

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Robotic Vehicle with Bluetooth Interface and Obstacle Avoidance

Circuit Documentation

Summary

The circuit in question appears to be designed for a mobile robot or vehicle with wireless control capabilities. It includes motor drivers for wheel movement, an ultrasonic sensor for distance measurement, a Bluetooth module for wireless communication, a temperature sensor, servo motors, LEDs for indication, and a microcontroller (Arduino UNO) to manage the logic and sensor data processing. The circuit is powered by a 12V battery, which also supplies power to the motor driver and through it to the Arduino UNO.

Component List

L298N DC Motor Driver

Arduino UNO

HC-05 Bluetooth Module

HC-SR04 Ultrasonic Sensor

Gearmotor DC Wheels (Left and Right)

Temperature Sensor (LM35)

Servo

12V Battery

LED: Two Pin (Red)

Wiring Details

L298N DC Motor Driver

Arduino UNO

HC-05 Bluetooth Module

HC-SR04 Ultrasonic Sensor

Gearmotor DC Wheels (Left and Right)

Temperature Sensor (LM35)

Servo

12V Battery

LED: Two Pin (Red)

Documented Code

#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_MODULE
#define INCLUDE_DASHBOARD_MODULE // Include Dashboard module
#include <Dabble.h>

const unsigned int trig = 2;
const unsigned int echo = 8;

// Right motor
int rightMotorPin1 = 3;
int rightMotorPin2 = 5;
int sensorPin = A0; // Temperature sensor pin, if needed

// Left motor
int leftMotorPin1 = 6;
int leftMotorPin2 = 9;

void setup() {
    pinMode(rightMotorPin1, OUTPUT);
    pinMode(rightMotorPin2, OUTPUT);
    pinMode(leftMotorPin1, OUTPUT);
    pinMode(leftMotorPin2, OUTPUT);
    pinMode(trig, OUTPUT);
    pinMode(echo, INPUT);

    rotateMotor(0, 0);   
    Dabble.begin(9600, 10, 11);
    Serial.begin(9600);
}

void loop() {
    unsigned long duration; // Variable for measuring time
    int distance;           // Variable for storing distance

    // Generate pulse from trig pin
    digitalWrite(trig, LOW);   // Turn off trig
    delayMicroseconds(2);
    digitalWrite(trig, HIGH);  // Generate pulse from trig
    delayMicroseconds(5);      // Pulse duration is 5 microseconds
    digitalWrite(trig, LOW);   // Turn off trig
    
    // Calculate the duration
    duration = pulseIn(echo, HIGH);  
    distance = int(duration / 2 / 29.412); // Calculate distance (cm)

    Serial.println(distance); // Print distance to Serial Monitor

    int rightMotorSpeed = 0;
    int leftMotorSpeed = 0;

    Dabble.processInput();
    
    // Check distance
    if (distance <= 15) { // If distance is less than 15 cm
        rightMotorSpeed = -100; // Move backward
        leftMotorSpeed = -100; 
    } else {
        // Control using GamePad
        if (GamePad.isUpPressed()) {
            rightMotorSpeed = 100;
            leftMotorSpeed = 100;
        } else if (GamePad.isDownPressed()) {
            rightMotorSpeed = -100;
            leftMotorSpeed = -100;
        } else if (GamePad.isLeftPressed()) {
            rightMotorSpeed = 100;
            leftMotorSpeed = 0;
        } else if (GamePad.isRightPressed()) {
            rightMotorSpeed = 0;
            leftMotorSpeed = 100;
        } else {
            rightMotorSpeed = 0;
            leftMotorSpeed = 0; // Stop
        }
    }

    // Function to control motors
    rotateMotor(rightMotorSpeed, leftMotorSpeed);
}

void rotateMotor(int rightMotorSpeed, int leftMotorSpeed) {
    // Control right motor
    if (rightMotorSpeed < 0) {
        analogWrite(rightMotorPin1, 0);
        analogWrite(rightMotorPin2, 100);    
    } else if (rightMotorSpeed > 0) {
        analogWrite(rightMotorPin1, 100);
        analogWrite(rightMotorPin2, 0);      
    } else {
        analogWrite(rightMotorPin1, 0);
        analogWrite(rightMotorPin2, 0);  
    }

    // Control left motor
    if (leftMotorSpeed < 0) {
        analogWrite(leftMotorPin1, 0);
        analogWrite(leftMotorPin2, 100);    
    } else if (leftMotorSpeed > 0) {
        analogWrite(leftMotorPin1, 100);
        analogWrite(leftMotorPin2, 0);      
    } else {
        analogWrite(leftMotorPin1, 0);
        analogWrite(leftMotorPin2, 0);  
    }
}

This code is designed to control a robot's movement using an Arduino UNO, with inputs from an ultrasonic sensor and a Bluetooth module. The robot can move forward, backward, and turn based on the distance detected by the ultrasonic sensor or commands received via Bluetooth. The temperature sensor's data is read but not used in the control logic. The LEDs are controlled directly by the Arduino's digital pins and are likely used as status indicators.