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

Arduino-Controlled Bluetooth Robot with IR Obstacle Avoidance and Line Following

Image of Arduino-Controlled Bluetooth Robot with IR Obstacle Avoidance and Line Following

Circuit Documentation

Summary

This circuit is designed to control a robotic vehicle with multiple functionalities including Bluetooth control, line following, obstacle avoidance, and remote control via an IR receiver. The core of the circuit is an Arduino UNO microcontroller which interfaces with an L298N DC motor driver for motor control, HC-05 Bluetooth Module for wireless communication, ultrasonic sensor for distance measurement, IR sensors for line following, and a micro servo for actuation. The circuit is powered by a 7.4V battery, and a rocker switch is used to turn the power on and off.

Component List

L298N DC Motor Driver

  • Description: A module used to control the direction and speed of DC motors.
  • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, ENA, IN1, IN2, IN3, IN4, ENB

HC-05 Bluetooth Module

  • Description: A wireless communication module that allows for Bluetooth connectivity.
  • Pins: Key, VCC, GND, TXD, RXD, State

Ultrasonic Sensor

  • Description: A sensor that measures distance using ultrasonic waves.
  • Pins: +VCC, Trigger, Echo, GND

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Pins: IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13

IR Receiver

  • Description: A module that receives IR signals from a remote control.
  • Pins: DATA, VCC, GND

Micro Servo 9G

  • Description: A small servo motor for precise control of mechanical movement.
  • Pins: GND, +5V, PWM

Rocker Switch

  • Description: A switch to turn the circuit power on and off.
  • Pins: 1, 2

Motor with Reducer (x4)

  • Description: A DC motor with a gear reducer to decrease speed and increase torque.
  • Pins: 3 - 6 VCC, GND

IR Sensor (x2)

  • Description: A sensor that detects IR light reflecting off surfaces for line following.
  • Pins: out, gnd, vcc

7.4V Battery

  • Description: A power source for the circuit.
  • Pins: +, -

HX1838 Infrared IR Wireless Remote Control

  • Description: A remote control that sends IR signals to be received by the IR receiver.
  • Pins: Various buttons with unique IR codes

Wiring Details

L298N DC Motor Driver

  • 12V connected to Rocker Switch and Arduino UNO (Vin)
  • GND connected to 7.4V Battery (-)
  • OUT1, OUT2 connected to Motor with Reducer
  • OUT3, OUT4 connected to Motor with Reducer
  • ENA connected to Arduino UNO (D10)
  • IN1 connected to Arduino UNO (D9)
  • IN2 connected to Arduino UNO (D8)
  • IN3 connected to Arduino UNO (D7)
  • IN4 connected to Arduino UNO (D6)
  • ENB connected to Arduino UNO (D5)

HC-05 Bluetooth Module

  • VCC connected to IR Receiver (VCC)
  • GND connected to IR Receiver (GND)
  • TXD connected to Arduino UNO (D2)
  • RXD connected to Arduino UNO (D3)

Ultrasonic Sensor

  • +VCC connected to Arduino UNO (5V)
  • Trigger connected to Arduino UNO (A3)
  • Echo connected to Arduino UNO (A2)
  • GND connected to common ground

Arduino UNO

  • Vin connected to Rocker Switch and L298N DC Motor Driver (12V)
  • GND connected to common ground
  • 5V connected to common VCC
  • A0 connected to IR Sensor (out)
  • A1 connected to IR Sensor (out)
  • A2 connected to Ultrasonic Sensor (Echo)
  • A3 connected to Ultrasonic Sensor (Trigger)
  • A4 connected to Micro Servo 9G (PWM)
  • A5 connected to IR Receiver (DATA)
  • D2-D10 connected to HC-05 Bluetooth Module and L298N DC Motor Driver as per the control logic

IR Receiver

  • VCC connected to common VCC
  • GND connected to common ground
  • DATA connected to Arduino UNO (A5)

Micro Servo 9G

  • GND connected to common ground
  • +5V connected to common VCC
  • PWM connected to Arduino UNO (A4)

Rocker Switch

  • Pin 1 connected to 7.4V Battery (+)
  • Pin 2 connected to L298N DC Motor Driver (12V) and Arduino UNO (Vin)

Motor with Reducer

  • 3 - 6 VCC connected to L298N DC Motor Driver (OUT1, OUT2, OUT3, OUT4)
  • GND connected to common ground

IR Sensor

  • out connected to Arduino UNO (A0, A1)
  • gnd connected to common ground
  • vcc connected to common VCC

7.4V Battery

    • connected to Rocker Switch
    • connected to common ground

Documented Code

#include <SoftwareSerial.h>
SoftwareSerial BT_Serial(2, 3); // RX, TX

#include <IRremote.h>
const int RECV_PIN = A5;
IRrecv irrecv(RECV_PIN);
decode_results results;

#define enA 10 // Enable1 L298 Pin enA
#define in1 9  // Motor1 L298 Pin in1
#define in2 8  // Motor1 L298 Pin in2
#define in3 7  // Motor2 L298 Pin in3
#define in4 6  // Motor2 L298 Pin in4
#define enB 5  // Enable2 L298 Pin enB

#define servo A4

#define R_S A0 // IR sensor Right
#define L_S A1 // IR sensor Left

#define echo A2    // Echo pin
#define trigger A3 // Trigger pin

int distance_L, distance_F = 30, distance_R;
long distance;
int set = 20;

int bt_ir_data; // Variable to receive data from the serial port and IRremote
int Speed = 130;
int mode = 0;
int IR_data;

void setup() {
  // Initialize pins as inputs or outputs
  pinMode(R_S, INPUT);
  pinMode(L_S, INPUT);
  pinMode(echo, INPUT);
  pinMode(trigger, OUTPUT);
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(servo, OUTPUT);

  // Initialize IR receiver and serial communication
  irrecv.enableIRIn();
  irrecv.blink13(true);
  Serial.begin(9600);
  BT_Serial.begin(9600);

  // Move servo to initial positions
  for (int angle = 70; angle <= 140; angle += 5) {
    servoPulse(servo, angle);
  }
  for (int angle = 140; angle >= 0; angle -= 5) {
    servoPulse(servo, angle);
  }
  for (int angle = 0; angle <= 70; angle += 5) {
    servoPulse(servo, angle);
  }
  delay(500);
}

void loop() {
  // Read Bluetooth data
  if (BT_Serial.available() > 0) {
    bt_ir_data = BT_Serial.read();
    Serial.println(bt_ir_data);
    if (bt_ir_data > 20) {
      Speed = bt_ir_data;
    }
  }

  // Read IR remote data
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    bt_ir_data = IRremote_data();
    Serial.println(bt_ir_data);
    irrecv.resume(); // Receive the next value
    delay(100);
  }

  // Process received data and control the robot
  // ... (rest of the code)
}

// Additional functions for IR data processing, servo control, ultrasonic reading, and motor control
// ... (rest of the functions)

Note: The code provided above is a partial representation of the full code. It includes setup and loop functions, initialization of components, and reading of Bluetooth and IR data. The rest of the code, indicated by comments, would contain the logic for processing the received data and controlling the robot's movements, as well as additional functions for servo control, ultrasonic reading, and motor control.