dfrobot flame sensor coding

in my project i m using a dfrobot flame sensor.ordered in online and got it just yesterday.i got a sample code from the website like this..

int val;
void setup()
{
Serial.begin(9600);
}
void loop()
{
val=analogRead(5);
Serial.println(val ,DEC);
delay(100);
}

i used it.connected correctly but got reading around 400, 500.. i thought there may be some problem..any help???

Is it printing 0 when there's no flame at all?

nope..i got 400-500 when there is no flame..

Have you got the sensor wired to analogue pin A5 or digital pin 5 ?

analog pin 5..

nope..i got 400-500 when there is no flame..

What do you get when there IS flame? Feel free to offer more details without prompting.

Show a picture of the device connected to the Arduino.

mechatro:
i used it.connected correctly but got reading around 400, 500.. i thought there may be some problem..any help???

I'm not even sure what the problem is, as you haven't volunteered what you expect to get, compared to what you actually get.

its dfrobot flame sensor.see here..

http://www.robotshop.com/ca/content/images/dfrobot-flame-sensor-large.jpg

if i light a candle and get that closer to the sensor, it shows upto 998, 1000..it cant differentiate between light and flame.. if i take it into a bright room, the reading shows 400, 500..if i am going to show some demo, then i have to show it only in a normal lighting room it seems..

i gave this code..

if(val>400)
{digitalWrite(13, LOW);
digitalWrite(7, HIGH);
}
if(val<100)
{digitalWrite(13,HIGH);
digitalWrite(7, LOW);
}

13 corresponds to motor wheels..7 corresponds to 12V DC Brushless fan..if it senses fire, it stops and the fan starts rotating thus extinguishing fire..

it works...but not in a brighter room/outdoors.. any help??

if i take it into a bright room, the reading shows 400, 500

if i light a candle and get that closer to the sensor, it shows upto 998, 1000.

it cant differentiate between light and flame.

These three statements are not mutually true.

i said what i got...if the room is brighter , i get 400 - 500 reading..but if i light a candle and take that upto certain level ( nearer to the sensor ) say 5cm, the reading shoots up to 900-1000...if the intensity gets lowered, the reading comes to 400-500..at this stage it cant differentiate between flame and brightness..

at this stage it cant differentiate between flame and brightness..

So, up close it can tell the difference, but far away it can't. What is the range of the sensor advertised to be?

Detection range: 20cm (4.8V) ~ 100cm (1V)

-25 degrees Celsius to 85 degrees Celsius - operating range.

Detection range: 20cm (4.8V) ~ 100cm (1V)

What voltage are you using? What range do you expect?

i am using 5v supply from arduino atmega 8. i connected it to analog pin 5 and then opened serial monitor after making vcc and gnd connections.. then i obtained the above mentioned readings..

.if it senses fire, it stops and the fan starts rotating thus extinguishing fire..

or
if it senses fire, it stops and the fan starts rotating thus fanning the fire and making it worse..

i am using 5v supply from arduino atmega 8

The spec you listed, then, shows the range to be 20 cm. Is this, or is it not, consistent with the range that the sensor is actual able to detect the flame (vs. bright ambient light)?

you noticed "fire" but forgot to notice that the fire is from a "candle".. no fire from candle can fume up if air is blown towards it..if i am in earth, this is the fact..and i am in earth infact :stuck_out_tongue:

if(val>400)

{digitalWrite(13, LOW);
      digitalWrite(7, HIGH);
      }
      if(val<100)
      {digitalWrite(13,HIGH);
      digitalWrite(7, LOW);
      }




13 corresponds to motor wheels..7 corresponds to 12V DC Brushless fan..if it senses fire, it stops and the fan starts rotating thus extinguishing fire..

Here's a tip. Use constants.

const byte MOTOR = 13;
const byte FAN = 7;
const int UPPER_THRESHOLD = 400;
const int LOWER_THRESHOLD = 100;

if (val > UPPER_THRESHOLD)
  {
  digitalWrite (MOTOR, LOW);
  digitalWrite (FAN, HIGH);
  }

if (val < LOWER_THRESHOLD)
  {
  digitalWrite (MOTOR, HIGH);
  digitalWrite (FAN, LOW);
  }

i light a candle and take that upto certain level ( nearer to the sensor ) say 5cm, the reading shoots up to 900-1000...if the intensity gets lowered, the reading comes to 400-500..at this stage it cant differentiate between flame and brightness..

How do you lower a candle's intensity? You seem to be saying that the sensor reading goes up when a flame is near it. Isn't that what is supposed to happen?

thanks...but this is what i am using now..exactly..anyway thanks for your help.

Well, when using just one sensor the ambient light will have an effect.
One way is to add another sensor which is physically offset, ie 30 degrees, so you measure the difference and act when the difference is more than x
Off course you could also do this with one sensor, read the ambient light at the start, then act when it is more than x, just not as likely to be as reliable in real lift, but cheaper :slight_smile:

K