Hello guys! I have several working scetches which i want to merge into one. The first one turns on LED when sound is detected, second one turns on LED when light is detected and the third one turns on LED when gas is detected. Can anyone help me how to merge them?
// set pin numbers:
const int soundPin = 2; // the number of the Sound sensor pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int soundState = 0; // variable for reading the sound sensor status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the sound sensor pin as an input:
pinMode(soundPin, INPUT);
}
void loop(){
// read the state of the sound sensor value:
soundState = digitalRead(soundPin);
// check if any sound is detected.
// if it is, the sound sensor is :PW:
if (soundState == LOW) {
// turn LED on:
digitalWrite(ledPin, HIGH);
delay(60000);
//wait 60 seconds and turn it off
digitalWrite(ledPin, LOW);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
const int lightPin = 2;
const int ledPin = 13;
int value = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(lightPin, INPUT);
Serial.begin(9600);
}
void loop() {
value = digitalRead(lightPin);
if (value == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
delay(60000);
//wait 60 seconds and turn it off
digitalWrite(ledPin, LOW);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int ledPin = 13; // LED connected to digital pin 13
int sensorValue = 0; // value read from the sensor
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// determine alarm status
if (sensorValue >= 200)
{
digitalWrite(ledPin, HIGH); // sets the LED on
}
else
{
digitalWrite(ledPin, LOW); // sets the LED off
}
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.println(sensorValue);
// wait 100 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(100);
}