Arduino UNO Based Fire-Fighting Robot with L298N Motor Driver and Flame Sensors
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary of the Circuit
This circuit is designed to control a robotic system that can detect flames using multiple flame sensors and respond by activating a water pump and maneuvering to put out the fire. The system is controlled by an Arduino UNO microcontroller, which interfaces with flame sensors, a servo motor, DC motors for movement, and a water pump for extinguishing the fire. The Arduino UNO also controls the speed and direction of the DC motors through an L298N DC motor driver. A 12V battery powers the system, with a rocker switch to control power flow.
Component List
Arduino UNO
- Microcontroller board based on the ATmega328P
- Provides digital and analog I/O pins for interfacing with various sensors and actuators
L298N DC Motor Driver
- Dual H-bridge motor driver
- Capable of driving two DC motors or one stepper motor
L293D Motor Driver Module
- Motor driver module for controlling DC motors
- Provides an H-bridge for controlling the direction of a motor
12V Battery
- Provides the power source for the circuit
- Powers the motors and the motor driver modules
Mini Diaphragm Water Pump
- Used for pumping water to extinguish detected flames
- Powered by the motor driver module
Rocker Switch
- Acts as a power switch for the circuit
- Controls the connection between the battery and the motor drivers
Servo
- A rotary actuator that allows for precise control of angular position
- Used for directing the water pump nozzle
KY-026 Flame Sensor (x3)
- Detects the presence of a flame or fire
- Provides both analog and digital outputs
DC Motor (x4)
- Converts electrical energy into mechanical motion
- Used for the movement of the robotic system
Wiring Details
Arduino UNO
5Vconnected to VCC of all KY-026 Flame Sensors and ServoGNDconnected to GND of all KY-026 Flame Sensors, Servo, L298N DC motor driver, and L293D Motor Driver ModuleVinconnected to5Vof L298N DC motor driver- Digital pins
D2toD12connected to various control pins of the L298N DC motor driver, Servo, and KY-026 Flame Sensors
L298N DC Motor Driver
5Vconnected toVinof Arduino UNOGNDconnected to GND of Arduino UNOIN1,IN2,IN3,IN4,ENA, andENBconnected to corresponding digital pins on Arduino UNOOUT1,OUT2,OUT3,OUT4connected to DC Motors12Vconnected to the output of the rocker switch
L293D Motor Driver Module
GNDconnected to GND of 12V BatteryM1connected to Mini Diaphragm Water Pump12Vconnected to the output of the rocker switch
12V Battery
+connected to the input of the rocker switch and12Vof L293D Motor Driver Module-connected to GND of L293D Motor Driver Module, L298N DC motor driver, and Arduino UNO
Mini Diaphragm Water Pump
Negative (-)connected toM1of L293D Motor Driver ModulePositive (+)connected toM1of L293D Motor Driver Module
Rocker Switch
inputconnected to+of 12V Batteryoutputconnected to12Vof L298N DC motor driver and12Vof L293D Motor Driver Module
Servo
vccconnected to5Vof Arduino UNOgndconnected to GND of Arduino UNOpulseconnected toD11of Arduino UNO
KY-026 Flame Sensors
VCCconnected to5Vof Arduino UNOGNDconnected to GND of Arduino UNOD0connected to digital pinsD8,D9, andD10of Arduino UNO for each sensor respectively
DC Motors
pin 1andpin 2of each motor connected toOUT1,OUT2,OUT3, andOUT4of L298N DC motor driver
Documented Code
#include <Servo.h> // Include the Servo library
Servo myservo; // Create a servo object
int pos = 0; // Variable to store the servo position
int motor_speed = 70; // Set the motor speed
boolean fire = false; // Flag for fire detection
// Define sensor and motor control pins
#define Left 9 // Left sensor
#define Right 10 // Right sensor
#define Forward 8 // Front sensor
#define LM1 2 // Left motor
#define LM2 7 // Left motor
#define RM1 4 // Right motor
#define RM2 12 // Right motor
#define pump 6 // Water pump
void setup() {
// Set pin modes
pinMode(Left, INPUT);
pinMode(Right, INPUT);
pinMode(Forward, INPUT);
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(RM1, OUTPUT);
pinMode(RM2, OUTPUT);
pinMode(pump, OUTPUT);
// Set motor speed
analogWrite(3, motor_speed);
analogWrite(5, motor_speed);
// Attach the servo to pin D11 and set initial position
myservo.attach(11);
myservo.write(90);
}
void put_off_fire() {
delay(500);
// Activate motors and pump
digitalWrite(LM1, HIGH);
digitalWrite(LM2, HIGH);
digitalWrite(RM1, HIGH);
digitalWrite(RM2, HIGH);
digitalWrite(pump, HIGH);
delay(500);
// Sweep the servo from 50 to 130 degrees
for (pos = 50; pos <= 130; pos += 1) {
myservo.write(pos);
delay(10);
}
// Sweep the servo back to 50 degrees
for (pos = 130; pos >= 50; pos -= 1) {
myservo.write(pos);
delay(10);
}
// Turn off the pump and reset servo position
digitalWrite(pump, LOW);
myservo.write(90);
fire = false;
}
void loop() {
myservo.write(90); // Reset servo position
// Check flame sensors and control motors accordingly
if (digitalRead(Left) == 1 && digitalRead(Right) == 1 && digitalRead(Forward) == 1) {
digitalWrite(LM1, HIGH);
digitalWrite(LM2, HIGH);
digitalWrite(RM1, HIGH);
digitalWrite(RM2, HIGH);
} else if (digitalRead(Forward) == 0) {
digitalWrite(LM1, HIGH);
digitalWrite(LM2, LOW);
digitalWrite(RM1, HIGH);
digitalWrite(RM2, LOW);
fire = true;
} else if (digitalRead(Left) == 0) {
digitalWrite(LM1, HIGH);
digitalWrite(LM2, LOW);
digitalWrite(RM1, HIGH);
digitalWrite(RM2, HIGH);
} else if (digitalRead(Right) == 0) {
digitalWrite(LM1, HIGH);
digitalWrite(LM2, HIGH);
digitalWrite(RM1, HIGH);
digitalWrite(RM2, LOW);
}
delay(300); // Delay for sensor reading stability
// If fire is detected, activate fire extinguishing routine
while (fire == true) {
put_off_fire();
}
}
This code controls the robotic system's response to flame detection. It reads inputs from the flame sensors and activates the motors and water pump to navigate towards the fire and extinguish it. The servo motor is used to sweep the water stream across the area to ensure the fire is put out effectively.