DIY Fire Fighting Robot using Arduino and Ultrasonic Sensor

Published  February 25, 2022   0
R Robo Man
Author
DIY Arduino Fire Fighting Robot using Ultrasonic Sensor

As we have heard many fire accidents take place around us. The Surat fire accident in which many students were trapped in an institute by fire. Even in many homes and offices, such fire accidents take place due to a lack of attention to extinguish the fire after firing on match sticks, incense sticks, cigarettes, etc. “Humans are bound to make mistakes”. So due to such mistakes many times a small fire is enough to destroy everything on its way. In such situations fire brigades if reaches late due to traffic at the hotspot area then there is a huge risk on the lives of many peoples. Even firemen kept their lives in danger to protect people.

Arduino based Fire Fighting Robot

Thus, to combat the situation instead of human beings, fire fighting robots are used in the modern world which navigates the area and extinguishes the fire in a given environment with avoiding any obstacles it faces in its. The principle used in the design is such that it enables the robot to be extended for a more robust system which is to be used to combat actual fires in residential or commercial settings of the area. The main purpose of this arduino project is to create a fully autonomous robot, which means, once the robot is started by the user, it navigates, it searches, and extinguishes the fire on its own, with no assistance or input from the user, with giving an alert message to your phone number and also avoids obstacles in its way. In order to reach this goal, I have selected motors, sensors, fire extinguisher mechanical parts, and general design according to the requirement of the robot. For future scope and for a large system, a replica of the same robot to a large scale with fire-resistant material so that robot cannot be harmed through fire and prevents any cause of harm to humans and properties at an accurate timing level could be made. 

Previosly, we made many robotic projects, including the Arduino based fire Fighting Robot

Component Required for Fire Fighting Robot

Component Required for Firerover

Project Used Hardware

Fire Fighting Robot using Arduino

