Hi everyone, I am coding to read from flame sensor and temperature sensor attached to analog input Arduino, but the result from temperature sensor was incorrect and unstable (sometimes 29 celcius, sometimes 40 celcius), while flamse sensor voltage result no problem. Can anyone help me to identify which part of coding doing wrong? Will be very much appreciated!! Thank you!
p/s attached picture below shows the temperature was inconstant..
//declare variables
int buzzer = 8;
int led = 7;
float tempC;
float voltage;
int tempPin = A0; // Temp sensor plugged analog pin 0
int flamePin = A2; //flame sensor plugged analog pin 2
// write setup function
void setup ()
{
Serial.begin(9600);
pinMode(flamePin, INPUT); //analog flame sensor
pinMode (led, OUTPUT); //led pin
pinMode(buzzer, OUTPUT); //buzzer pin
pinMode(tempPin, INPUT); //analog temperature sensor
}
void loop ()
{
//print temperature reading
tempC = analogRead(tempPin); // taking the temp pin reading and setting it equal to tempC variable
tempC = (5.0*tempC*100.0)/1024.0; // will convert the analog input to a temperature in celcius
Serial.print((byte)tempC); //will output the converted temperature to pc
//print flame voltage reading
voltage = analogRead (flamePin);
voltage = (5.0*voltage)/1024.0;
Serial.println ((byte)voltage);
//if temperature exceed, if flame exist, there is fire
if (tempC>35[img]http://[img][img][/img][/img][/img])
{
if (voltage <= 3) //there is flame
{
digitalWrite (led, HIGH);
digitalWrite (buzzer, HIGH);
}
else //No flame detected
{
digitalWrite (led, LOW);
digitalWrite (buzzer, LOW);
}
}
else //No flame detected
{
digitalWrite (led, LOW);
digitalWrite (buzzer, LOW);
}
delay (3000);
}
Hi thanks for your reply, i have added the code tag. I apologized I don't have the circuit diagram right now. Basically, I'm using buzzer, led as analog ouput, LM35 (temperature sensor) and flamse sensor as analog input. I want to switch on led and buzzer if temperature exceed value I set and there is flame detected.
and temperature sensor LM35. The problem is not fix yet. The temperature result was inaccurate when adding flame sensor together. Please someone help me.
Hi thanks for looking this. My circuit diagram as attached. Sorry for the ugly drawing. Thanks!
Second attachment is the Flame Sensor Module Getting Started Guide. The temperature value seems crash with the flame sensor value, and I not sure why! sigh,
Hi thanks for the reply, 01 indicate my xbee 1. I deleted the coding but forgot to change the picture. But it doesn't influence the result. Well, I am trying the most basic coding, and yet the result of temperature also not correct.
// write setup function
void setup ()
{
Serial.begin(9600);
}
void loop ()
{
int b= analogRead(A1); //LM35 sensor
Serial.println(b);
delay (3000);
int a=analogRead(A0); //flame sensor
Serial.println(a);
delay(3000);
}
1019... is flame analog value; 61... is temperature analog value
The value obtained is not constant.
i had the same problem some time ago, i could fix it using this code
nt safeAnalogRead(int pin)
{
int x = analogRead(pin); // make an initial reading to set up the ADC
delay(10); // let the ADC stabilize
x = analogRead(pin); // toss the first reading and take one we will keep
delay(10); // delay again to be friendly to future readings
return x;
}