Go Down

Topic: Analog read pin on Atmega328 chip and piezo knock sensor, how to avoid overload? (Read 797 times) previous topic - next topic

alexmg2

Hi all, playing with piezo knock sensor today, connecting it to analog read pin on Atmega is super simple and I have no problem there, also reading value from that pin is not a problem since the code is very simple, I am just curious: since analog read pin's input voltage per Atmega-s datasheet should be in a range of -0.5V to VCC+0.5V how can I limit my piezo not to exceed that value? I know some piezo elements can generate some decent volts so I am curious if there any technique that will limit voltage input coming from piezo?

vaj4088

The usual way is to wire a Schottky diode from the pin to Vcc so that the diode conducts if the voltage on the pin exceeds Vcc.  Also wire a Schottky diode from the pin to ground so that the diode conducts if the pin goes below ground.  Test!

However, if the voltage of the sensor is excessive you may need to be more aggressive, using other devices (such as a current limiting resistor and/or transorbs) to protect the ATMega.

By the way, the diodes will slightly affect the shape of the waveform coming from the knock sensor, but I gather that this is not important for a knock sensor.

I hope that you don't use up too many Arduinos.  Good Luck!



Wawa

No need to add anything to a piezo knock sensor.
Except for a 1Megohm resistor to ground, to stop the pin from floating.
A common 1" piezo isn't able to deliver the current to damage a pin.
Arduino pins have inbuild protection diodes to VCC and ground.
They clamp the voltage of the piezo to VCC+0.5volt and GND-0.5volt.
Protection is only needed if input current can get over 1mA.
See this Atmel application note where the connect 680volt pp to a pin through a 1Meg resistor.
www.atmel.com/images/doc2508.pdf
Leo..

alexmg2

Thanks everyone for info, I will continue experimenting without protection diode as Wawa suggest , piezo I am using even less than 1", if Atmega fails, I'll then add shottky's, which seems very easy too.

Wawa

Some knock sensor code to try.
Multiple A/D readings, so it doesn't miss knock peaks.
Very sensitive if you set the threshold to 1.
With the bare piezo flat on a desk, with some soft weight on it, it can detect a pin dropping on the desk.
Leo..
Code: [Select]
// knock sensor/alarm
// Piezo, with 1Megohm load resistor across, connected to A0 and ground
// optional 5volt buzzer on pin 13

int threshold = 100; // alarm threshold from 1 (very sensitive) to 1022 <<<<<<<<
int alarmDuration = 100; // alarm duration in milliseconds <<<<<<<<

const byte piezoPin = A0;
int rawValue; // raw A/D readings
int piezoValue; // peak value
const byte onboardLED = 13; // onboard LED and/or buzzer

void setup() {
  analogReference(INTERNAL); // remove this line if too sensitive
  Serial.begin(9600); // serial monitor for raw piezo output
  pinMode (onboardLED, OUTPUT);
}

void loop() {
  // reset
  piezoValue = 0;
  // read
  for (int x = 0; x < 250; x++) { // multiple A/D readings
    rawValue = analogRead(piezoPin);
    if (rawValue > piezoValue) {
      piezoValue = rawValue; // store peaks
    }
  }
  // print
  if (piezoValue > 0) {
    Serial.print(F("Piezo value is "));
    Serial.println(piezoValue);
  }
  // action
  if (piezoValue > threshold) {
    Serial.print(F("The knock was over the threshold of "));
    Serial.println(threshold);
    digitalWrite (onboardLED, HIGH);
    delay(alarmDuration);
    digitalWrite (onboardLED, LOW);
  }
}

Go Up