Argh Knock Sensor PCBs Inconsistent!

Hello everyone -

I've been getting advice for years on this forum for how to put together a pretty simple project. But, I've also been frustrated by expensive failure for years as well. I was hoping for a Christmas miracle tonight but, once again, my PCBs do not work.

I built my project via Arduino and breadboard a long time ago, converted them to Eagle and ordered turnkey PCBs from PCBWay.com (in China). They do sourcing, PCB manufacturing, and assembly for me. I got a box of 10 PCBs in yesterday and uploaded my code - 5 worked, 5 did not. This video is an example of what I'm seeing:

In the video, you can see the first PCB working as expected - on the board, there is a piezo element that is supposed to work like a knock sensor. It's soldered flat to the board and connected to A1 on the ATMega328. When you tap the knock sensor, the LEDs light up to indicate how hard you tapped. 4 LEDs means >100 on A1.

The second PCB does not work, giving basically no reading when you tap. FWIW, if I tap it long enough I will eventually get an LED or two. But it's very inconsistent.

The third PCB also does not work, maxing out at >100 the entire time, even when I'm not touching the sensor.

These are three identical PCBs from the same order with identical code :frowning: I do not see any imperfections on the board that I can spot with my own eyes (missing resistors, etc.)

I had a professional EE help me with the schematic. It is attached below for your viewing pleasure. Obviously there's a little more going on here than just the piezo and the controller but the rest is pretty self explanatory and serves a purpose (buzzer, on/off switch, etc.)

This is the code I've got flashed to the board. Obviously it's not my final code, but it's the code in use in the video, which I use for sensor diagnostic purposes:

int sensorPin = A1;
int ledOnePin = 3;
int ledTwoPin = 4;
int ledThreePin = 7;
int ledFourPin = 9;

void setup() {
  pinMode(sensorPin, INPUT);
  pinMode(ledOnePin, OUTPUT);
  pinMode(ledTwoPin, OUTPUT);
  pinMode(ledThreePin, OUTPUT);
  pinMode(ledFourPin, OUTPUT);
}

void loop() {
  int hitVal = 0;
  hitVal = analogRead(sensorPin);
  if (hitVal > 25) {digitalWrite(ledOnePin, HIGH);delay(50);}
  else {digitalWrite(ledOnePin, LOW);}
  if (hitVal > 50) {digitalWrite(ledTwoPin, HIGH);delay(50);}
  else {digitalWrite(ledTwoPin, LOW);}
  if (hitVal > 75) {digitalWrite(ledThreePin, HIGH);delay(50);}
  else {digitalWrite(ledThreePin, LOW);}
  if (hitVal > 100) {digitalWrite(ledFourPin, HIGH);delay(50);}
  else {digitalWrite(ledFourPin, LOW);}
  delay(10);
}

I would love anyone's experienced opinion on what on earth is going on here. Why would I get such inconsistent results? Is there something I need to improve in my design, or is shoddy manufacturing to blame? What do you guys think? Every run of 10 of these PCBs costs me $200 so I'm getting pretty sick of ordering boxes of 10 that I have to almost immediately pitch and start over with.

Thanks!
Matt

How is the piezo soldered to the board? The diaphragm is very heat sensitive, it shrivels on contact with a soldering iron, putting leads on them is a fine art.

Need some close up images of that.

Can you program an LED-blinky program to ensure the microcontroller is operating properly?

What values do you have for the crystal load capacitors?

aarg:
How is the piezo soldered to the board? The diaphragm is very heat sensitive, it shrivels on contact with a soldering iron, putting leads on them is a fine art.

Need some close up images of that.

I think you may be on the right track with this question. I can't be there to see them do the manufacturing (in China), but the design is such that there are two solder pads on the board, so presumably they put a small amount of solder paste on the pads then place the piezo face down on the pads then cook.
I pulled a piezo off and it broke a little bit, but here is an image after that:

Hi,
OPs image, can you please attach your images as this will make it easier for some platforms to display.


That method of "fixing" the piezo is nowhere suitable when you are hitting it as hard as you do in the YouTube clip.
The solder in the joint will be adding a thickness to that edge of the piezo, meaning the whole disk is not supported by the PCB, any pressure puts the solder joints under a bending stress and it can delaminate the joint from the PCB.
Also as the joint cannot be observed by the naked eye, the quality of the joint cannot be guaranteed.

This is a classic situation where in hindsight you should have some strategically placed test pads on your PCB for troubleshooting.
Do you have access to a scope?
Can you please post a picture of the component side of the PCB?

Tom.... :slight_smile:

Missing the Schottky across the piezo disc.

But likely mechanical. Piezo should be stood slightly off the PCB, soldered only by one edge, with the central pad connected by fine wire.

Hi,
The piezo is capable of producing much more than the 3V3 volts of the 328 input voltage limit.
The 1M resistor will not do the job adequately.
A clamping circuit of some sort would be recommended.
Did you measure the signal voltage at the analog input to check the output level of clouting a piezo like that?

Tom.. :slight_smile:

Paul__B:
Missing the Schottky across the piezo disc.

But likely mechanical. Piezo should be stood slightly off the PCB, soldered only by one edge, with the central pad connected by fine wire.

Yes, the piezo will work best if it is allowed to flex.
A suggestion would be to mount the piezo on a support ring around its edge and wire the piezo to the PCB so you do not have any solder joints under the stress of "pressing" the piezo.
Is there a reason for the piezo rather than a membrane or tactile button?
Tom... :slight_smile: