How to run BUZZER and LED simultaneously

Hello dear geeks, I'm stuck and need your help!

How can I run LED and Buzzer simultaneously, my current code will run either the LED or the BUZZER FIRST then will carry on with the following line of code

My goal is: Press the button to stop the loop and simultaneously make noise and flash the RED LED

void modeOff() {
  digitalWrite(GREEN_LED, LOW); // Switch OFF  GREEN LED 
  digitalWrite(RED_LED, HIGH); // Switch ON RED LED
  delay(1000); // Delay for 1 second
  digitalWrite(RED_LED, LOW); // Switch OFF RED LED
  digitalWrite(GREEN_LED, HIGH); Switch ON GREEN LED
  
    tone(BUZZER, 1350); // Make sound
    delay(150);
    tone(BUZZER, 950); 
    delay(150);
    tone(BUZZER, 450); 
    delay(200);
    noTone(BUZZER); 
}

So far: If the button is pressed loop is stopped, RED LED FLASH and then BUZZ.

How do we run the LED and the BUZZ at the same time?

You take a look at the blink without delay example code in the IDE, and get rid of the delays.

1 Like

This shows you what’s basically needed.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.