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

Arduino-Controlled Firefighting Robot with Ultrasonic Obstacle Detection and Bluetooth Interface

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Firefighting Robot with Ultrasonic Obstacle Detection and Bluetooth Interface

Circuit Documentation

Summary

The circuit in question appears to be a robotic system equipped with various sensors, actuators, and control modules. It includes flame sensors for fire detection, an ultrasonic sensor for distance measurement, motors for movement, a water pump for extinguishing fires, and an Arduino UNO microcontroller for processing and control. The system also features a Bluetooth module for wireless communication, a motor driver for controlling the motors, a relay for switching the water pump, and power management components such as a battery case and a buck converter. The robot is designed to navigate, detect flames, and take action to extinguish fires, with the capability to be controlled remotely via Bluetooth.

Component List

Sensors

Actuators

Control Modules

Power Management

Switches

Wiring Details

KY-026 Flame Sensor

Ultrasonic Sensor

Motor and Wheels

Water Pump

Servo Motor

Arduino UNO

HC-05 Bluetooth Module

L298N DC Motor Driver

Relay 5V Single Connection

LM2596 Buck Converter

Rocker Switch

Toggle Switch SPST

Documented Code

Arduino UNO (Main Controller)

#include <Wire.h>
#include <Servo.h>
#include <Adafruit_MLX90614.h>
#include <SoftwareSerial.h>

// Define Ultrasonic Sensor Pins
#define TRIG_PIN A3
#define ECHO_PIN A2

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

// Define pins for flame sensors
#define FLAME_SENSOR_LEFT 4
#define FLAME_SENSOR_RIGHT 13
#define FLAME_SENSOR_FRONT 11

#define LM1 6  // Left motor forward
#define LM2 7  // Left motor backward
#define RM1 8  // Right motor forward
#define RM2 9  // Right motor backward
#define PUMP_PIN A1 // Water pump

#define enA 5  // Enable pin for left motor
#define enB 10 // Enable pin for right motor

#define BUZZER_PIN 3  // Buzzer pin

#define BLUETOOTH_RX 12
#define BLUETOOTH_TX 2

// Distance threshold to stop the robot (in cm)
#define DISTANCE_THRESHOLD 20

// Create SoftwareSerial object for Bluetooth communication
SoftwareSerial bluetooth(BLUETOOTH_TX, BLUETOOTH_RX);

void setup() {
  // Initialize serial communication for Bluetooth
  bluetooth.begin(9600);
  Serial.begin(9600);

  // Motor pins setup
  pinMode(LM1, OUTPUT);
  pinMode(LM2, OUTPUT);
  pinMode(RM1, OUTPUT);
  pinMode(RM2, OUTPUT);

  // Sensors and actuators setup
  pinMode(FLAME_SENSOR_LEFT, INPUT);
  pinMode(FLAME_SENSOR_RIGHT, INPUT);
  pinMode(FLAME_SENSOR_FRONT, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(PUMP_PIN, OUTPUT);

  // Ultrasonic sensor setup
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);

  // Initialize actuators to be off
  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(PUMP_PIN, LOW);

  // Initialize MLX90614 sensor
  mlx.begin();
}

void loop() {
  // Read flame sensor values (digital)
  bool leftFlame = digitalRead(FLAME_SENSOR_LEFT);
  bool rightFlame = digitalRead(FLAME_SENSOR_RIGHT);
  bool frontFlame = digitalRead(FLAME_SENSOR_FRONT);

  // Measure distance using the ultrasonic sensor
  long distance = measureDistance();  // This will also print the distance to the Serial Monitor

  // Robot movement logic
  if (distance <= DISTANCE_THRESHOLD) {  // Obstacle detected within threshold
    stopRobot();
    if (!frontFlame) {  // Flame detected in front after stopping
      extinguishFire();
    }
  } else if (!frontFlame) {  // Flame detected in front
    moveForward();
  } else if (!leftFlame) {  // Flame detected on the left
    moveRight();
  } else if (!rightFlame) {  // Flame detected on the right
    moveLeft();
  } else {  // No flame detected
    stopRobot();
  }

  // Bluetooth control
  if (bluetooth.available()) {
    char command = bluetooth.read();
    controlRobotViaBluetooth(command);
  }
}

void moveForward() {
  Serial.println("Moving Forward");
  analogWrite(enA, 120); // Write The Duty Cycle 0 to 255 Enable Pin A for Motor1 Speed 
  analogWrite(enB, 120);
  digitalWrite(LM1, LOW);
  digitalWrite(LM2, HIGH);
  digitalWrite(RM1, LOW);
  digitalWrite(RM2, HIGH);
}

void moveLeft() {
  Serial.println("Turning Left");
  analogWrite(enA, 200); // Write The Duty Cycle 0 to 255 Enable Pin A for Motor1 Speed 
  analogWrite(enB, 200);
  digitalWrite(LM1, LOW); // Left Motor backward Pin 
  digitalWrite(LM2, LOW); // Left Motor forward Pin 
  digitalWrite(RM1, LOW); // Right Motor forward Pin 
  digitalWrite(RM2, HIGH); // Right Motor backward Pin 
}

void moveRight() {
  Serial.println("Turning Right");
  analogWrite(enA, 200); // Reduce speed for turning
  analogWrite(enB, 200);
  digitalWrite(LM1, LOW); // Left Motor backward Pin 
  digitalWrite(LM2, HIGH); // Left Motor forward Pin 
  digitalWrite(RM1, LOW); // Right Motor forward Pin 
  digitalWrite(RM2, LOW); // Right Motor backward Pin 
}

void stopRobot() {
  Serial.println("Stopping Robot");
  digitalWrite(LM1, LOW);
  digitalWrite(LM2, LOW);
  digitalWrite(RM1, LOW);
  digitalWrite(RM2, LOW);
}

void extinguishFire() {
  Serial.println("Extinguishing Fire");
  // Activate buzzer and pump for fire extinguishing
  digitalWrite(BUZZER_PIN, HIGH);
  digitalWrite(PUMP_PIN, HIGH);

  // Run pump for a certain period (adjust time as needed)
  delay(5000