P-Channel MOSFET or NPN Transistor?

Hi folks,

I want to use a little buzzer in an arduino project.
I use an esp8266 which should activate the buzzer.
My sketch is working well, the buzzer beeps as I expected.
But:
Sometimes the esp8266 crashes if I switch it on. It happens very often so I have to fix that problem. It only happens, if the buzzer is directly connected to a GPIO of the esp8266. If I remove the buzzer, it never crashes at boot process.

So because I do not know how I can avoid these crashes, my idea is not connecting the buzzer directly to a gpio pin. Instead of connecting it directly, would it bepossible to put it behind a transistor like a 2N3904 or a mosfet NPD 6020P? (i am not very good in electronics so maybe i am totally wrong)
Does this make sense?

Or do anyone of you have an idea to avoid the boot crashes somehow? Or maybe you are not allowed to connect a buzzer directly to a gpio? I don't know.

Thanks a lot.
Greetings

it depends on the buzzer - so please post a link.

An electromechanical buzzer will take a lot of current and generate spikes that will upset the ESP;

A piezo sounder will be more efficient and cause fewer issues.

I do not exactly know which buzzer it is. It was inculded in a bag of multiple things I bought as set from a chinese shop :-/
but I think that's my one: HYDZ HXD Piezo Hydz Buzzer at Rs 8/piece in Mumbai | ID: 13462393333
HYDZ is graved on the top and it looks like this one.

crazysky:
Sometimes the esp8266 crashes if I switch it on. It happens very often so I have to fix that problem. It only happens, if the buzzer is directly connected to a GPIO of the esp8266. If I remove the buzzer, it never crashes at boot process.

So here's the problem.

You nave not explained what you are doing in order for us to determine the problem, :astonished:

What ESP8266?

What GPIO pin?

The “documentation” for that buzzer mentions currents of 20-30mA. That is too much for an ESP pin. Use the 2n3904 NPN transistor on the low side and with a base resistor of 1k. Add a fly back diode across the buzzer (say 1n4148)

Also see this for the best pins to use bearing in mind that some have to float high at system start: ESP8266 Pinout Reference: Which GPIO pins should you use? | Random Nerd Tutorials

Connecting a buzzer to a GPIO will act as a ground or a stiff pull up depending where the other side is connected. The ESP devices specify what GPIOs need to be in what state when booting and which ones do not. Read the documentation, add a driver for the buzzer a transistor or MOSFET will do fine.

6v6gt:
The “documentation” for that buzzer mentions currents of 20-30mA.

OK, so you found the datasheet. :grinning:

The "secret" is that if you connect something to GPIO0 or GPIO2 of the ESP2866, it must not pull either of them LOW at boot.

This means you must use a PNP transistor with emitter connected to 3.3 V, base to the output pin via a 330 Ohm resistor and the collector to the buzzer.

Technical details from the OP’s supplied link:

Under the meticulous supervision of our skilled professionals, we are providing a high quality range of Piezo Hydz Buzzer. Voltage: • (V) 1.5/3/5/9/12 • (V) 1-2/2-5/4-8/7-12/8-15 Current: • (MAX)mA 20/30/30/30/30

The voltage is not obvious since the range is quite wide but let’s guess that it is around 3v or 5v since it was supplied with an Arduino kit.

I'm not questioning you, I simply did not research the behaviour of the piezo "buzzer" sufficiently deeply. You clearly do need a transistor to drive it from an ESP8266. An Arduino output with an ATmega328 would be fine up to 30 mA.

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