Advertisement
safwan092

Untitled

Feb 5th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. // Gas Sensor with Buzzer
  2.  
  3. // Pin connections
  4. const int gasSensorPin = A0; // Analog pin for gas sensor
  5. const int buzzerPin = 9; // Digital pin for buzzer
  6.  
  7. // Threshold value for gas detection
  8. const int gasThreshold = 500; // Adjust this value according to your sensor's sensitivity
  9.  
  10. void setup() {
  11. pinMode(buzzerPin, OUTPUT);
  12. Serial.begin(9600);
  13. }
  14.  
  15. void loop() {
  16. // Read the gas sensor value
  17. int gasValue = analogRead(gasSensorPin);
  18.  
  19. // Print the gas value to the serial monitor
  20. Serial.print("Gas Value: ");
  21. Serial.println(gasValue);
  22.  
  23. // If the gas value exceeds the threshold, activate the buzzer
  24. if (gasValue > gasThreshold) {
  25. digitalWrite(buzzerPin, HIGH);
  26. delay(1000); // Buzzer on time
  27. digitalWrite(buzzerPin, LOW);
  28. delay(1000); // Buzzer off time
  29. } else {
  30. digitalWrite(buzzerPin, LOW);
  31. }
  32.  
  33. delay(500); // Delay between readings
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement