An autonomous fire-fighting robot car built with ESP32, featuring automatic flame detection, tracking, and extinguishing capabilities with manual override control via WiFi. This smart robot car mainly automatically finds and fights fires using flame sensors and a water pump system until it doesn't detect any fire around it.
This project is an ESP32-based autonomous firefighter robot car that can detect, track, and extinguish flames. It features both automatic and manual control modes accessible through a responsive web interface. The robot uses flame sensors for fire detection, a servo-mounted water pump for extinguishing, and a dual-motor drive system for navigation.
- ๐ค Autonomous Fire Detection: Three flame sensors (left, center, right) for 180ยฐ fire detection
- ๐ฏ Smart Tracking: Automatically rotates and moves toward detected flames
- ๐ง Servo-Controlled Water Spray: Sweeping water spray pattern for effective fire suppression
- ๐ฑ WiFi Web Interface: Control the robot from any device connected to its WiFi network
- ๐ Dual Mode Operation:
- AUTO Mode: Autonomous fire detection and extinguishing
- MANUAL Mode: Full directional control via web interface
- ๐ฎ Responsive Controls: Real-time button controls with visual feedback
- โก PWM Motor Control: Smooth speed control for precise movements
| Component | Quantity | Description |
|---|---|---|
| ESP32 Development Board | 1 | Main microcontroller |
| L298N Motor Driver | 1 | Dual H-Bridge for motor control |
| DC Motors (with wheels) | 4 | For robot movement |
| Flame Sensors | 3 | KY-026 or similar IR flame sensors |
| SG90 Servo Motor | 1 | For water nozzle direction control |
| Mini Water Pump | 1 | 3-6V DC submersible pump |
| 5V Relay Module | 1 | To control water pump |
| BC547 NPN Transistor | 1 | For relay switching |
| 1kฮฉ Resistor | 1 | Base resistor for transistor |
| 18650 Batteries | 2-3 | Power supply (7.4V or 11.1V) |
| Battery Holder | 1 | For batteries |
| Jumper Wires | - | Male-to-male and male-to-female |
- Small water container/tank
- Plastic tubing for water delivery
- Switch for main power
- LED indicators
| L298N Pin | ESP32 Pin | Description |
|---|---|---|
| ENA | GPIO 25 | Left motor speed (PWM) |
| IN1 | GPIO 26 | Left motor direction 1 |
| IN2 | GPIO 27 | Left motor direction 2 |
| ENB | GPIO 14 | Right motor speed (PWM) |
| IN3 | GPIO 18 | Right motor direction 1 |
| IN4 | GPIO 13 | Right motor direction 2 |
| 12V/VCC | Battery + | Motor power supply |
| GND | Battery - & ESP32 GND | Common ground |
Note: Remove jumpers on ENA and ENB for PWM speed control.
| Sensor Position | ESP32 Pin | Connection |
|---|---|---|
| Left Flame Sensor | GPIO 34 | Digital OUT โ GPIO 34 |
| Center Flame Sensor | GPIO 35 | Digital OUT โ GPIO 35 |
| Right Flame Sensor | GPIO 32 | Digital OUT โ GPIO 32 |
| VCC (all sensors) | 3.3V | Power |
| GND (all sensors) | GND | Ground |
Sensor Logic: Output = LOW when flame detected, HIGH when no flame.
| Servo Wire | ESP32 Pin | Description |
|---|---|---|
| Signal (Orange/Yellow) | GPIO 33 | PWM control signal |
| VCC (Red) | 5V | Power (can use external 5V if needed) |
| GND (Brown/Black) | GND | Ground |
This circuit uses a BC547 NPN transistor to safely switch the relay from the ESP32:
ESP32 GPIO 23 โ 1kฮฉ Resistor โ BC547 Base (Middle pin)
BC547 Emitter (Left pin) โ GND
BC547 Collector (Right pin) โ Relay IN pin
Relay Module:
โโ VCC โ 5V
โโ GND โ GND
โโ IN โ BC547 Collector
โโ COM โ Pump VCC (+)
โโ NO โ Battery/Power Supply (+)
Water Pump:
โโ Positive โ Relay COM
โโ Negative โ Battery GND
Why use BC547?
- ESP32 GPIO pins output only 3.3V with limited current (~40mA)
- Relay coils typically need 5V and more current
- BC547 acts as a switch, allowing ESP32 to control the relay safely
/* MOTOR PINS (L298N) */
#define ENA 25 // Left motor speed
#define IN1 26 // Left motor direction
#define IN2 27 // Left motor direction
#define ENB 14 // Right motor speed
#define IN3 18 // Right motor direction
#define IN4 13 // Right motor direction
/* SERVO */
#define SERVO_PIN 33 // Water nozzle servo
/* FLAME SENSORS */
#define FLAME_LEFT 34 // Left flame sensor
#define FLAME_CENTER 35 // Center flame sensor
#define FLAME_RIGHT 32 // Right flame sensor
/* RELAY / PUMP */
#define PUMP_RELAY 23 // Pump control via transistor- Fire Detection: The robot continuously monitors all three flame sensors
- Target Acquisition:
- If center sensor detects fire โ Move forward toward flame
- If left sensor detects fire โ Rotate right until center sensor locks on
- If right sensor detects fire โ Rotate left until center sensor locks on
- Approach: Robot moves closer to the fire for 0.6 seconds
- Verification: Double-checks if fire is still detected by center sensor
- Extinguish: Executes spray cycle:
- Activates water pump
- Servo sweeps from 70ยฐ to 110ยฐ and back (covering the fire area)
- Pump turns off after spray cycle
- Repeat: Returns to scanning mode
- User has full control via web interface
- Directional buttons: Forward, Backward, Left, Right
- Manual water pump control (hold to spray)
- Stop button for emergency halt
- WiFi Access Point: Robot creates "FireFighter_Bot" network (password: 12345678)
- Control Panel: Responsive web interface accessible at
http://192.168.4.1 - Features: Mode toggle, directional controls, pump control
Install required libraries:
- ESP32 Board Support
- ESP32Servo library
Steps:
- Open Arduino IDE
- Go to File โ Preferences
- Add ESP32 board URL:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json - Go to Tools โ Board โ Boards Manager, search "ESP32" and install
- Install ESP32Servo library: Sketch โ Include Library โ Manage Libraries โ Search "ESP32Servo"
- Connect ESP32 to computer via USB
- Select board: Tools โ Board โ ESP32 Dev Module
- Select correct COM port: Tools โ Port
- Click Upload button
- Mount motors and motor driver on chassis
- Connect all components according to circuit diagram
- Secure ESP32, sensors, and relay module
- Mount servo with water nozzle at front
- Attach water container and connect tubing to pump
- Connect battery (ensure proper voltage: 7.4V-11.1V)
- Power on the robot
- Wait for ESP32 to boot (~5 seconds)
- On your phone/laptop, connect to WiFi:
- SSID:
FireFighter_Bot - Password:
12345678
- SSID:
- Open browser and go to:
http://192.168.4.1
Mode Selection:
- AUTO: Robot autonomously detects and fights fires
- MANUAL: User controls all movements
Manual Controls:
- โฒ Forward
- โผ Backward
- โ Turn Left
- โบ Turn Right
- โ Stop
- HOLD FOR WATER ๐ง: Press and hold to activate pump
- Start in MANUAL mode to test motors and pump
- Switch to AUTO mode
- Use a lighter or candle to test flame detection
- Observe robot's tracking and extinguishing behavior
/* Main Sections */
โโ WiFi & WebServer Setup
โโ Pin Definitions
โโ Global Variables (mode, speeds)
โโ setup() - Initialize all components
โโ loop() - Main logic
โ โโ Auto mode: Flame detection & response
โ โโ Manual mode: Web command processing
โโ executeSprayCycle() - Water spray pattern
โโ Motor Control Functions
โ โโ moveForward()
โ โโ moveBackward()
โ โโ turnLeft()
โ โโ turnRight()
โ โโ stopMoving()
โโ handleRoot() - Web interface HTML/CSS| Problem | Possible Solution |
|---|---|
| Motors don't move | โข Check L298N connections โข Ensure battery is charged โข Verify ENA/ENB jumpers are removed โข Check motor polarity |
| Wrong direction | Swap IN1โIN2 or IN3โIN4 connections, or modify LEFT_FORWARD_LOGIC and RIGHT_FORWARD_LOGIC constants in code |
| Pump doesn't activate | โข Check relay connections โข Verify BC547 transistor orientation โข Test relay with multimeter โข Check pump power supply |
| Flame sensors not detecting | โข Adjust sensor sensitivity (potentiometer on sensor) โข Check 3.3V power supply โข Test sensors individually with Serial monitor |
| Can't connect to WiFi | โข Reset ESP32 โข Check WiFi credentials in code โข Ensure device WiFi is enabled |
| Servo jitters | โข Use external 5V power source for servo โข Add capacitor across servo power lines |
| Robot moves too fast/slow | Adjust motorSpeed and turnSpeed variables (0-255 range) |
- Add temperature sensor for heat detection
- Implement obstacle avoidance with ultrasonic sensors
- Battery level monitoring and low battery warning
- Add buzzer for audio alerts
- Implement camera streaming for remote monitoring
- Add GPS module for location tracking
- Create mobile app for better control interface
- Multiple pump nozzles for wider coverage
- Data logging to SD card
- Integration with IoT platforms (Firebase, Blynk)
This project is open-source and available under the MIT License.
- Mehedi Hasan
- Farhana Alam
โญ If you found this project helpful, please give it a star! โญ


