const int buzzerPin = 8; // Digital pin connected to the buzzer
int fadeAmount = 5; // Amount to increase or decrease the volume
int volume = 0; // Variable to store the current volume level
void setup() {
pinMode(buzzerPin, OUTPUT); // Set the buzzer pin as output
}
void loop() {
// Fade in
analogWrite(buzzerPin, volume);
volume = volume + fadeAmount;
if(volume <= 0 || volume >= 255){
fadeAmount = -fadeAmount;
}
delay(10);
}