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

Arduino UNO-Based Autonomous Robot with Ultrasonic and IR Sensors, Bluetooth Control, and Battery Power

Image of Arduino UNO-Based Autonomous Robot with Ultrasonic and IR Sensors, Bluetooth Control, and Battery Power

Circuit Documentation

Summary

This circuit is designed to control a set of DC motors using an Arduino UNO, an L298N motor driver, and various sensors including an HC-SR04 Ultrasonic Sensor, IR sensors, and an HC-05 Bluetooth Module. The circuit is powered by a 2x 18650 battery pack. The Arduino UNO is programmed to control the motor driver based on sensor inputs.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. HC-SR04 Ultrasonic Sensor

    • Description: Ultrasonic distance sensor.
    • Pins: VCC, TRIG, ECHO, GND
  3. 2x 18650 Battery Pack

    • Description: Battery pack providing power to the circuit.
    • Pins: vcc, gnd
  4. IR Sensor

    • Description: Infrared sensor for obstacle detection.
    • Pins: out, gnd, vcc
  5. L298N DC Motor Driver

    • Description: Dual H-Bridge motor driver.
    • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
  6. HC-05 Bluetooth Module

    • Description: Bluetooth module for wireless communication.
    • Pins: Key, VCC, GND, TXD, RXD, State
  7. DC Motor

    • Description: Standard DC motor.
    • Pins: pin 1, pin 2

Wiring Details

Arduino UNO

  • 5V connected to:

    • VCC of IR Sensor
    • VCC of HC-SR04 Ultrasonic Sensor
    • VCC of HC-05 Bluetooth Module
    • VCC of another IR Sensor
  • GND connected to:

    • GND of IR Sensor
    • GND of HC-SR04 Ultrasonic Sensor
    • GND of another IR Sensor
    • GND of 2x 18650 Battery Pack
    • GND of L298N DC Motor Driver
    • GND of HC-05 Bluetooth Module
  • Vin connected to:

    • 5V of L298N DC Motor Driver
  • D11 connected to:

    • ENB of L298N DC Motor Driver
  • D10 connected to:

    • ENA of L298N DC Motor Driver
  • D9 connected to:

    • ECHO of HC-SR04 Ultrasonic Sensor
  • D8 connected to:

    • TRIG of HC-SR04 Ultrasonic Sensor
  • D7 connected to:

    • IN4 of L298N DC Motor Driver
  • D6 connected to:

    • IN3 of L298N DC Motor Driver
  • D5 connected to:

    • IN2 of L298N DC Motor Driver
  • D4 connected to:

    • IN1 of L298N DC Motor Driver
  • D3 connected to:

    • out of IR Sensor
  • D2 connected to:

    • out of another IR Sensor
  • D1 connected to:

    • TXD of HC-05 Bluetooth Module
  • D0 connected to:

    • RXD of HC-05 Bluetooth Module

HC-SR04 Ultrasonic Sensor

  • VCC connected to:

    • 5V of Arduino UNO
  • GND connected to:

    • GND of Arduino UNO
  • TRIG connected to:

    • D8 of Arduino UNO
  • ECHO connected to:

    • D9 of Arduino UNO

2x 18650 Battery Pack

  • vcc connected to:

    • 12V of L298N DC Motor Driver
  • gnd connected to:

    • GND of Arduino UNO

IR Sensor

  • vcc connected to:

    • 5V of Arduino UNO
  • gnd connected to:

    • GND of Arduino UNO
  • out connected to:

    • D3 of Arduino UNO

Another IR Sensor

  • vcc connected to:

    • 5V of Arduino UNO
  • gnd connected to:

    • GND of Arduino UNO
  • out connected to:

    • D2 of Arduino UNO

L298N DC Motor Driver

  • 5V connected to:

    • Vin of Arduino UNO
  • GND connected to:

    • GND of Arduino UNO
  • 12V connected to:

    • vcc of 2x 18650 Battery Pack
  • ENB connected to:

    • D11 of Arduino UNO
  • ENA connected to:

    • D10 of Arduino UNO
  • IN4 connected to:

    • D7 of Arduino UNO
  • IN3 connected to:

    • D6 of Arduino UNO
  • IN2 connected to:

    • D5 of Arduino UNO
  • IN1 connected to:

    • D4 of Arduino UNO
  • OUT1 connected to:

    • pin 2 of DC Motor
    • pin 2 of another DC Motor
  • OUT2 connected to:

    • pin 1 of DC Motor
    • pin 1 of another DC Motor
  • OUT3 connected to:

    • pin 2 of another DC Motor
    • pin 2 of another DC Motor
  • OUT4 connected to:

    • pin 1 of another DC Motor
    • pin 1 of another DC Motor

HC-05 Bluetooth Module

  • VCC connected to:

    • 5V of Arduino UNO
  • GND connected to:

    • GND of Arduino UNO
  • TXD connected to:

    • D1 of Arduino UNO
  • RXD connected to:

    • D0 of Arduino UNO

Code Documentation

#define Trig 8
#define Echo 9

const int in21 = 4;    // L298N-2 pin 4
const int in22 = 5;    // L298N-2 pin 5
const int in23 = 6;    // L298N-2 pin 6
const int in24 = 7;    // L298N-2 pin 7
const int enA = 10;    // L298N-2 pin 10
const int enB = 11;    // L298N-2 pin 11

void setup() 
{  
  pinMode(Trig, OUTPUT); // выход 
  pinMode(Echo, INPUT); // вход 

  pinMode(in21, OUTPUT);      // выход на L298n
  pinMode(in22, OUTPUT);      // выход на L298n
  pinMode(in23, OUTPUT);      // выход на L298n
  pinMode(in24, OUTPUT);      // выход на L298n
} 

unsigned int impulseTime=0; 
unsigned int distance_sm=0; 

void loop() 
{  
  digitalWrite(Trig, HIGH); 
  delayMicroseconds(10); // 10 микросекунд 
  digitalWrite(Trig, LOW);
  impulseTime=pulseIn(Echo, HIGH); // замеряем длину импульса 
  distance_sm=impulseTime/58; // переводим в сантиметры 

  if (distance_sm>25) // если расстояние более 25 сантиметров 
  {     
      digitalWrite(in21, LOW);
      digitalWrite(in22, HIGH);
      analogWrite(enA, 60);

      analogWrite(enB, 60);
      digitalWrite(in23, HIGH);
      digitalWrite(in24, LOW);
  }  
  else 
  {   
      digitalWrite(in21, HIGH);
      digitalWrite(in22, LOW);

      analogWrite(enA, 100);

      analogWrite(enB, 100);
      
      digitalWrite(in23, HIGH);
      digitalWrite(in24, LOW); 
      delay(1100); // если застряет или не выезжает из угла  - измените время поворота. сейчас там стоит 1,1 с.
  }   

  delay(50); 
}

This code is designed to control the L298N motor driver based on the distance measured by the HC-SR04 Ultrasonic Sensor. The motors are controlled to move forward if the distance is greater than 25 cm and to turn if the distance is less than 25 cm. The IR sensors and Bluetooth module are also connected but not utilized in this code snippet.