Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Gas Sensor with Buzzer
- // Pin connections
- const int gasSensorPin = A0; // Analog pin for gas sensor
- const int buzzerPin = 9; // Digital pin for buzzer
- // Threshold value for gas detection
- const int gasThreshold = 500; // Adjust this value according to your sensor's sensitivity
- void setup() {
- pinMode(buzzerPin, OUTPUT);
- Serial.begin(9600);
- }
- void loop() {
- // Read the gas sensor value
- int gasValue = analogRead(gasSensorPin);
- // Print the gas value to the serial monitor
- Serial.print("Gas Value: ");
- Serial.println(gasValue);
- // If the gas value exceeds the threshold, activate the buzzer
- if (gasValue > gasThreshold) {
- digitalWrite(buzzerPin, HIGH);
- delay(1000); // Buzzer on time
- digitalWrite(buzzerPin, LOW);
- delay(1000); // Buzzer off time
- } else {
- digitalWrite(buzzerPin, LOW);
- }
- delay(500); // Delay between readings
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement