Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int buzzer = D2;
- int smokeA0 = A0;
- // Your threshold value. You might need to change it.
- int sensorThres = 600;
- void setup() {
- pinMode(buzzer, OUTPUT);
- pinMode(smokeA0, INPUT);
- Serial.begin(9600);
- }
- void loop() {
- int analogSensor = analogRead(smokeA0);
- Serial.print("Pin A0: ");
- Serial.println(analogSensor);
- // Checks if it has reached the threshold value
- if (analogSensor > sensorThres)
- {
- tone(buzzer, 1000, 200);
- }
- else
- {
- noTone(buzzer);
- }
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement