0

I'm trying to light up an LED and play a buzzer noise at the same time. Here is my code so far:

Import RPi.GPIO as GPIO
Import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(7, GPIO.OUT)

while True:
    GPIO.output(7, 1)
    time.sleep(2)
    GPIO.output(7,0)
    time.sleep(2)

GPIO.cleanup()

and here is how my RBp is connected:

https://imgur.com/a/zjusD5X

The LED lights up as expected but all I'm getting from the piezo is a very short static noise as if it's getting electricity. But no sustaining noise.

I don't think theres anything wrong with the code as I've seen multiple examples online that are basically identical and work with no issues. The buzzer I'm using is from the arduino starter kit if thats any help.

If anyone can help me figure out why it's not working that would be very appreciated!

tlfong01
  • 4,384
  • 3
  • 9
  • 23
smuvv
  • 101
  • 1
  • related if not dupe: https://raspberrypi.stackexchange.com/q/17092/19949 in short, depending on the type of the buzzer, it might be neccessary to drive it with a square wave not a static "on"-signal. – Ghanima Oct 13 '19 at 20:35
  • Try the following from the command line. `sudo pigpiod` then `pigs p 7 128` Any noise? – joan Oct 13 '19 at 20:38
  • 1
    get rid of the LED – jsotola Oct 13 '19 at 20:56
  • Have you observed the right polarity for your piezo buzzer, it has an anode & cathode just like an LED. – Dougie Oct 13 '19 at 21:25
  • spec anybody? https://imgur.com/gallery/ImHgTC4. – tlfong01 Oct 14 '19 at 03:54
  • @smuvv, If you apply a step DC voltage, your piezo will oscillate, but cannot sustain. The bad thing if that the oscillation start spike is over 30V, and might fry your Rpi. So it is important to use a Zener to protect you Rpi: https://raspberrypi.stackexchange.com/questions/103868/using-rpi-and-adc-to-read-analog-signal-of-piezo-sensor-for-acoustic-instrument – tlfong01 Oct 14 '19 at 04:47
  • @smuvv, and if you want a sustainable oscillation, then you need a "active" circuit, which roughly means your piezo is "passive", no energy/power/voltage source to sustain the oscillation. The active circuit has power source to let the oscillation not dying: Active vs Passive Buzzer: https://electronics.stackexchange.com/questions/224374/active-vs-passive-buzzer – tlfong01 Oct 14 '19 at 04:54
  • @smuvv, What confuses everybody, well, almost, is that your "buzzer" is NOT at all a buzzer. It is only a "transducer" which converts "mechanical pressure" to voltage, and vice versa. And if you attach a diaphragm on top of the piezo, and apply high/low voltage, the diaphragm will experience high/low piezo mechanical pressure/force, sort of vibrating, generating sound waves to human ears diaphragm connected to the ME to EE to NN (Neural network). So now you have an EE to ME to acoustic transducer. That is the end of my everyday use of English practice. Many thanks for listening! :) – tlfong01 Oct 14 '19 at 05:16
  • Can we have a close up of the pins at the Pi end? It is not at all clear. You could be out by one on each pin. – joan Oct 14 '19 at 09:01

1 Answers1

-1

Question

My pizeo buzzer is no working, how to fix it?

piezo connect


Answer

(1) You seem to have connected Rpi's 40 pin header's 5V power to one end of the piezo, and one GPIO pin to other end of the piezo. It is worse than connecting a resistor in a similar way. Rpi GPIO cannot stand 5V, and might fry even you connect through a current limiting protect resistor, say 4k7.

(2) If you have connected a piezo, it is even worse. Piezo might oscillate, with a starting spike, though very short, say 10uS, might be as high as 30V, and might also fry your pi.

(3) And even if your pi has not yet fried, the piezo can pass a current as high as 30mA, which is beyond GPIO limit. So it might also fry your Rpi.

So you have already done 3 things to fry your Rpi. If your Rpi is not yet fried, I would suggest a better way, that is called active piezo buzzer (Appendix C below)


References

(1) Pizo Experiment Notes - tlfong01

(2) AliExpress 5v Active Buzzer magnetic Long continuous beep alarm tone 12mm active Piezo Buzzers - US $1.2/10 pcs

(3) Active vs Passive Buzzer - EE StackExchange Forum Discussion

(4) Active Piezo Buzzer Makes Sound On Both Rpi GPIO Low and High Level Signal


Appendices

Appendix A - Piezo Buzzer Spec

piezo spec

Appendix B - Active Piezo Buzzer Circuit and Schematic 2

piezo 1

Appendix C - Active Piezo Buzzer Circuit and Schematic 2

piezo 2


End of Answer

tlfong01
  • 4,384
  • 3
  • 9
  • 23