Hi
I bought a few of those piezo devices. They are the size of bus tokens with no plastic packaging. I've used piezos many times before, but not sure how to wire this one to arduino or nodemcu. Can someone give me some direction? I tried putting a 330ohm resistor in parralel and connected it to a digital pin (D7), but it doesn't work.
const int BUZZER_PIN = 7;
void setup() {
// put your setup code here, to run once:
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
beep(200);
delay(1000);
}
void beep(unsigned char delayms){
digitalWrite(BUZZER_PIN, 20); // Almost any value can be used except 0 and 255
// experiment to get the best tone
delay(delayms); // wait for a delayms ms
digitalWrite(BUZZER_PIN, 0); // 0 turns it off
delay(delayms); // wait for a delayms ms
}
digitalWrite(BUZZER_PIN, 20);
i copied it from somewhere and it seemed to work fine for other piezos. Same for the resistors. I saw one article with 1MOhm across the two wires and I saw someone put 100ohm in series. I didn't have 100ohm. So I used the next closest thing. I was just afraid to fry the nodemcu. Those piezos almost look like a piece of paper the size of a 10 cents canadian coin so it doesn't give me much confidence in it, but i am sure what makes the others bigger is the plastic packaging.
You may have confused an active buzzer vs passive one (which is what you have). An active buzzer only needs voltage to create a sound yours needs an AC signal.
Also I've seen projects where the piezo element is used as a sensor. It looks like you're confusing that as well.
so get rid of that resistor and try a tone() command.
This worked. The resistor doesn't really make any difference. The sound is barely audible. I have a use for that, but it disappointing for this project.
What would you use it for as a sensor? Just wondering
On a completely unrelated note. Is there a way where I can easily find my previous posts?
int piezoPin = 8;
void setup() {
}//close setup
void loop() {
/*Tone needs 2 arguments, but can take three
Pin#
Frequency - this is in hertz (cycles per second) which determines the pitch of the noise made
Duration - how long teh tone plays
*/
tone(piezoPin, 1500, 500);
Piezo discs are sensitive impact sensors, which a high value of burden resistor (megohms) they will generate
detectable voltages for even quite small impacts and taps.
To get a high volume of sound from a piezo disc requires an accoustically resonant housing matching the disc
and to be driven at the resonant frequency - the efficiency can be very high (compared to a standard loudspeaker
for instance).
sed003:
I saw one article with 1MOhm across the two wires and I saw someone put 100ohm in series.
A piezo device can, if impacted, generate potentially damaging high voltages (10s of volts) and is essentially an ideal current device, albeit low currents. The 1M Ohm parallel resistor is intended to give the current someplace to go that isn't through the oxide layer of your Arduino's input transistors.
Like any protection circuit you don't really need it until you do, so there's no harm in having it and it mitigates some potential for damage to the Arduino.