Problem in running two sensor in arduino

Hello,

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);
}


The wiring are exactly connected the same. i have cross checked many times.

Flame sensor:
https://www.amazon.in/COMPOINDIA-PD018-Flame-sensor-module/dp/B092SMTDYG/ref=sr_1_4?dchild=1&keywords=flame+sensor&qid=1621138547&sr=8-4

Smoke(gas)sensor:
https://www.amazon.in/Robocraze-Methane-Sensor-Arduino-731/dp/B079Z43PRM/ref=sr_1_2?dchild=1&keywords=mq4+sensor&qid=1621141098&sr=8-2

Please help me with this problem.

Show us a good schematic of your circuit.

Show us a good image of your ‘actual’ wiring.

Give links to components.


In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the </> icon from the ‘reply menu’ to attach the copied sketch.

1 Like

Hi, @saksham_12
Welcome to the forum.

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.

Tom.... :grinning: :+1: :coffee: :australia:

1 Like

Thank you @LarryD
I have done those changes to my topic.
Added the circuit diagram also.

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.

Replace the two sensors with two potentiometers.

Use these potentiometers to set the levels to prove your code.


BTW

  pinMode(flamePin, INPUT); // declare sensor as input
  pinMode(smokePin, INPUT); //declare sensor as input

The above two lines are not needed.


Do you have links to the two sensors ?

1 Like

@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.

Tom.. :grinning: :+1: :coffee: :australia:

2 Likes

Is there an A0 and D0 pin on your flame sensor ?

Is there an A0 and D0 pin on the smoke sensor ?


It’s best to show us links to the sensors so we can give informed help.

1 Like

If there are DO pins on the sensor PCBs.

Use the D0 pins on the sensor boards.

Connect these to digital inputs on the Arduino.

The potentiometers on the sensor boards are for DO trigger operation.

1 Like

@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 .:disappointed_relieved:

See post 9 and 10.

@ 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.

Show us your new sketch.

And you will need to adjust the trigger point potentiometers on the sensor boards for the level you want.

Note when the sensor boards LEDs come on the voltage on the digital input pin should be HIGH, 5v.

Hi,
Can you post a picture of your project please so we can see your component layout?

How are you powering your project?

Tom... :grinning: :+1: :coffee: :australia:

#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.

Also I am right now using laptop USB to power the Arduino.

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
}

1 Like

Hi,
Have you got a DMM?

Tom... :grinning: :+1: :coffee: :australia:

1 Like

@TomGeorge Actually its strict lockdown here. All these important components like DMM and soldering iron are in college lab.