Arduino UNO-Based Fire Detection and Extinguishing Robot with Flame Sensors and Servo Control
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to detect flames using multiple flame sensors and control a robot equipped with motors and a servo to extinguish the fire. The system uses an Arduino UNO microcontroller to read sensor data, control the motors, and activate a fire extinguisher mechanism.
Component List
Arduino UNO
- Description: Microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
KY-026 Flame Sensor
- Description: Flame sensor module for detecting fire.
- Pins: A0, GND, VCC, D0
L293D Motor Driver
- Description: Motor driver IC for controlling DC motors.
- Pins: pin 1, pin 2, pin 10, pin 9, pin 12, pin 11, pin 5, pin 6, pin 7, pin 8, pin 3, pin 4
Hobby Gearmotor with 48:1 gearbox
- Description: DC motor with a 48:1 gearbox for increased torque.
- Pins: pin 1, pin 2
Servo
- Description: Servo motor for precise control of angular position.
- Pins: GND, VCC, PWM
1N4007 Rectifier Diode
- Description: General-purpose rectifier diode.
- Pins: Cathode, Anode
Wiring Details
Arduino UNO
5V connected to:
- VCC of KY-026 Flame Sensor
- VCC of Servo
- VCC of another KY-026 Flame Sensor
- VCC of another KY-026 Flame Sensor
GND connected to:
- GND of KY-026 Flame Sensor
- GND of another KY-026 Flame Sensor
- GND of another KY-026 Flame Sensor
- GND of Servo
A0 connected to:
- D0 of KY-026 Flame Sensor
A1 connected to:
- D0 of another KY-026 Flame Sensor
A2 connected to:
- D0 of another KY-026 Flame Sensor
D6 connected to:
- PWM of Servo
D8 connected to:
- pin 5 of L293D Motor Driver
D9 connected to:
- pin 6 of L293D Motor Driver
D10 connected to:
- pin 7 of L293D Motor Driver
D11 connected to:
- pin 8 of L293D Motor Driver
KY-026 Flame Sensor
VCC connected to:
- 5V of Arduino UNO
GND connected to:
- GND of Arduino UNO
D0 connected to:
- A0 of Arduino UNO
Another KY-026 Flame Sensor
VCC connected to:
- 5V of Arduino UNO
GND connected to:
- GND of Arduino UNO
D0 connected to:
- A1 of Arduino UNO
Another KY-026 Flame Sensor
VCC connected to:
- 5V of Arduino UNO
GND connected to:
- GND of Arduino UNO
D0 connected to:
- A2 of Arduino UNO
L293D Motor Driver
pin 5 connected to:
- D8 of Arduino UNO
pin 6 connected to:
- D9 of Arduino UNO
pin 7 connected to:
- D10 of Arduino UNO
pin 8 connected to:
- D11 of Arduino UNO
pin 10 connected to:
- pin 1 of Hobby Gearmotor with 48:1 gearbox
pin 9 connected to:
- pin 2 of Hobby Gearmotor with 48:1 gearbox
pin 12 connected to:
- pin 1 of another Hobby Gearmotor with 48:1 gearbox
pin 11 connected to:
- pin 2 of another Hobby Gearmotor with 48:1 gearbox
Hobby Gearmotor with 48:1 gearbox
pin 1 connected to:
- pin 10 of L293D Motor Driver
pin 2 connected to:
- pin 9 of L293D Motor Driver
Another Hobby Gearmotor with 48:1 gearbox
pin 1 connected to:
- pin 12 of L293D Motor Driver
pin 2 connected to:
- pin 11 of L293D Motor Driver
Servo
VCC connected to:
- 5V of Arduino UNO
GND connected to:
- GND of Arduino UNO
PWM connected to:
- D6 of Arduino UNO
Code Documentation
#include <Servo.h>
// Define motor control pins
int motor1A = 8;
int motor1B = 9;
int motor2A = 10;
int motor2B = 11;
// Define flame sensor input pins
int flameSensor1 = A0;
int flameSensor2 = A1;
int flameSensor3 = A2;
// Define servo motor control pin
int servoPin = 6;
Servo nozzleServo;
// Define solenoid valve control pin
int solenoidPin = 12;
// Threshold for detecting fire
int threshold = 500;
void setup() {
// Initialize motor control pins as outputs
pinMode(motor1A, OUTPUT);
pinMode(motor1B, OUTPUT);
pinMode(motor2A, OUTPUT);
pinMode(motor2B, OUTPUT);
// Initialize flame sensor input pins
pinMode(flameSensor1, INPUT);
pinMode(flameSensor2, INPUT);
pinMode(flameSensor3, INPUT);
// Initialize solenoid pin as output
pinMode(solenoidPin, OUTPUT);
// Attach the servo motor
nozzleServo.attach(servoPin);
// Begin serial communication
Serial.begin(9600);
}
void loop() {
// Read values from flame sensors
int sensorValue1 = analogRead(flameSensor1);
int sensorValue2 = analogRead(flameSensor2);
int sensorValue3 = analogRead(flameSensor3);
// Print sensor values for debugging
Serial.print("Flame Sensor 1: ");
Serial.println(sensorValue1);
Serial.print("Flame Sensor 2: ");
Serial.println(sensorValue2);
Serial.print("Flame Sensor 3: ");
Serial.println(sensorValue3);
// Determine the direction based on sensor values
if (sensorValue1 > threshold) {
// Turn left towards the fire
turnLeft();
} else if (sensorValue2 > threshold) {
// Move forward towards the fire
moveForward();
} else if (sensorValue3 > threshold) {
// Turn right towards the fire
turnRight();
} else {
// Stop if no fire is detected
stopRobot();
}
// Check if any sensor detects fire
if (sensorValue1 > threshold || sensorValue2 > threshold || sensorValue3 > threshold) {
// Activate extinguisher
activateExtinguisher();
} else {
// Deactivate extinguisher
deactivateExtinguisher();
}
delay(500); // Delay for stability
}
// Function to move forward
void moveForward() {
digitalWrite(motor1A, HIGH);
digitalWrite(motor1B, LOW);
digitalWrite(motor2A, HIGH);
digitalWrite(motor2B, LOW);
}
// Function to turn left
void turnLeft() {
digitalWrite(motor1A, LOW);
digitalWrite(motor1B, HIGH);
digitalWrite(motor2A, HIGH);
digitalWrite(motor2B, LOW);
}
// Function to turn right
void turnRight() {
digitalWrite(motor1A, HIGH);
digitalWrite(motor1B, LOW);
digitalWrite(motor2A, LOW);
digitalWrite(motor2B, HIGH);
}
// Function to stop the robot
void stopRobot() {
digitalWrite(motor1A, LOW);
digitalWrite(motor1B, LOW);
digitalWrite(motor2A, LOW);
digitalWrite(motor2B, LOW);
}
// Function to activate the fire extinguisher
void activateExtinguisher() {
nozzleServo.write(90); // Adjust the servo to aim the nozzle
digitalWrite(solenoidPin, HIGH); // Open solenoid valve to release CO2
}
// Function to deactivate the fire extinguisher
void deactivateExtinguisher() {
digitalWrite(solenoidPin, LOW); // Close solenoid valve
}
``