Back to Tutorial

ESP32-Based Autonomous Fire Extinguisher Bot


🔥 FIRE BOT – Bluetooth Controlled Fire Extinguisher Robot

Welcome to the FIRE BOT project! This robot is designed to detect and extinguish small fires using a flame sensor and a water pump. It is fully controllable via Bluetooth, making it ideal for educational or experimental firefighting applications.


🧠 Features

  • 🔥 Flame detection
  • 💧 Water pump activation
  • 🎮 Bluetooth remote control (with mobile app)
  • 🛞 Motor movement: Forward, Reverse, Left, Right
  • 🔁 Servo motor to aim the water spray
  • 🧪 Manual + Automatic mode supported

📦 Hardware Used

  • Arduino Uno (or compatible board)
  • L298N Dual H-Bridge Motor Driver
  • 2 DC Motors (for movement)
  • Bluetooth module (HC-05/HC-06)
  • Flame sensor
  • Water pump
  • Servo motor (SG90 recommended)
  • Power source (Li-ion battery pack or similar)
  • Jumper wires and chassis

📜 Arduino Code Breakdown

#include <Servo.h>
#include <L298NX2.h>

#define LED_BUILTIN 2

  • Servo.h: Controls the servo motor.
  • L298NX2.h: Custom library to control two motors via L298N.
  • LED_BUILTIN: Unused, default Arduino LED.

🧩 Pin Definitions

#define IN_1 2
#define IN_2 3
#define IN_3 4
#define IN_4 5
#define F1 10
#define PUMP 6
#define SERVO 9

ComponentArduino PinDescription
Motor A2, 3L298N IN1 & IN2
Motor B4, 5L298N IN3 & IN4
Pump Relay6Controls water pump
Servo Motor9Spray aiming
Flame Sensor10Input from flame sensor

🚀 Setup Function

void setup() {
myservo.attach(SERVO);
Serial.begin(9600);
pinMode(PUMP, OUTPUT);
pinMode(F1, INPUT);

// Motor & Pump Test
mybot.forward();
delay(5000);
mybot.stop();
mybot.backward();
delay(5000);
mybot.stop();

myservo.write(90); // center
delay(1000);
myservo.write(180); // right
digitalWrite(PUMP, HIGH); // test spray
}

Initializes serial, servo, motors, and flame sensor.

Performs a full functional test at startup.

🔄 Main Loop

Flame Detection (Optional Auto Mode)

f1 = digitalRead(F1); Serial.print(f1);
Optional logic for auto mode:

 
if (f1 == 1)
 digitalWrite(PUMP, HIGH);
 else
digitalWrite(PUMP, LOW);
Uncomment for automatic spraying based on flame sensor.

🔗 Bluetooth Command Handling

while (Serial.available() > 0) 
{
bdata = Serial.read();
switch (bdata) {
...
}
}

📱 Bluetooth Commands

CommandActionDescription
FMove ForwardBoth motors move forward
BMove BackwardBoth motors move backward
LTurn LeftLeft spin using motor logic
RTurn RightRight spin using motor logic
SStopStops all motors
VPump ONActivates pump to spray water
vPump OFFTurns off the pump
WServo Move RightServo rotates from 0 to 90
wServo Move LeftServo rotates back from 90 to 0

🖼️ How It Works

  1. Use a Bluetooth app (like “Bluetooth RC Controller”) to send commands.
  2. The robot responds with motor control, pump activation, and servo aiming.
  3. Optionally, the flame sensor detects fire and triggers the pump automatically.
HOW TO OPERATE

#include <Servo.h>
#include <L298NX2.h>

#define LED_BUILTIN 2

//-------------L298---------------------------------------------------
// Motor 1 settings
#define IN_1 2 //rx2
#define IN_2 3 //tx2

// Motor 2 settings
#define IN_3 4 //d4
#define IN_4 5 //d5

#define F1 10


L298NX2 mybot(IN_1, IN_2, IN_3, IN_4); // for full speed


//---------Bluetooth RC Controller Define----
#define PUMP 6   //D6
#define SERVO 9  //D9


char bdata; // for bluetooth command store

Servo myservo;
int f1;

void setup() {
  myservo.attach(SERVO);
  Serial.begin(9600);

 
  pinMode(PUMP, OUTPUT);
  pinMode(F1, INPUT);



  // Testing
  mybot.forward();
  delay(5000);
  mybot.stop();
  mybot.backward();
  delay(5000);
  mybot.stop();
  myservo.write(90);
  delay(1000);
  myservo.write(180);
  digitalWrite(PUMP, HIGH);
  // Test done
}

void loop() {
  f1 = digitalRead(F1);
 

  Serial.print(f1);
  Serial.print("\t");

//  if automatic then remove comment

  // if (f1 == 1)
  //   digitalWrite(PUMP, HIGH);
  // else
  //   digitalWrite(PUMP, LOW);

 

  while (Serial.available() > 0) {
    bdata = Serial.read();
    Serial.println(bdata);

    // Make condition based on BLE data
    switch (bdata) {
      case 'F':
        Serial.println("Forward");
        mybot.forward();
        break;

      case 'B':
        Serial.println("Reverse");
        mybot.backward();
        break;

      case 'L':
        Serial.println("Left");
        mybot.forwardA();
        mybot.backwardB();
        break;

      case 'R':
        Serial.println("Right");
        mybot.forwardB();
        mybot.backwardA();
        break;

      case 'S':
        Serial.println("Stop");
        mybot.stop();
        break;

      case 'V':
        Serial.println("PUMP ON");
        digitalWrite(PUMP, HIGH);
        break;

      case 'v':
        Serial.println("PUMP LOW");
        digitalWrite(PUMP, LOW);
        break;

      case 'W':
        Serial.println("SERVO MOVE");
        for (int pos = 0; pos < 90; pos++)
          myservo.write(pos);
        break;

      case 'w':
        Serial.println("SERVO BACK");
        for (int pos = 90; pos >= 0; pos--)
          myservo.write(pos);
        break;
    }
  }
}

Share this post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to Tutorial