Fire Fighting Robot Project {HELP}

Hello, I trying to make Fire Fighting Robot Project for school and I need help. I am new to coding for the Arduino. What I'm trying to make this robot do is to be autonomous and use a temperature sensor to detect fires. Once the sensors detected a fire the led will turn ,but the initial plan was to use a
extinguisher like a fan or water to take out the fire. The parts I am using is an Arduino UNO R3, Ultrasonic sensor,Temperature DHT11, IR Flame Sensor, and Smoke sensor and they would be used for detecting the fire. The autonomous portion of the robot works, I need help to make the code for the sensor to detect. Any help will be appreciated, thank you!

Here's what I have now:

#include <AFMotor.h> //import your motor shield library
#define trigPin 12 // define the pins of your sensor
#define echoPin 13
AF_DCMotor motor1(1,MOTOR12_64KHZ); // set up motors.
AF_DCMotor motor2(2, MOTOR12_8KHZ);

void setup() {
Serial.begin(9600); // begin serial communitication
Serial.println("Motor test!");
pinMode(trigPin, OUTPUT);// set the trig pin to output (Send sound waves)
pinMode(echoPin, INPUT);// set the echo pin to input (recieve sound waves)
motor1.setSpeed(105); //set the speed of the motors, between 0-255
motor2.setSpeed (105);
}

void loop()
{

long duration, distance; // start the scan
digitalWrite(trigPin, LOW);
delayMicroseconds(2); // delays are required for a succesful sensor operation.
digitalWrite(trigPin, HIGH);

delayMicroseconds(10); //this delay is required as well!
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;// convert the distance to centimeters.
if (distance < 25)/*if there's an obstacle 25 centimers, ahead, do the following: */ {
Serial.println ("Close Obstacle detected!" );
Serial.println ("Obstacle Details:");
Serial.print ("Distance From Robot is " );
Serial.print ( distance);
Serial.print ( " CM!");// print out the distance in centimeters.

Serial.println (" The obstacle is declared a threat due to close distance. ");
Serial.println (" Turning !");
motor1.run(FORWARD); // Turn as long as there's an obstacle ahead.
motor2.run (BACKWARD);

}
else
{
Serial.println ("No obstacle detected. going forward");
delay (15);
motor1.run(FORWARD); //if there's no obstacle ahead, Go Forward!
motor2.run(FORWARD);
}
}

So what you have there is a pretty standard obstacle avoider that can wander around without bumping into things?

