// Define pin connections
const int tempSensorPin = A0;
const int gasSensorPin = A1;
const int buzzerPin = 7;
const int ledPin = 13;
// Define threshold values
const int tempThreshold = 50; // Example threshold for temperature in Celsius
const int gasThreshold = 300; // Example threshold for gas sensor analog value
void setup() {
// Initialize serial communication at 9600 baud rate
Serial.begin(9600);
// Configure pins
pinMode(tempSensorPin, INPUT);
pinMode(gasSensorPin, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read sensor values
int tempValue = analogRead(tempSensorPin);
int gasValue = analogRead(gasSensorPin);
// Convert analog reading to temperature (Celsius) for demonstration purposes
float voltage = tempValue * (5.0 / 1023.0);
float temperatureC = (voltage - 0.5) * 100; // Assuming LM35 sensor
// Print sensor values for debugging
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
Serial.print("Gas Level: ");
Serial.println(gasValue);
// Check if either sensor exceeds the threshold
if (temperatureC > tempThreshold || gasValue > gasThreshold) {
// Activate buzzer and LED
digitalWrite(buzzerPin, HIGH);
digitalWrite(ledPin, HIGH);
} else {
// Deactivate buzzer and LED
digitalWrite(buzzerPin, LOW);
digitalWrite(ledPin, LOW);
}
// Wait for a short while before the next loop
delay(500);
}