In this DIY project, we will build a Fire-Fighting Robot that can detect and extinguish fire using flame sensors and a water-spraying mechanism. This robot is an ideal starter project for those interested in robotics, Arduino, and embedded systems.
Overview
This fire-fighting robot uses:
- Two flame sensors to detect fire direction (left or right)
- An ultrasonic sensor to avoid obstacles
- A relay-controlled submersible pump to spray water
- DC motors controlled by L298N motor driver to move the robot
Components Required
Component | Quantity |
---|---|
Arduino UNO | 1 |
Flame Sensor Module | 2 |
Ultrasonic Sensor (HC-SR04) | 1 |
L298N Motor Driver Module | 1 |
DC Motors with wheels | 2 or 4 |
Submersible Water Pump | 1 |
Relay Module (5V) | 1 |
12V Battery or Power Supply | 1 |
Chassis for Robot | 1 |
Jumper Wires | Several |
Breadboard (optional) | 1 |
Wiring Connection
Flame Sensors:
- FLAME_LEFT → Digital Pin 2
- FLAME_RIGHT → Digital Pin 3
- (Connect VCC to 5V, GND to GND)
Ultrasonic Sensor (HC-SR04):
- Trig Pin → Digital Pin 8
- Echo Pin → Digital Pin 9
- Connect VCC to 5V, GND to GND)
L298N Motor Driver:
- IN1 → Pin 4
- IN2 → Pin 5
- IN3 → Pin 6
- IN4 → Pin 7
- ENA → Pin 10 (PWM)
- ENB → Pin 11 (PWM)
- Connect motors to OUT1/OUT2 and OUT3/OUT4 respectively
- Power the motor driver with a separate 12V source for motors
Relay and Pump:
- Relay Input → Pin 12
- Pump +ve → Relay Output
- Pump -ve → GND
Note: Make sure to use a flyback diode across the pump terminals for protection.
Flyback Diode Placement (for your setup)
Component Connected To Pump +ve Relay output terminal Pump −ve Battery GND Diode Cathode (stripe end) Pump +ve (Relay output) Diode Anode (plain end) Pump −ve (Battery GND)
How It Works
- Flame Detection
- The flame sensors detect the presence and direction of fire.
LOW
signal indicates fire detected.
- Obstacle Avoidance
- The ultrasonic sensor checks for obstacles. If something is within 15 cm, the robot stops to avoid collision.
- Movement Logic
- If flame is detected on the left: the robot turns left
- If flame is on the right: it turns right
- If flame is detected straight ahead: it stops and activates the water pump for 3 seconds
- If no flame is detected: it stops and turns off the pump
- Water Pump Activation
- A relay is used to switch on a 5V/12V submersible pump to extinguish the fire
Arduino Code
// --- Pin Definitions ---
#define FLAME_LEFT 2
#define FLAME_RIGHT 3
#define TRIG_PIN 8
#define ECHO_PIN 9
#define RELAY_PIN 12
#define IN1 4
#define IN2 5
#define IN3 6
#define IN4 7
#define ENA 10
#define ENB 11
#define STOP_DISTANCE 15 // cm
void setup() {
Serial.begin(9600);
pinMode(FLAME_LEFT, INPUT);
pinMode(FLAME_RIGHT, INPUT);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH); // Relay off (active LOW)
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
stopMotors();
}
void loop() {
int flameL = digitalRead(FLAME_LEFT);
int flameR = digitalRead(FLAME_RIGHT);
long distance = getDistance();
bool flameDetected = (flameL == LOW || flameR == LOW);
Serial.print("Flame L: "); Serial.print(flameL);
Serial.print(" | Flame R: "); Serial.print(flameR);
Serial.print(" | Distance: "); Serial.println(distance);
if (flameDetected) {
if (distance > 0 && distance < STOP_DISTANCE) {
stopMotors();
digitalWrite(RELAY_PIN, LOW); // Turn ON pump
Serial.println("Fire detected & close! Spraying...");
delay(3000); // Spray for 3 seconds
digitalWrite(RELAY_PIN, HIGH); // Turn OFF pump
} else if (distance >= STOP_DISTANCE) {
moveForward();
digitalWrite(RELAY_PIN, HIGH); // Keep pump OFF
Serial.println("Fire detected, moving closer...");
}
} else {
stopMotors();
digitalWrite(RELAY_PIN, HIGH); // Pump OFF
Serial.println("No fire. Standing by...");
}
delay(200);
}
// --- Motor Functions ---
void moveForward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
analogWrite(ENA, 150);
analogWrite(ENB, 150);
}
void stopMotors() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
analogWrite(ENA, 0);
analogWrite(ENB, 0);
}
// --- Ultrasonic Function ---
long getDistance() {
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
long duration = pulseIn(ECHO_PIN, HIGH, 20000); // Timeout after 20ms
if (duration == 0) return -1; // Invalid reading
return duration * 0.034 / 2;
}
Testing Your Robot
- Upload the code to your Arduino using the Arduino IDE.
- Power the Arduino and motor driver.
- Place a small candle or lighter in front of the robot.
- Watch it detect the flame, navigate toward it, and spray water!
Safety Tips
- Use low flame sources like candles for testing.
- Never test near flammable materials.
- Use protective gloves and goggles while handling fire and water.
Future Improvements
- Add camera module for vision-based flame detection.
- Use IR sensors for better obstacle detection.
- Add Bluetooth/Wi-Fi for remote control.
- Incorporate fire extinguisher spray instead of water pump.