1

How I can use multi smoke sensor in one code? I mean how can I use more than one sensor, where both sensors has the same purpose, like use smoke sensor in multi room. Similar to this code where one is used only. How I can more than one, in Arduino Uno R3,,

<per>
 int redLed = 12;
int greenLed = 11;
int buzzer = 10;
int smokeA0 = A5;
// Your threshold value
int sensorThres = 400;
void setup() {
 pinMode(redLed, OUTPUT);
 pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
void loop() {
 int analogSensor = analogRead(smokeA0);
 Serial.print("Pin A0: ");
 Serial.println(analogSensor);
 // Checks if it has reached the threshold value
 if (analogSensor > sensorThres)
 {
 digitalWrite(redLed, HIGH);
 digitalWrite(greenLed, LOW);
 tone(buzzer, 1000, 200);
 }
 else
 {
 digitalWrite(redLed, LOW);
 digitalWrite(greenLed, HIGH);
 noTone(buzzer);
 }
 delay(100);
}

How I can add more than one sensor to get same purpose. check detect 1 and detect2 and detect 3 if one of this detection LED Red ON, Thanks`

asked Sep 10, 2016 at 14:14

2 Answers 2

1

just duplicate the parts of the code that handle the sensor.

int redLed = 12;
int greenLed = 11;
int buzzer = 10;
int smokeSensor1 = A5;
int smokeSensor2 = A4;
int smokeSensor3 = A3;
// Your threshold value
int sensorThres = 400;
void setup() {
 pinMode(redLed, OUTPUT);
 pinMode(greenLed, OUTPUT);
 pinMode(buzzer, OUTPUT);
 pinMode(smokeSensor1, INPUT);
 pinMode(smokeSensor2, INPUT);
 pinMode(smokeSensor3, INPUT);
 Serial.begin(9600);
}
void loop() {
 int analogSensor1 = analogRead(smokeSensor1);
 int analogSensor2 = analogRead(smokeSensor2);
 int analogSensor3 = analogRead(smokeSensor3);
 Serial.print("Pin A0: ");
 Serial.println(analogSensor1);
 // Checks if it has reached the threshold value
 if( (analogSensor1 > sensorThres) || (analogSensor2 > sensorThres) || (analogSensor3 > sensorThres) )
 {
 digitalWrite(redLed, HIGH);
 digitalWrite(greenLed, LOW);
 tone(buzzer, 1000, 200);
 }
 else
 {
 digitalWrite(redLed, LOW);
 digitalWrite(greenLed, HIGH);
 noTone(buzzer);
 }
 delay(100);
}
answered Sep 10, 2016 at 18:07
0

You haven't mentioned what sensor you are using, so I can't offer any help on how to interface with it. Though you can add 'multi-sensor code' by adding code that will get the state of the sensor at times when you can afford to wait a few ms before checking the state of the other sensors. With the code you provided, you could after the if/else block but before the delay.

Also, it is typically not a good idea to put sensors far away from each other but still connect them to the same controller. You should give each room its own Arduino.

answered Sep 10, 2016 at 16:39
1
  • I use Mq2 smoke sensor. I mean use mq2 sensor in many room at least 3 sensor in one Arduino uno. Commented Sep 10, 2016 at 16:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.