Connecting Piezo buzzer

Hello Arduino community,

I'm new here, and I'm more or less new to electronics and to Arduino specifically. I'm mostly playing around with connecting different components and trying to get stuff working.

I am working on a Piezo Buzzer which must sound on command from a java program with a specific pin on a raspberry pi.
The problematic is the same that if it was an arduino(I suppose.).

Here the specifications of the equipment:
Piezo Buzzer: Piezo Transducer - 15V Buzzer (2800Hz) | The Pi Hut
Transistor: 2N2222
Raspberry: Pi 3 Model B+ (a pin like the GPIO 2, when set to HIGH deliver 3.3V, as Arduino)

I have questions on my circuits, because whatever I am trying, impossible to make working my buzzer.

My first try was like the following schematic:

Unfortunately, the buzzer was noising randomly. Sometime it was buzzing (1/10), sometime it was not(9/10).
I though it was coming from a component which was defective. I replaced everything and I had the same result.
Then I though it was from my buzzer which wasn't working well with only 5V but it is when the piezo is connected directly to the 5V pin.
Then I though it was with my schematic which was wrong.

I searched on this forum and saw previous post about "how to connect a piezo buzzer":
https://forum.arduino.cc/index.php?topic=380219.0
https://forum.arduino.cc/index.php?topic=526417.0

Some answers tell us to:

TonyWilk:
[...] add a 100ohm resistor across the piezo.[...]

lawrence_jeff:
[...]the answer is in fact that the piezo needs a resistor in parallel when used with this circuit

It doesn't when directly connected to the arduino pin so it must sink current when the tone low function goes low... when you add a transistor the negative pin of the piezo (in this diagram) stays high due to the capacitance[...]

I tried like the following schematics with 1K ohms to 220 ohms for the resistance in parrallel:

Unfortunately, No sound. I just hear a little pulse but no real noise.

Then I though it was about oscillation or it requires an AC drive.

MarkT:
Yes nothing happens because a piezo element is a capacitor(*), so DC drive is not possible, you must use
AC drive, aka push-pull, and expect no net DC current to flow.

(*) all large-value ceramic capacitors are made out of the same basic material type as piezo transducers

But in the specifications of the buzzer it is describing that:

This buzzer requires no external oscillation, simply place a DC voltage across the terminals and it will make noise!

I am totally blocked, I don't know what to do.
I know that it requires a voltage between 9V and 15V but it noises when I set directly to the 5V pin.

Why it isn't when I set a simple transistor. I don't get it if you can help me.

I highly doubt that the buzzer in the link is a piezo buzzer.
The 15volt/40mA specs point to a mechanical buzzer (claxon).
Sales dudes get things wrong all the time.

No resistor across the buzzer needed, and 4mA base current (1k base resistor) for the 2N2222 is enough.
Use any external voltage between 5 and 15volt to power the buzzer (higher voltage = louder).
A (1N4148) back-EMF protection diode across the buzzer might be wise, to protect the transistor. Just in case.
Leo..

Operating Voltage 9V - 15V DC

So why would you expect it to work off 5V ?

Did you not read the datasheet you linked ?

Wawa:
I highly doubt that the buzzer in the link is a piezo buzzer.
The 15volt/40mA specs point to a mechanical buzzer (claxon).
Sales dudes get things wrong all the time.

No resistor across the buzzer needed, and 4mA base current (1k base resistor) for the 2N2222 is enough.
Use any external voltage between 5 and 15volt to power the buzzer (higher voltage = louder).
A (1N4148) back-EMF protection diode across the buzzer might be wise, to protect the transistor. Just in case.
Leo..

Oh ok :o , thanks for the information

raschemmel:
So why would you expect it to work off 5V ?

Did you not read the datasheet you linked ?

I did but like I said it is working perfectly on 5V pin, and it is working randomly with the transistor.

borsing:
[..]
Then I though it was from my buzzer which wasn't working well with only 5V but it is when the piezo is connected directly to the 5V pin.
[...]
I know that it requires a voltage between 9V and 15V but it noises when I set directly to the 5V pin. [...]

Until you are ready to do things properly , there's no point in continuing this discussion.

Test the buzzer with a 12V supply, switched with the transistor, and if that doesn't work, then we'll talk.

Unfortunately, the buzzer was noising randomly. Sometime it was buzzing (1/10), sometime it was not(9/10).
I though it was coming from a component which was defective. I replaced everything and I had the same result.
Then I though it was from my buzzer which wasn't working well with only 5V but it is when the piezo is connected directly to the 5V pin.

Does the word "marginal" mean anything to you ?

Didn't see any 'real' pictures of your setup.
There are different pinouts for '2222' transistors. Maybe you connected it wrong.
A transistor as switch 'looses' a bit, but it shouldn't be more than 0.2-0.4volt with >= 5% base drive.
Leo..

Wawa:
Didn't see any 'real' pictures of your setup.
There are different pinouts for '2222' transistors. Maybe you connected it wrong.

The transistor is precisely the 2N2222A. I followed this image for the branching.

I tried with a Led replacing the buzzer and it was working well.

Wawa:
A transistor as switch 'looses' a bit, but it shouldn't be more than 0.2-0.4volt with >= 5% base drive.
Leo..

Oh I didn't know that, maybe it is the reason why the buzzer seems to work randomly with a transistor.
There is maybe a threshold below 5V where the buzzer stop working.

raschemmel:
Until you are ready to do things properly , there's no point in continuing this discussion.

Test the buzzer with a 12V supply, switched with the transistor, and if that doesn't work, then we'll talk.
Does the word "marginal" mean anything to you ?

Ok I get your point, you are right. I will get a new buzzer which can work with 5V DC to avoid adding another supply.
If you have any recommendation about it, I am interested.

A P2N2222A has the pinout reversed (1,2,3 = C, B, E).
Leo..

Wawa:
A P2N2222A has the pinout reversed (1,2,3 = C, B, E).
Leo..

Just tried to reverse the transistor in case, nothing.
I am pretty sure it was correct at the beginning.
Thanks for the clue ^^
.

Since running this buzzer at 5V, is way outside the specified supply voltage range, I suggest it might be that the Emitter-Collector voltage drop [typically around 100mV to 300mV, or more], is reducing the supply voltage, to the buzzer, even more [to more like 4.9 to 4.7V], which is just enough of a reduction in voltage for the buzzer to not function.

Try disconnecting the end of the buzzer, that is currently connected to 5V, and instead, connect it to a voltage in the range 9-15V. And, of course, connect the negative side of that voltage source, to the Emitter, on the transistor. Also, make sure it's a voltage source that can deliver the required buzzer current.

And, another thought. Have you checked to see if that GPIO is actually going HIGH?