Arduino UNO/ Arduino mega 2560r3, Flame sensors [(x 3 pieces) out of which 1 has 4-pins and other 2 has 3-pins], Servo Motor (SG90)[x2 pieces ], L298N motor Driver module, Mini DC Submersible Pump, Robot chassis with 4 motors and 4 wheels, A small container, Connecting wires, jumper wires, Water tube, Relay module(5v 1 channel), Batteries(4 li-ion 3.7v 18650 à 3 used in series to make 12v supply and 1 battery is used to power on gsm module, Switch, BMS board, Ultrasonic sensor (HC-SR04), Battery holder, GSM 800l module, 2g sim card, 1kohm, and 2kohm resistors, soldering machine, soldering wire, wire cutter, screw driver, glue sticks and glue gun and some small screws and nuts.

Project Used Software

Arduino IDE

Project Hardware Software Selection

The main brain of this project is Arduino UNO/Mega depending upon applicating features. In my case, I‘m using the gsm module as features are more all pins of Arduino UNO are full so Arduino mega is used. But I cannot find 2g sim card anywhere so without 2g sim card, the alert message feature is useless so without the SMS feature Arduino UNO can be used. L298n motor driver is used to run the 4 motors of the robot. L293d motor driver shield has only some pins left for Arduino so here l298n is used rather than l293d for efficient use of all pins.

L293D Pinout

2 motors of two directions (left, right) are connected parallelly to run all 4 motors. Relay of 5v 1 channel is used to on/off the pump for water flow, for that 9v battery is used. The ultrasonic sensor is used to detect obstacles, with that two servo motors are used one for the obstacle to detecting an obstacle in both directions and the other is for water tube moves up and down. 3 flame sensors are used to detect fire in all 3 directions à left, center, right out of which the center should be of 4 pins so that the fourth pin is of analog pin used to calculate the distance of fire from the robot. Gsm 800l module is used with 2g sim card properly inserted and connected according to the circuit diagram. Arduino IDE software is used to write and admin/upload the code to Arduino.

Fire Fighting Robot

Circuit Diagram

 

 

Fire Fighting Robot using Arduino and Ultrasonic Sensor Circuit Diagram

 

According to the circuit diagram shown, Arduino mega is here the main component. The left flame sensor is connected to pin 2, the right flame sensor is connected to pin 3, center flame sensor is connected to pin4. The center flame sensor if using has 4 pins àvcc, gnd, d0, a0 then a0 (analog) pin of the sensor goes to a1 analog pin of Arduino and d0 goes to digital pin 4 of Arduino and vcc and gnd are connected together with all vcc gnd pins of other components and finally Vcc and GND iof that is connected to Arduino. IN1, IN2, IN3, IN4 of L298n motor driver are connected to digital pin numbers 9,10,11,12 respectively. moto1 out point of the driver is connected to any 2 motors that are parallelly connected of any direction similarly with motor 2 out. check the polarity of motors as both mot1 and mot2 ports has to be connected with the same polarity. So that when the forward function is called by Arduino then all four motors move in forwarding directions. signal pin of the relay goes to pin 5. 9v battery positive and pump positive both go to no and common pin of relay respectively. Both negatives are interconnected. Now signal of servo of the water tube is connected to pin no 6 and the signal of servo of the obstacle is connected to pin no 7. Trigger pin of hc -sr04 ultrasonic sensor is connected analog pin a2 of Arduino and echo pin of ultrasonic sensor is connected to analog pin a3 of Arduino. All +5v and grounds are connected together and then connected to 5v and gnd of arduino. Make 12v power supply by connecting 3 li-ion 3.7v in series, the positive of it goes to +12v of l298n through switch and ground to gnd of l298n, connect +5v and gnd of l298n to +5v and gnd of Arduino. Connect +5v and gnd of gsm to 3.7v 18650 li-ion battery. Insert 2g sim card properly as shown in the picture. Now connect TX of gsm to digital pin 14 of Arduino and RX of gsm to digital pin 15 of Arduino with 3.3v voltage divider in between using 1k ohm and 2k ohm resistors, connect both resistors together and connect to rx of gsm and another point of 2k resistor is connected to gnd and another point of 1k resistor is connected to pin 15 of Arduino.

Code
//FIREROVER //
//*------ Arduino Fire Fighting Robot Code----- *//
//By ~ RHYTHM SHAH //
#include <NewPing.h>
#include <Servo.h>
#include <SoftwareSerial.h>
//Create software serial object to communicate with SIM800L
SoftwareSerial mySerial(14, 15); //SIM800L Tx & Rx is connected to Arduino #14 & #15
Servo myservo;
Servo servo;
int pos = 0;    
boolean fire = false;
/*-------defining Inputs------*/
#define Left_S 2      // left sensor
#define Right_S 3     // right sensor
#define Forward_S 4  //forward sensor
#define TRIGGER_PIN A2
#define ECHO_PIN A3
/*-------defining Outputs------*/
#define IN1 9       // left motor
#define IN2 10       // left motor
#define IN3 11      // right motor
#define IN4 12       // right motor
#define pump 5
const int sensorMin = 0;     // sensor minimum
const int sensorMax = 1024;  // sensor maximum
#define max_distance 50
NewPing sonar(TRIGGER_PIN, ECHO_PIN, max_distance);
int distance = 0;
int leftDistance;
int rightDistance;
boolean object;
void setup()
{
  randomSeed(analogRead(0));
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
 //Begin serial communication with Arduino and SIM800L
  mySerial.begin(9600);
  Serial.println("Initializing...");
  pinMode(Left_S, INPUT);
  pinMode(Right_S, INPUT);
  pinMode(Forward_S, INPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(pump, OUTPUT);
  myservo.attach(6);
  myservo.write(90);
  servo.attach(7);
  servo.write(0);
}
void put_off_fire()
{
    delay (500);
    stop() ; delay(10);
   digitalWrite(pump, HIGH);  delay (500);
   for (pos = 50; pos <= 130; pos += 1)
   {
    myservo.write(pos);
    delay(10);  
  }
  for (pos = 130; pos >= 50; pos -= 1) {
    myservo.write(pos);
    delay(10);
  }
 digitalWrite(pump, LOW);
  myservo.write(90);
  fire=false;
}
void loop()
{
   myservo.write(90); //Sweep_Servo();
    // read the sensor on analog A0:
 int sensorReading = analogRead(A1); int range = map(sensorReading, sensorMin, sensorMax, 0, 3);  
    if (digitalRead(Left_S) ==1 && digitalRead(Right_S)==1 && digitalRead(Forward_S) ==1) //If Fire not detected all sensors are zero
    {
    //Do not move the robot
    stop() ;
    }
    else if (digitalRead(Forward_S) ==0) //If Fire is straight ahead
    {
      switch (range) {
  case 0:    // A fire closer than 1.5 feet away.
    Serial.println("** Close Fire **");
    fire = true;
    break;
  case 1:    // A fire between 1-3 feet away.
    Serial.println("** Distant Fire **");
    objectAvoid();
    moveForward(); //Move the robot forward
    break;
   sendSMS();
   Serial.println("message sent.");
   delay(1000);
    }
    else if (digitalRead(Left_S) ==0) //If Fire is to the left
    {
    //Move the robot left
    objectAvoid();
    moveLeft();
    sendSMS();
   Serial.println("message sent.");
   delay(1000);
    }
    else if (digitalRead(Right_S) ==0) //If Fire is to the right
    {
    //Move the robot right
    objectAvoid();
    moveRight();
    sendSMS();
   Serial.println("message sent.");
   delay(1000);
    }
delay(300); //Slow down the speed of robot
     while (fire == true)
     {
      put_off_fire();
     }
}
void objectAvoid() {
  distance = getDistance();
  if (distance <= 15) {
    //stop
    stop();
    lookLeft();
    lookRight();
    delay(100);
    if (rightDistance <= leftDistance) {
      //left
      object = true;
      turn();
    } else {
      //right
      object = false;
      turn();
    }
    delay(100);
  }
  else {
    //forword
    moveForward();
  }
}
int getDistance() {
  delay(50);
  int cm = sonar.ping_cm();
  if (cm == 0) {
    cm = 100;
  }
  return cm;
}
int lookLeft () {
  //look left
  servo.write(150);
  delay(500);
  leftDistance = getDistance();
  delay(100);
  servo.write(90);
  return leftDistance;
  delay(100);
}
int lookRight() {
  //look right
  servo.write(30);
  delay(500);
  rightDistance = getDistance();
  delay(100);
  servo.write(90);
  return rightDistance;
  delay(100);
}
void turn() {
  if (object == false) {
   
    moveLeft();
    delay(700);
    moveForward();
    delay(800);
    moveRight();
    delay(900);
    if (digitalRead(Right_S) ==0) {
      loop();
    } else {
      moveForward();
    }
  }
  else {
    moveRight();
    delay(700);
    moveForward();
    delay(800);
    moveLeft();
    delay(900);
    if (digitalRead(Left_S) ==0) {
      loop();
    } else {
      moveForward();
    }
  }
}
void moveRight() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
}
void moveLeft() {
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, HIGH);
 digitalWrite(IN3, HIGH);
 digitalWrite(IN4, LOW);
}
void stop() {
 digitalWrite(IN1, HIGH);
 digitalWrite(IN2, HIGH);
 digitalWrite(IN3, HIGH);
 digitalWrite(IN4, HIGH);
}
void moveForward() {
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}
void sendSMS()
{
  mySerial.println("AT"); //Once the handshake test is successful, it will back to OK
  updateSerial();
  mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
  updateSerial();
  mySerial.println("AT+CMGS=\"+ZZxxxxxxxxxxx\"");//change ZZ with country code and xxxxxxxxxxx with phone number to sms
  updateSerial();
  mySerial.print("FIRE DETECTED !!"); //text content
  updateSerial();
  mySerial.write(26);
}
void updateSerial()
{
  delay(500);
  while (Serial.available())
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available())
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}
Video

Have any question realated to this Article?

Ask Our Community Members