const int smokeSensorPin = A0; // Analog pin for smoke sensor
const int buzzerPin = 8; // Digital pin for buzzer
const int threshold = 300; // Threshold value for smoke detection
void setup() {
pinMode(smokeSensorPin, INPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int sensorValue = analogRead(smokeSensorPin); // Read the analog value from the smoke sensor
Serial.print("Smoke Sensor Value: ");
Serial.println(sensorValue); // Print the sensor value to the Serial Monitor
if (sensorValue > threshold) {
digitalWrite(buzzerPin, HIGH); // Turn on the buzzer
} else {
digitalWrite(buzzerPin, LOW); // Turn off the buzzer
}
delay(100); // Wait for 100 milliseconds before the next loop
}
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}