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!

  • related if not dupe: 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? imgur.com/gallery/ImHgTC4. – tlfong01 Oct 14 '19 at 3:54
-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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.