0% found this document useful (0 votes)
2 views

Code for Flame Sensor

The document contains an Arduino code that reads sensor data from analog pin A0 to detect fire proximity. It maps the sensor readings to four ranges, providing output for close fire, distant fire, or no fire detected. The code initializes serial communication and includes a delay between sensor readings.

Uploaded by

p.garje297
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Code for Flame Sensor

The document contains an Arduino code that reads sensor data from analog pin A0 to detect fire proximity. It maps the sensor readings to four ranges, providing output for close fire, distant fire, or no fire detected. The code initializes serial communication and includes a delay between sensor readings.

Uploaded by

p.garje297
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// lowest and highest sensor readings:

const int sensorMin = 0; // sensor minimum


const int sensorMax = 1024; // sensor maximum

void setup() {
// initialize serial communication @ 9600 baud:
Serial.begin(9600);
}
void loop() {
// read the sensor on analog A0:
int sensorReading = analogRead(A0);
// map the sensor range (four options):
// ex: 'long int map(long int, long int, long int, long int, long int)'
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);

// range value:
switch (range) {
case 0: // A fire closer than 1.5 feet away.
Serial.println("** Close Fire **");
break;
case 1: // A fire between 1-3 feet away.
Serial.println("** Distant Fire **");
break;
case 2: // No fire detected.
Serial.println("No Fire");
break;
}
delay(1); // delay between reads
}

You might also like