Add a buzzer - I got Arduino today for my birthday

Hello guys,
I got Arduino today as a gift and I’m very happy.

I made a simple project with a LED toggle on when I press a button.

But I would like to also attach a buzzer to make short a beep sound whenever I press the button to turn on the light. The LED is in the other room and notify my girl that I woke up (she wakes up early) but a sound is also needed since the sun may be very bright and you cannot see the LED.

I don’t know where to connect the buzzer and how to set it up so I would be very happy if you could help me. I got Elegoo complete kit so I think I have everything I need in there.

This is the code I did for the moment:

int led = 13;
int button = 12;

int ledState = HIGH;
int buttonCurrent;
int buttonPrevious = LOW;

void setup() {
pinMode(button, INPUT);
pinMode(led, OUTPUT);

}

void loop()
{
buttonCurrent = digitalRead(button);

if (buttonCurrent == HIGH && buttonPrevious == LOW)
{
if (ledState == HIGH)
{
ledState = LOW;
}
else
{
ledState = HIGH;
}
}

digitalWrite(led, ledState);

buttonPrevious = buttonCurrent;
}

In your complete kit is there a buzzer example project? That would be a good place to start.

2 types of buzzers ‘active’ and ‘passive’. You can look them up, research is good for you. Also, in the complete kit, there is an active and a passive buzzer.

You’re on the right track…
Since you want the buzzer to sound in sync with the LED, obviously the buzzer state should be set/reset at the same point in your code.

The thing you need to be careful of now - is there are many types of buzzer, and only a few (the weaker ones) could be driven directly from an output pin.

To get the general idea, look into how you’d drive a relay with a transistor or FET. The method will be exactly the same, and will open you up to a lot of future possibilities !

Enjoy.

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