My advice for getting the fire detection part to work, is to split the project into a number of separate but integrated parts. Forget for now that it's a vehicle of some sort, and get only the fire-related sensors working. You can move them around by hand to test if they reliably detect the presence of a fire. I wouldn't even think of having them on a vehicle till I got that sorted. (Except maybe to mount them on the chassis to make sure they fit, but I would not have the vehicle driving around, I'd move it to around the fire by hand.)

To get the fire detection part to work, you'll need to dig out the documentation for the flame, smoke and temperature sensors you have, and get each of those working then figure out how their combined values reliably mean there's a fire to put out.

Then and only then, would I put them on the vehicle which wanders around, and add new logic which gets it to "focus" on the fire once it sees it, and steers accordingly.

Then and only then would I do the extinguishing part.

Thanks I really appreciate it and I will take your advice. I will update you when I do that,and thanks again.

Also could I use this code Arduino made, when I used this code it work and showed the temperature and humidity on the serial monitor. Could I just add the led function when the sensor detect a fire

Code:

// DHT11 Temperature and Humidity Sensors Example
#include "DHT.h" //include DHT library
#define DHTPIN 3 //define as DHTPIN the Pin 3 used to connect the Sensor
#define DHTTYPE DHT11 //define the sensor used(DHT11)
DHT dht(DHTPIN, DHTTYPE);//create an instance of DHT
/setup/
void setup() {
Serial.begin(9600); //initialize the Serial communication
delay(6000); //wait 6 seconds
Serial.println("Temperature and Humidity test!");//print on Serial monitor
Serial.println("T(C) \tH(%)"); //print on Serial monitor
dht.begin(); //initialize the Serial communication
}
/loop/
void loop() {

float h = dht.readHumidity(); // reading Humidity
float t = dht.readTemperature(); // read Temperature as Celsius (the default)
// check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print(t, 2); //print the temperature
Serial.print("\t");
Serial.println(h, 2); //print the humidity
delay(2000); //wait 2 seconds
}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

Step202:
code it work and showed the temperature and humidity on the serial monitor. Could I just add the led function when the sensor detect a fire

I don't think a dht is for detecting a fire. But yeah if you think some value it returns means there's a fire, sure you can turn an led on. You have read the temperature into a variable called "t", so if some value of t, lets say you have that in a variable called "fireThreshold" means a fire, all you need to say is

if (t > fireThreshold)
{
// turn the led on or spray foam or whatever
}

But do you think a dht can really detect a fire? Surely high temp (and I have no idea how high a dht can go) doesn't mean a fire? It might be measuring the heat of a car engine....

edit: I just found a dht11 goes to 50C. Coffee is hotter than that.

In your first post you mentioned a flame detector sensor: purely my opinion but I think that's probably your best chance of finding the fire. That and the smoke detector. But to get those to work you'll need to read the datasheets of the sensors.

manor_royal:
if (t > fireThreshold)
{
// turn the led on or spray foam or whatever
}

I've tried to add the code to the code I already have and for some reason it reads the temperature but doesn't turn on the led. Sorry I am new to coding for Arduino, thanks!

Here's the code:

// DHT11 Temperature and Humidity Sensors Example
int ledPin = 8;
int fireThreshold = 20;
#include "DHT.h"         //include DHT library
#define DHTPIN 7      //define as DHTPIN the Pin 7 used to connect the Sensor
#define DHTTYPE DHT11    //define the sensor used(DHT11)
DHT dht(DHTPIN, DHTTYPE);//create an instance of DHT
/*setup*/
void setup() 
{
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);    //initialize the Serial communication
  delay(6000);           //wait 6 seconds
  Serial.println("Temperature and Humidity test!");//print on Serial monitor
  Serial.println("T(C) \tH(%)");                   //print on Serial monitor
  dht.begin();           //initialize the Serial communication
}
/*loop*/
void loop() 
{
 
  float h = dht.readHumidity();    // reading Humidity 
  float t = dht.readTemperature(); // read Temperature as Celsius (the default)
  // check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t)) {    
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  Serial.print(t, 2);    //print the temperature
  Serial.print("\t");
  Serial.println(h, 2);  //print the humidity
  delay(2000);           //wait 2 seconds
  
  if (t > fireThreshold)
  {
    digitalWrite(ledPin, HIGH);(// turn the led on or spray foam or whatever
  }
}

Is t actually over the threshold?

You got the led the right way round?

Add a serial print there and have it say "turning on the led"

Thanks, it work when I added the serial print, it showed "turning on the led" when the temperature is over 20. But it doesn't turn on the led when the temperature is over 20. I tried to flip the led to see if it was the wrong way, but it still didn't turn on.

[:UPDATE: I started to work, I will try to make it better and work on the other sensor. I really appreciate everything, helping me with this project. I will ask if I have and difficulties and thanks again! ]

Code:

// DHT11 Temperature and Humidity Sensors Example
int ledPin = 8;
int fireThreshold = 20;
#include "DHT.h"         //include DHT library
#define DHTPIN 7      //define as DHTPIN the Pin 7 used to connect the Sensor
#define DHTTYPE DHT11    //define the sensor used(DHT11)
DHT dht(DHTPIN, DHTTYPE);//create an instance of DHT
/*setup*/
void setup() 
{
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);    //initialize the Serial communication
  delay(6000);           //wait 6 seconds
  Serial.println("Temperature and Humidity test!");//print on Serial monitor
  Serial.println("T(C) \tH(%)");                   //print on Serial monitor
  dht.begin();           //initialize the Serial communication
}
/*loop*/
void loop() 
{
 
  float h = dht.readHumidity();    // reading Humidity 
  float t = dht.readTemperature(); // read Temperature as Celsius (the default)
  // check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t)) {    
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  Serial.print(t, 2);    //print the temperature
  Serial.print("\t");
  Serial.println(h, 2);  //print the humidity
  delay(2000);           //wait 2 seconds
  
  if (t > fireThreshold)
  {
    Serial.print("turning on the led");
    digitalWrite(ledPin, HIGH);
  }
}

Maybe the led's busted. Or you have it in the wrong pin?

As a test, use the builtin led on pin 13?

Hi,
If these are your sensors.

,Temperature DHT11, IR Flame Sensor, and Smoke sensor

You need to sit down and work out you fire detection strategy.
None of these devices remotely detects fire/heat.
None of these devices has directional functionality.

All they can do is tell you when your robot is on fire, or the fire is within say 5cm, but not in what direction.

You need to get a directional IR detector and scan it around the robot.
To scan you will need the sensor mounted on a servo, or you get your robot to stop and do a turn through 180 or 360 degrees at intervals.

