Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Based Fire-Fighting Robot with L298N Motor Driver and Flame Sensors

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Fire-Fighting Robot with L298N Motor Driver and Flame Sensors

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

L298N DC Motor Driver

L293D Motor Driver Module

12V Battery

Mini Diaphragm Water Pump

Rocker Switch

Servo

KY-026 Flame Sensor (x3)

DC Motor (x4)

Wiring Details

Arduino UNO

L298N DC Motor Driver

L293D Motor Driver Module

12V Battery

Mini Diaphragm Water Pump

Rocker Switch

Servo

KY-026 Flame Sensors

DC Motors

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.