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;
}