hii, i am working on a circuit with arduino nano and a buzzer. but im confused about something so in my circuit i connected the negative side of the buzzer to digital pin 2 and the positive side of the buzzer do i connect it to GND or VCC?
What buzzer ?
If your buzzer has a positive and a negative, you have two options
- negative to pin and positive to Vcc
- positive to pin and negative to GND
(1) sounds like what you asked for.
never used a buzzer, just make sure that you don’t overload the pin of you arduino.
ahha okay, so far im connecting as this : negative to pin and positive to 3.3 Vcc
What buzzer are you using, give us a link ?
im using this kind of buzzer :
Many of these buzzers use less than 20mA. The Nano should drive 40mA so you ought to be OK with a direct connection. Personally, it makes more sense to connect buzzer -ve to GND and buzzer +ve to the Nano pin. It makes more sense because digitalWrite(buzzerpin,HIGH); is a more logical way for a new programmer to think of when making the buzzer buzz.
I have 2 small points to make:-
Some of the buzzers advertised are not actually "buzzers". They are small (piezo) speakers. So simply powering them will not make a noise - they need PWM.
The way to test this is to connect the buzzer directly to a 3.3v or 5v supply. If it buzzes then great. Otherwise it may be a "speaker", so use PWM.
I have personally fallen into this rather simple trap before where a sellers listing said buzzer.
Some of the buzzers (and speakers) listed are mechanical buzzers, so have a (relatively large) coil inside. Although you should be OK connecting as I mention above, it is worth adding a diode in reverse across the buzzer/speaker (connect diode anode to GND and diode cathode - which has the line around the diode body - to the buzzer and Nano pin.
This will prevent any flyback noise and/or voltage spikes.
I just know someone is going to say that is not needed. And I agree in principle. But for the sake of a cheap diode (use a IN4001 or similar) it would not do any harm.
Finally, note that not all of the Nano digital pins offer PWM. Check the specs before deciding on what pin to connect (if it is a speaker).