How i can combine code for 3 same smoke sensor

plz guide me how i can combine code for mq2 smoke sensor. i am using three mq2 smoke sensor in my project . plz help me how i can combine this single code for 2 more smoke sensors. thanks :slight_smile: :slight_smile: . your reply highly appreciated :slight_smile:

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

void loop() {
int analogSensor = analogRead(smokeA0);

Serial.print("Pin A0: ");
// Checks if it has reached the threshold value
if (analogSensor > sensorThres)
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
tone(buzzer, 1000, 200);
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);

Just read the value from two other analog input pins. What’s the expected output? Do you have an array of green and red LEDs?

BTW, did you read the sticky post at the top of the forum? Learn to use code tags (that’s the β€œ</>” button in the editor) and post a diagram of your wiring. I would recommend you to read about arrays in C/C++, they will come in handy in that job.