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

Arduino UNO Controlled Obstacle Avoidance Robot with HC-05 Bluetooth and L298N Motor Driver

Image of Arduino UNO Controlled Obstacle Avoidance Robot with HC-05 Bluetooth and L298N Motor Driver

Circuit Documentation

Summary

The circuit in question appears to be a complex system involving an Arduino UNO microcontroller, various sensors (including IR sensors and an ultrasonic sensor), a motor driver, relays, LEDs, a buzzer, and several other components. The system is likely designed for some form of automation or robotics application, given the presence of motors and sensors that can detect obstacles. The Arduino UNO is used as the central processing unit, interfacing with the HC-05 Bluetooth module for wireless communication, and controlling the motors through the L298N motor driver.

Component List

Microcontroller

  • Arduino UNO: A microcontroller board based on the ATmega328P, with a variety of digital and analog I/O pins.

Sensors

  • IR Sensors: Used for obstacle detection or line tracking.
  • HC-SR04 Ultrasonic Sensor: Measures distance by emitting ultrasonic waves and timing their return after bouncing off objects.
  • Voltage Sensor DC: Measures DC voltage in the circuit.

Actuators

  • 5v Mini Water Pump: An electric pump for moving water.
  • Peristaltic Pump: A type of pump used for precise dosing of liquids.
  • Hobby Gearmotors with 48:1 Gearbox: Motors used for driving wheels or other mechanical parts.
  • Fan: Used for cooling or airflow.

Communication

  • HC 05: A Bluetooth module for wireless communication.

Power

  • 1 Channel 5V Relay Module: An electrically operated switch that allows you to control a high power circuit with a low power signal.
  • 1-Channel Relay (5V 10A): Similar to the above, used for controlling higher power devices.
  • Polymer Lithium Ion Battery - Generic: Provides power to the circuit.
  • Li-ion Battery, 2200 mAh 11.1 V: Another power source for the circuit.

Indicators

  • LEDs (Red, White, Four Pin): Used as visual indicators.
  • 7 Segment Display: Displays numerical information.
  • 128x64 OLED Display (I2C IIC SPI Serial): A small screen for displaying text or graphics.

Control

  • L298N DC Motor Driver: Controls the direction and speed of DC motors.
  • Rocker Switch (SPST): A single-pole single-throw switch used to control power.

Sound

  • Buzzer: An audible alarm or signal device.

Wiring Details

Arduino UNO

  • Digital pins D0-D13 are used for interfacing with various components such as the HC-05 Bluetooth module, LEDs, buzzer, and motor driver.
  • Analog pins A0-A3 are connected to IR sensors for obstacle detection.
  • Power pins (3.3V, 5V, GND, Vin) provide power to the circuit and are connected to various components like the motor driver, IR sensors, and relay modules.

IR Sensors

  • Connected to the Arduino's analog pins for signal output and to the motor driver's 5V and GND for power.

HC-SR04 Ultrasonic Sensor

  • VCC and GND pins are connected to the ESP32 for power.
  • TRIG and ECHO pins are connected to the ESP32's digital pins for distance measurement.

L298N DC Motor Driver

  • IN1-IN4 control the direction of the motors.
  • OUT1-OUT4 are connected to the gearmotors.
  • 5V and GND provide power to the driver and connected sensors.
  • 12V is connected to a voltage source through a rocker switch.

Relays

  • Relay modules are used to control the water pump and peristaltic pump.
  • Signal pins are connected to the Arduino for control.
  • Power and ground pins are connected to the power source and common ground.

LEDs

  • Anodes are connected to the Arduino's digital pins through resistors.
  • Cathodes are connected to the common ground.

Buzzer

  • One pin is connected to the Arduino's digital pin for control.
  • The other pin is connected to the common ground.

ESP32

  • Used for additional processing and control, interfacing with the OLED display, ultrasonic sensor, and voltage sensor.
  • Digital and power pins are connected to corresponding components.

OLED Display

  • SDA and SCL are connected to the ESP32 for I2C communication.
  • VCC and GND provide power to the display.

