Sunday, May 20, 2012

Flame Detector Sensor, Arduino Tutorial


This is a sample code to show how this cheap component from DealExtreme works with Ardunio (2.5$ with free shipping). These are very useful sensors for building [b]firefighting robots[/b]  :D  Look at the sample code for more info.
Sensor detecting match flame


purchase link:
http://www.dealextreme.com/p/arduino-flame-sensor-for-temperature-detection-blue-dc-3-3-5v-118075

OBS1: I assume this component uses Infrared and should be in direct sight to detect flame. This would work easily on big flames but for a match flame (very small), it could miss it.
OBS2: I read the values with analogRead but I guess they are readable with Digital Read as well as differences are quite high.
-------------------------
/*
  FLAME detector connected to Arduino
  http://www.dealextreme.com/p/arduino-flame-sensor-for-temperature-detection-blue-dc-3-3-5v-118075

 Developer:
 Akbar (Shahab) F. Moghaddam
 20.05.12

 Comment : I assume this component uses Infrared and should be in direct sight to detect flame. This would work easily on big flames but for a match flame (very small), it could miss it.

 */

//CONSTANTS
const int pinD0 = 0;
const int pinA0 = 1;

//VARIABLE
int A = -999;
int D = -999;
int readVal = 0;
boolean logging = false;
boolean fire = false;
boolean changed = true;


void setup() {              
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(13, OUTPUT);
  pinMode(0, INPUT);
  pinMode(1, INPUT);
  Serial.begin(19200);
}

void loop() {
  initialAll();
  readValues();
  loggingProcess();
  if (changed)
    printState();
  delay(1000);// wait for a second
}

void initialAll(){
  readVal = 0;
}

void readValues(){
  A = analogRead(pinA0);
  D = analogRead(pinD0);
  fireCheck();
  if (Serial.available()>0){
    readVal = Serial.read();
  }
}

void loggingProcess(){
  if (readVal == 'l'){
    if (logging)
      logging = false;
    else
      logging = true;
  }
 
  if (logging){
    Serial.println("------------");
    Serial.println("SYUMMARY");
    Serial.print("A0:");
    Serial.println(A);
    Serial.print("D0:");
    Serial.println(D);
    Serial.println("------------");
  }
}

void printState(){
  if (fire){
    Serial.println("------------");
    Serial.println("FLAME Detected");
    Serial.println("------------");  
  }
  else{
    Serial.println("------------");
    Serial.println("NO FLAME");
    Serial.println("------------");  
  }
  changed = !changed;
}

void fireCheck(){
  if (A < 350 && D < 350){
    fire = true;
    changed = !changed;
  }
  else{
    fire = false;
    changed = !changed;  
  }
}

3 comments:

  1. I appreciate the code - it worked on first try. I even hooked up a little LED and lit it up whenever it sees a fire, which is cool.

    There are two values in the program, A & D - what do they represent and what units do they have? Any information you might have would be greatly appreciated!

    ReplyDelete
    Replies
    1. well if you read it carefully youll see this:
      //VARIABLE
      int A = -999;
      int D = -999;
      int readVal = 0;
      boolean logging = false;
      boolean fire = false;
      boolean changed = true;
      I hope that answers you

      Delete
  2. hey shahab, I was wondering, in the code you are saying D0 = 0 and A0 = 1 ,, well A0 is not equal to 1, but its equal to A0 or 14 . am I seeing it wrong? because Im confused now. also , I would appreciate if you show the schematics of the prototypes too. Im glad I found you weblog, you have tons of cool stuff.
    Im a software engineering student and Im playing with arduino alot, your weblog gives me alot of things to play with and figure out.

    ReplyDelete