I am building a fire alarm system using Arduino UNO. In this project I am using a flame and smoke sensor for inputs in the pins A0 and A1 respectively. I need my arduino to start the buzzer if any one of them detects fire or smoke.
I have given the project a trial in proteus(simulation software) and everything worked well.
But when I tested it after the components arrive, I got a different output. The fire sensor is working well. but smoke sensor was not giving input. Infact the on-board light of smoke sensor was on whenever it is detecting smoke.
then I removed only the flame sensor and smoke sensor worked perfectly as programed.
In short whenever both the sensor are connected the the arduino is not getting input from smoke sensor and when only smoke sensor is attached the system is working normal as programed.
My Code -
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int flamePin = A0; // choose the input pin (for Fire sensor)
int smokePin = A1; // choose the input pin (for smoke sensor)
int buzzer = 13; // choose the pin for the Buzzer
int G_led = 8; // choose the pin for the Green LED
int R_led = 9; // choose the pin for the Red Led
int flame_value; // variable for reading the sensorpin status
int smoke_value; // variable for reading the sensorpin status
void setup() {
pinMode(flamePin, INPUT); // declare sensor as input
pinMode(smokePin, INPUT); //declare sensor as input
pinMode(buzzer, OUTPUT); // declare Buzzer as output
pinMode(R_led, OUTPUT); // declare Red LED as output
pinMode(G_led, OUTPUT); // declare Green LED as output
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" WELCOME To ");
lcd.setCursor(0, 1);
lcd.print(" Fire Detector ");
delay(2000);
lcd.clear();
}
void loop() {
flame_value = digitalRead(flamePin); // Digital input value
smoke_value = digitalRead(smokePin); //Digital input value
if (flame_value != 0 || smoke_value != 0) { // check if the Fire variable is High
lcd.setCursor(0, 0);
lcd.print(" Alert ");
lcd.setCursor(0, 1);
lcd.print(" Fire ");
digitalWrite(buzzer, HIGH); // Turn LED on.
digitalWrite(R_led, LOW); // Turn LED on.
digitalWrite(G_led, HIGH); // Turn LED off.
delay(100);
}
else { // check if the Fire variable is Low
lcd.setCursor(0, 0);
lcd.print("...CONDITIONS...");
lcd.setCursor(0, 1);
lcd.print(".....Normal.....");
digitalWrite(buzzer, LOW); // Turn LED off.
digitalWrite(R_led, HIGH); // Turn LED off.
digitalWrite(G_led, LOW); // Turn LED on.
}
delay(100);
}
Please read the post at the start of any forum , entitled "How to use this Forum".
Can I suggest you change;
flame_value = analogRead(flamePin); // Analog input value
smoke_value = analogRead(smokePin); //Analog input value
to;
flame_value = analogRead(flamePin); // Analog input value
flame_value = analogRead(flamePin); // Analog input value
smoke_value = analogRead(smokePin); //Analog input value
smoke_value = analogRead(smokePin); //Analog input value
Read each input twice, this is because there is only one ADC, and it needs time for its input capacitor to charge to the input it is switched too.
Thank you @TomGeorge for taking time to reply.
But even after this modification in code, the smoke sensor is not working even after I remove the flame sensor.
It is just the same error.
@LarryD I have potentiometers already installed on the sensors PCB. If I increase the levels, the flame sensor works but smoke sensor don't. if I remove the flame sensor and then increase the level of the potentiometer of smoke sensor, Its working wine. The problem only occurs when both of the sensor are connected, otherwise one sensor works perfectly.
HI,
Can you run this code, it is an edited version of your code that tests the analog inputs
The results are on the IDE monitor screen, set baud to 115200.
int flamePin = A0; // choose the input pin (for Fire sensor)
int smokePin = A1; // choose the input pin (for smoke sensor)
int buzzer = 13; // choose the pin for the Buzzer
int G_led = 8; // choose the pin for the Green LED
int R_led = 9; // choose the pin for the Red Led
int flame_value; // variable for reading the sensorpin status
int smoke_value; // variable for reading the sensorpin status
void setup() {
Serial.begin(115200);
Serial.println("=== analog input raw data test ===");
pinMode(flamePin, INPUT); // declare sensor as input
pinMode(smokePin, INPUT); //declare sensor as input
pinMode(buzzer, OUTPUT); // declare Buzzer as output
pinMode(R_led, OUTPUT); // declare Red LED as output
pinMode(G_led, OUTPUT); // declare Green LED as output
}
void loop() {
flame_value = digitalRead(flamePin); // Digital input value
flame_value = digitalRead(flamePin); // Digital input value
smoke_value = digitalRead(smokePin); //Digital input value
smoke_value = digitalRead(smokePin); //Digital input value
Serial.print("flame_value = ");
Serial.print(flame_value);
Serial.print("\t smoke_value = ");
Serial.println(smoke_value);
delay(250);
}
Along with @LarryD 's pots you should see independent readings.
Even with your sensors connected you should see independent readings.
@TomGeorge when I run the code I was getting input 0 on smoke sensor even after providing the butane. So I changed its input pin of smoke sensor from A1 to A3 and then the serial monitor showed 1.
So I changed the input pin in my code also, but its still the same, only one sensor working at a time .
@ I connected the flame sensor's and smoke sensor's D0 pin to Arduino pins number 10 and 11 respectively, but now both the sensors are not triggering the buzzer unless one sensor is removed from the circuit.
#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int flamePin = 10; // choose the input pin (for Fire sensor)
int smokePin = 11; // choose the input pin (for smoke sensor)
int buzzer = 13; // choose the pin for the Buzzer
int G_led = 8; // choose the pin for the Green LED
int R_led = 9; // choose the pin for the Red Led
int flame_value; // variable for reading the sensorpin status
int smoke_value; // variable for reading the sensorpin status
void setup() {
pinMode(buzzer, OUTPUT); // declare Buzzer as output
pinMode(R_led, OUTPUT); // declare Red LED as output
pinMode(G_led, OUTPUT); // declare Green LED as output
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" WELCOME To ");
lcd.setCursor(0, 1);
lcd.print(" Fire Detector ");
delay(2000);
lcd.clear();
}
void loop() {
flame_value = digitalRead(flamePin); // Digital input value
smoke_value = digitalRead(smokePin); //Digital input value
if (flame_value != 0 || smoke_value != 0) { // check if the Fire variable is High
lcd.setCursor(0, 0);
lcd.print(" alert ");
lcd.setCursor(0, 1);
lcd.print(" fire ");
digitalWrite(buzzer, HIGH); // Turn LED on.
digitalWrite(R_led, LOW); // Turn LED on.
digitalWrite(G_led, HIGH); // Turn LED off.
delay(100);
}
else { // check if the Fire variable is Low
lcd.setCursor(0, 0);
lcd.print("...CONDITIONS...");
lcd.setCursor(0, 1);
lcd.print(".....Normal.....");
digitalWrite(buzzer, LOW); // Turn LED off.
digitalWrite(R_led, HIGH); // Turn LED off.
digitalWrite(G_led, LOW); // Turn LED on.
}
delay(100);
}
Its exactly the same, I have just changed the input pins. for the sensors to digital.
@TomGeorge Actually the project is a complete mess right now. I was just checking it before installing it inside the room model. If I share the real photo no one will get it. The wires are jumbled around.
But I am sharing this circuit diagram. I have made the connections exactly the same, just changed the input pins for sensor from A0 and A1 to digital pin 10 and 11.
Since we are using digital inputs now, we need to set the pinMode to INPUT_PULLUP (since we don’t know if the sensor boards are open collector).
Put this in the setup() function.
pinMode(flamePin, INPUT_PULLUP); // declare sensor as input
pinMode(smokePin, INPUT_PULLUP); //declare sensor as input
We must determine if the alarm condition is HIGH or LOW.
Do a Serial.println(flamePin); to check wether the alarm gives a HIGH or LOW.
Do a Serial.println(smokePin); to check wether the alarm gives a HIGH or LOW.
Report back with results of the serial prints.
Edit My guess is an alarm will give a LOW on D11 and D10.
if (flame_value == LOW || smoke_value == LOW )
{
//do some crap
}