Go Down

Topic: Piezo sensors 3 vs 2 pins (Read 502 times) previous topic - next topic

patrickhener

Can someone explain to me how I would wire this piezos to for example A0 of a mega NOT using the little pcb delivered with the piezo? I want to design it to a custom pcb just using the red and black wire of the piezo element. So how would I do that?

Thanks in advance,
Patrick

jremington

#1
Jun 11, 2019, 10:21 pm Last Edit: Jun 11, 2019, 10:28 pm by jremington
There is this, but why should it be powered at all? The piezo generates a voltage (tutorial) when vibrating.
Quote
Schnittstellentyp: analoger Signalausgang; Pin-Definition: S-Signalausgang, Spannungsversorgung (VCC), - Masse (GND).
I avoid products that no one has reviewed:
Quote
Schreiben Sie die erste Bewertung

Wawa

I assume you want to use it as contact microphone (wiring it to A0).
Yes, you can do that.
Just connect the red wire to A0 and the black wire to ground.
You also need a 1 Megohm resistor from A0 to ground.
Google "knock sensor" for code examples.
Leo..

patrickhener

#3
Jun 12, 2019, 07:07 am Last Edit: Jun 12, 2019, 07:08 am by patrickhener
I want to use it as a sensor to detect darts landing in the outer ring of the board. So if you do not hit any number but the piezo is triggered the dart has landed outside the board and you will loose a throw subtracted from throw count. Can someone scribble how this would look if using a pcb/prototyping board and I do not plug the resistor to the arduino directly?

jremington

#4
Jun 12, 2019, 04:53 pm Last Edit: Jun 12, 2019, 04:55 pm by jremington
What PCB/prototyping board? The one on the piezo sensor product page does nothing useful.

patrickhener

I designed one myself. So basically I want to use male headers to Plugin the piezo which I soldered female connectors to. The question is what schematic do I follow on my pcb? I understand I have to do Red piezo to A0 black piezo to ground. But how does the resistor come into play? I know how to stick it into the arduino directly, but how will this be on a pcb?

patrickhener

So just to clarify here are pictures of the pcb I designed. Will it work if I solder in a 1M resistor at the place I mistakenly labeled it to be a 5K resistor?

Pictures are here: Imgur Pictures

jremington

#7
Jun 12, 2019, 10:35 pm Last Edit: Jun 12, 2019, 10:36 pm by jremington
Quote
But how does the resistor come into play?
Most people find that using a 1Meg resistor in parallel with the piezo works well. Example

patrickhener

So I would say I designed the pcb right then. Traces are in parallel if I am not mistaken.

patrickhener

Well unfortunately it is not working as described in here. I will only get 0 as a value from the piezos. Tried a few things but it is not working at all. Disappointing if you ask me.

Wawa

#10
Jun 18, 2019, 12:09 am Last Edit: Jun 18, 2019, 02:54 am by Wawa
I will only get 0 as a value from the piezos.
That's normal when idle.
Code (which you didn't post yet) should constantly sample.
Example sketch (untested).
Leo..
Code: [Select]
const int threshold = 100; // 1 (sensitive) to 1023 (less sensitive)

void setup() {
  Serial.begin(9600);
}

void loop() {
  if (analogRead(A0) >= threshold) {
    Serial.println("Knock detected");
    delay(1000); // timeout
  }
}

patrickhener

Well thank you for the reply. I do exactly that. But it will keep beeing 0 no matter what happens. Even if I bang the dart board with my fist it will just be 0. So no chance to detect darts.

You might wanna look at my sketch but I do not think I did something wrong. I tried your example as well. Did not work either.

Sketch: https://github.com/patrickhener/dARts/blob/master/arduino/dARts.ino

Wawa

Must be something wrong with your resistor values or wiring or soldering.
Show a clear picture of the test setup.
Leo..

patrickhener

Thank you. You might see the images of the PCB in use here: Imgur Images.

Image one shows the PCB top side. At the bottom you will see 2 times 2 pins for either one piezo, leading to to red and the black cable of the piezo.

Image two shows the PCB bottom side. At the bottom you will see the traces and the 1M Ohm resistors.
The resistors are in parallel to the circuit. The red side of the piezos are leading to A0 and A1 and the black side to GND. So do the resistors, cause they are in parallel.

Image three will show the PCB in place on top of a Arduino Mega 2650 Rev3.
On the right side of the PCB you will see orange and black as well as yellow and black cable pair. Those will lead to each Piezo in use.

The USB Cable of the arduino is plugged into the Raspberry Pi in the picture which will read the serial communitcation.

The sketch I use can be found in the link I posted before. Also I took this sketch

Code: [Select]
/* Knock Sensor

 * ----------------

 *

 * Program using a Piezo element as if it was a knock sensor.

 *

 * We have to basically listen to an analog pin and detect

 * if the signal goes over a certain threshold. It writes

 * "knock" to the serial port if the Threshold is crossed,

 * and toggles the LED on pin 13.

 *

 * (cleft) 2005 D. Cuartielles for K3

 * edited by Scott Fitzgerald 14 April 2013

 */



int ledPin = 13;

int knockSensor = 0;               

byte val = 0;

int statePin = LOW;

int THRESHOLD = 100;



void setup() {

 pinMode(ledPin, OUTPUT);

 Serial.begin(9600);

}



void loop() {

  val = analogRead(knockSensor);     

  if (val >= THRESHOLD) {

    statePin = !statePin;

    digitalWrite(ledPin, statePin);

    Serial.println("Knock!");



  }

  delay(100);  // we have to make a delay to avoid overloading the serial port

}


I modified it to not trigger a LED but just println. Also I made it print out the val each cycle. The val remains 0 no matter what.

This is all detail I can give. I hope this helps.

Wawa

#14
Jun 18, 2019, 12:29 pm Last Edit: Jun 18, 2019, 12:53 pm by Wawa
Wiring seems ok.
Note that your code reads the piezo about 10x per second,
while my code reads the piezo about 10000x per second.
I will try to connect a piezo to my Mega tomorrow (almost midnight here), and try the codes.
Leo..

Go Up