Go Down

Topic: Fire Fighting Robot Project {HELP} (Read 4424 times) previous topic - next topic

Step202

Jan 15, 2017, 11:11 pm Last Edit: Jan 15, 2017, 11:20 pm by Step202
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);  
 }  
}

manor_royal

#1
Jan 16, 2017, 04:25 am Last Edit: Jan 16, 2017, 04:34 am by manor_royal
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.



If this was a Civil Engineering forum would there be posts like "I need to build a bridge. Someone send me drawings."

Step202

#2
Jan 16, 2017, 04:42 am Last Edit: Jan 16, 2017, 04:53 am by Step202
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
}

TomGeorge

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.. :)
Everything runs on smoke, let the smoke out, it stops running....

manor_royal

#4
Jan 16, 2017, 01:50 pm Last Edit: Jan 16, 2017, 01:57 pm by manor_royal
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.



If this was a Civil Engineering forum would there be posts like "I need to build a bridge. Someone send me drawings."

Step202

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:

Code: [Select]
// 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
  }
}

manor_royal

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"

If this was a Civil Engineering forum would there be posts like "I need to build a bridge. Someone send me drawings."

Step202

#7
Jan 16, 2017, 08:53 pm Last Edit: Jan 16, 2017, 09:10 pm by Step202
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! ]


https://gyazo.com/92d8a4c3cf591cf7e2ae79e9a7173d95

Code:

Code: [Select]
// 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);
  }
}

manor_royal

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

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

If this was a Civil Engineering forum would there be posts like "I need to build a bridge. Someone send me drawings."

TomGeorge

Hi,
If these are your sensors.
Quote
,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.... :)
Everything runs on smoke, let the smoke out, it stops running....

Step202

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:

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

manor_royal

#11
Jan 17, 2017, 05:11 am Last Edit: Jan 17, 2017, 05:12 am by manor_royal
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.



If this was a Civil Engineering forum would there be posts like "I need to build a bridge. Someone send me drawings."

Step202

#12
Jan 25, 2017, 05:37 pm Last Edit: Jan 25, 2017, 05:49 pm by Step202
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!

PaulS

The art of getting good answers lies in asking good questions.

Step202

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



Code:

Code: [Select]

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);
  }
 }
}



 

 

Go Up