Loading
Loading
IoT Lab content is currently available in Arabic only. We're working on an English version.
عرض بالعربية →Generating warning tones with the tone() function.
Connect the positive leg to a PWM-capable pin (like pin 9) through a small resistor to protect the pin, and the negative leg to GND.
const int buzzerPin = 9;
void setup() {
pinMode(buzzerPin, OUTPUT);
}
void loop() {
tone(buzzerPin, 1000); // 1000 Hz
delay(500);
tone(buzzerPin, 2000); // 2000 Hz
delay(500);
noTone(buzzerPin);
delay(1000);
}Using an Active Buzzer with the tone() function — the sound will be very distorted because an Active Buzzer has its own internal oscillator.