Skip to main content
added 50 characters in body
Source Link
Vasil Kalchev
  • 293
  • 1
  • 2
  • 12

You just need to assign the sensors different pins.

/* GAS Sensor MQ-2
This sensor detects flammable gasses
the board has four pins
connect AO to Arduino pin A0
connect DO to Arduino pin 2
connect Gnd to Arduino Gnd
connect Vcc to Arduino 5 volts
*/

int sensorPin =gasSensorPin= A0; // select theGAS inputsensor pin for the potentiometer
int DOPin =DOpin= 2; // select the pin for the LED
int sensorValue =gasSensorValue= 0; // variable to store the value coming from the sensor
int ledPin =13;= 13;

int tempSensorPin = A1;  //Temperature sensor pin
int tempSensorValue;

void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(DOPin, INPUT);
 pinMode(ledPin, OUTPUT);
 Serial.begin(9600);
 }


void loop() {
 // read the value from the sensor:
 sensorValue =gasSensorValue= analogRead(sensorPingasSensorPin);
 Serial.print("Analog Output = ");
 Serial.println(sensorValuegasSensorValue);
 // turn the ledPin on if triggered
 //
 if (digitalRead(DOPinDOpin) ==HIGH== HIGH){
 digitalWrite(ledPin, LOW);
 Serial.println("Digital Output = OFF");
 }
   else {
     digitalWrite(ledPin, HIGH);
     Serial.println("Digital Output = ON");
  }

Serial.print("Temperture: ");
tempSensorValue = analogRead(tempSensorPin));
Serial.println(analogRead(tempSensorPin));  //Print the value of pin A4

delay(1000);
}

This is your combined sketch.

You just need to assign the sensors different pins.

/* GAS Sensor MQ-2
This sensor detects flammable gasses
the board has four pins
connect AO to Arduino pin A0
connect DO to Arduino pin 2
connect Gnd to Arduino Gnd
connect Vcc to Arduino 5 volts
*/

int sensorPin = A0; // select the input pin for the potentiometer
int DOPin = 2; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
int ledPin =13;

int tempSensorPin = A1;  //Temperature sensor pin

void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(DOPin, INPUT);
 pinMode(ledPin, OUTPUT);
 Serial.begin(9600);
 }


void loop() {
 // read the value from the sensor:
 sensorValue = analogRead(sensorPin);
 Serial.print("Analog Output = ");
 Serial.println(sensorValue);
 // turn the ledPin on if triggered
 //
 if (digitalRead(DOPin) ==HIGH){
 digitalWrite(ledPin, LOW);
 Serial.println("Digital Output = OFF");
 }
   else {
     digitalWrite(ledPin, HIGH);
     Serial.println("Digital Output = ON");
  }

Serial.print("Temperture: ");
Serial.println(analogRead(tempSensorPin));  //Print the value of pin A4

delay(1000);
}

This is your combined sketch.

You just need to assign the sensors different pins.

/* GAS Sensor MQ-2
This sensor detects flammable gasses
the board has four pins
connect AO to Arduino pin A0
connect DO to Arduino pin 2
connect Gnd to Arduino Gnd
connect Vcc to Arduino 5 volts
*/

int gasSensorPin= A0; // GAS sensor pin
int DOpin= 2; // select the pin for the LED
int gasSensorValue= 0; // variable to store the value coming from the sensor
int ledPin = 13;

int tempSensorPin = A1;  //Temperature sensor pin
int tempSensorValue;

void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(DOPin, INPUT);
 pinMode(ledPin, OUTPUT);
 Serial.begin(9600);
 }


void loop() {
 // read the value from the sensor:
 gasSensorValue= analogRead(gasSensorPin);
 Serial.print("Analog Output = ");
 Serial.println(gasSensorValue);
 // turn the ledPin on if triggered
 //
 if (digitalRead(DOpin) == HIGH){
 digitalWrite(ledPin, LOW);
 Serial.println("Digital Output = OFF");
 }
   else {
     digitalWrite(ledPin, HIGH);
     Serial.println("Digital Output = ON");
  }

Serial.print("Temperture: ");
tempSensorValue = analogRead(tempSensorPin));
Serial.println(tempSensorPin);  //Print the value of pin A4

delay(1000);
}

This is your combined sketch.

Source Link
Vasil Kalchev
  • 293
  • 1
  • 2
  • 12

You just need to assign the sensors different pins.

/* GAS Sensor MQ-2
This sensor detects flammable gasses
the board has four pins
connect AO to Arduino pin A0
connect DO to Arduino pin 2
connect Gnd to Arduino Gnd
connect Vcc to Arduino 5 volts
*/

int sensorPin = A0; // select the input pin for the potentiometer
int DOPin = 2; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
int ledPin =13;

int tempSensorPin = A1;  //Temperature sensor pin

void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(DOPin, INPUT);
 pinMode(ledPin, OUTPUT);
 Serial.begin(9600);
 }


void loop() {
 // read the value from the sensor:
 sensorValue = analogRead(sensorPin);
 Serial.print("Analog Output = ");
 Serial.println(sensorValue);
 // turn the ledPin on if triggered
 //
 if (digitalRead(DOPin) ==HIGH){
 digitalWrite(ledPin, LOW);
 Serial.println("Digital Output = OFF");
 }
   else {
     digitalWrite(ledPin, HIGH);
     Serial.println("Digital Output = ON");
  }

Serial.print("Temperture: ");
Serial.println(analogRead(tempSensorPin));  //Print the value of pin A4

delay(1000);
}

This is your combined sketch.