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

Arduino-Controlled Firefighting Robot with Bluetooth and Ultrasonic Sensing

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

Circuit Documentation

Summary

This circuit is designed to control a robot with various sensors and actuators. It includes flame sensors for fire detection, a motor driver for wheel movement, a water pump for fire extinguishing, an ultrasonic sensor for distance measurement, and a Bluetooth module for wireless communication. The brain of the robot is an Arduino UNO microcontroller, which processes sensor data and controls actuators accordingly. The circuit is powered by a battery case, and voltage regulation is managed by an LM2596 buck converter. A relay is used to control the water pump, and switches are included for manual control.

Component List

Sensors

Actuators

Control

Power

Switches

Wiring Details

KY-026 Flame Sensor

Ultrasonic Sensor

Motor and Wheels

Servo Motor

Water Pump

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); // Reduce speed for turning
  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