Tom.... :slight_smile:

Another problem I had is that the led does turn on when the temperature reaches above 30 degrees and In the serial monitor it says "turning on the led". But when it the temperature drop below 30 degrees the led stays on and the "turning on the led" stop. Is there some way I can make the led turn off when the temperature is below 30 degrees, but I added this code and it fixed it:

Code:

if (t > fireThreshold)
  {
    Serial.print("turning on the led");
    digitalWrite(ledPin, HIGH);
  }
  else
  {
    Serial.print("turning off the led");
    digitalWrite(ledPin, LOW);

As Tom George pointed out, and as I said early in the thread, the dht is by no means a fire detecting sensor.

That said, you are surely learning a lot as you go, and having that sensor turn a led on and off is conceptually similar to a real fire sensor turning the foam on and off, so it's probably be a useful exercise.

But pretty soon you will need to start using a more useful sensor.

An update for the for robot I have all the sensor up and running ,but for some reason it doesn't want to work the autonomous portion. It will say if it needs to turn or not in the serial monitor ,but it doesn't actually move and if it does move it will just go in circles. I was thinking it could be the power because before when I set everything up to be mobile, powered by the batteries it wouldn't turn on. Thank you!

Your current code?

This is for a autonomous robot and a sensor (gas/smoke sensor) for detecting fires

Code:

int smokeA0 = A5;
int sensorThres = 600;
int ledPin = 8;
#include <AFMotor.h> //import your motor shield library
#define trigPin 12 // define the pins of your sensor
#define echoPin 13 
AF_DCMotor motor1(1,MOTOR12_64KHZ); // set up motors.
AF_DCMotor motor2(2, MOTOR12_8KHZ);
 
void setup() 
{
  pinMode(ledPin, OUTPUT);
  pinMode(smokeA0, INPUT);
  Serial.begin(9600); // begin serial communitication  
  Serial.println("Motor test!");
  pinMode(trigPin, OUTPUT);// set the trig pin to output (Send sound waves)
  pinMode(echoPin, INPUT);// set the echo pin to input (recieve sound waves)
  motor1.setSpeed(105); //set the speed of the motors, between 0-255
  motor2.setSpeed (105);  
}
 
void loop() {

  long duration, distance; // start the scan
  digitalWrite(trigPin, LOW);  
  delayMicroseconds(2); // delays are required for a succesful sensor operation.
  digitalWrite(trigPin, HIGH);

  delayMicroseconds(10); //this delay is required as well!
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;// convert the distance to centimeters.
  if (distance < 25)/*if there's an obstacle 25 centimers, ahead, do the following: */ {   
   Serial.println ("Close Obstacle detected!" );
   Serial.println ("Obstacle Details:");
   Serial.print ("Distance From Robot is " );
   Serial.print ( distance);
   Serial.print ( " CM!");// print out the distance in centimeters.

  Serial.println (" The obstacle is declared a threat due to close distance. ");
  Serial.println (" Turning !");
    motor1.run(FORWARD);  // Turn as long as there's an obstacle ahead.
    motor2.run (BACKWARD);

}
  else {
   Serial.println ("No obstacle detected. going forward");
   delay (15);
   motor1.run(FORWARD); //if there's no obstacle ahead, Go Forward! 
    motor2.run(FORWARD);  
  }  

  {
    // Smoke Sensor
    int analogSensor = analogRead(smokeA0);

    Serial.print("Pin A0: ");
    Serial.println(analogSensor);
    // Checks if it has reached the threshold value
    if (analogSensor > sensorThres)
  {
      Serial.print("Led On");
      digitalWrite(ledPin, HIGH);
  }
  else
  {
    Serial.print("Led off");
    digitalWrite(ledPin, LOW);
  }
 }
}
int smokeA0 = A5;

I really need to ask what the heck that name means.

  pinMode(smokeA0, INPUT);

What do you think pinMode does? For analog pins, NOTHING.

    Serial.print("Pin A0: ");
    Serial.println(analogSensor);

That's silly output, considering that you did NOT read from analog pin 0.

Aside from these issues, and the useless curly braces around the code to read from pin A5 and print stuff, I see no issues with the code. So, you must have a hardware problem - probably power related. So, a schematic is in order.

how can i fix this power issue I have : 1 D 9V battery,and 4 AA 1.5V battery. Because it won't move at all now before it was moving did the autonomous part and now it doesn't move at all. Please Help

how can i fix this power issue I have

Use a battery charger and charge the batteries.