Power Sources

  • Batteries are connected to provide power to the circuit, with the positive terminals connected to components and switches, and the negative terminals connected to the common ground.

Documented Code

#define in1 5 //L298n Motor Driver pins.
#define in2 6
#define in3 10
#define in4 11
#define EXTRA 4 
const int trigPin = 9;
const int echoPin = 18;
long duration;
int distance;
#define light_FR  13    //LED Front Right   pin A0 for Arduino Uno
//#define light_FL  15   //LED Front Left    pin A1 for Arduino Uno
#define light_BR  12    //LED Back Right    pin A2 for Arduino Uno
//#define light_BL  17    //LED Back Left     pin A3 for Arduino Uno
#define horn_Buzz 7    //Horn Buzzer       pin A4 for Arduino Uno
int command; //Int to store app command state.
int Speed = 204; // 0 - 255.
int Speedsec;
int buttonState = 0;
int lastButtonState = 0;
int Turnradius = 0; //Set the radius of a turn, 0 - 255 Note:the robot will malfunction if this is higher than int Speed.
int brakeTime = 45;
int brkonoff = 1; //1 for the electronic braking system, 0 for normal.
boolean lightFront = false;
boolean lightBack = false;
boolean horn = false;
boolean extra = false;
void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); 
  pinMode(EXTRA,OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(14,INPUT);
   pinMode(light_FR, OUTPUT);
 //   pinMode(light_FL, OUTPUT);
    pinMode(light_BR, OUTPUT);
 //   pinMode(light_BL, OUTPUT);
    pinMode(horn_Buzz, OUTPUT);
  
  Serial.begin(9600);  //Set the baud rate to your Bluetooth module.
}

void loop() {
  // Ultrasonic sensor measurement routine
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;
  Serial.println(distance);

  // Obstacle avoidance and horn alert
  if(distance < 25){
    Stop();
    delay(100);
    digitalWrite(in1,LOW);
    digitalWrite(in2,HIGH);
    digitalWrite(in3,LOW);
    digitalWrite(in4,HIGH);
    delay(500);
    digitalWrite(in1,LOW);
    digitalWrite(in2,LOW);
    digitalWrite(in3,LOW);
    digitalWrite(in4,LOW);
  }
  if(distance < 25){
    digitalWrite(horn_Buzz,1);
    delay(50);
    digitalWrite(horn_Buzz,0);
    delay(50);
    digitalWrite(horn_Buzz,1);
    delay(50);
    digitalWrite(horn_Buzz,0);
    delay(50);
    digitalWrite(horn_Buzz,1);
    delay(50);
    digitalWrite(horn_Buzz,0);
  }

  // IR sensor detection and horn alert
  if (digitalRead(14) == HIGH){
    // ... similar code for IR sensor detection and response
  }

  // Command processing from Bluetooth module
  if (Serial.available() > 0) {
    command = Serial.read();
    Stop(); //Initialize with motors stopped.
    
    // Light and horn control based on command
    if (lightFront) {digitalWrite(light_FR, HIGH);}
    if (!lightFront) {digitalWrite(light_FR, LOW);}
    if (lightBack) {digitalWrite(light_BR, HIGH);}
    if (!lightBack) {digitalWrite(light_BR, LOW);}
    if (horn) {digitalWrite(horn_Buzz, HIGH);}
    if (!horn) {digitalWrite(horn_Buzz, LOW);}
    if (extra) {digitalWrite(EXTRA, HIGH);}
    if (!extra) {digitalWrite(EXTRA, LOW);}

    // Motor control based on command
    switch (command) {
      case 'F':
        forward();
        break;
      // ... other cases for different commands
    }

    // Speed adjustment based on command
    Speedsec = Turnradius;
    if (brkonoff == 1) {
      brakeOn();
    } else {
      brakeOff();
    }
  }
}

// Motor control functions
void forward() {
  analogWrite(in1, Speed);
  analogWrite(in3, Speed);
}
// ... other motor control functions

void Stop() {
  analogWrite(in1, 0);
  analogWrite(in2, 0);
  analogWrite(in3, 0);
  analogWrite(in4, 0);
}

void brakeOn() {
  // Electronic braking system