hi guys
I am trying to read a knock sensor with the nano but no luck so far. reads up and down
its a car knock sensor "hyundai accent 2 1.3 1.5 2000 2005" unit and cant get it to read propper
Normally a knock sensor creates voltage uppun detect if i am not wrong,
its a piezo used in cars to meassure engine knock.
thanks guys
const int Voltread = A1;
int knockSensor = 0;
void setup (){
pinMode (Voltread, INPUT);
}
void loop() {
int knockSensor = analogRead (Voltread);
Serial.println (knockSensor);
What output do you get?
For best results you should add a circuit to hold the short spikes. Or you amplifiy (and limit) the signal into the digitial level range (0-5V) and catch changes with a pin change interrupt.
If the sensor is not sensitive enough, you have to knock harder or mount it better.
Well i have hit it quite hard the thing is that by just connecting the the sensor y goes from 0 to over 1000 randomly.
I have set it it pin a1 to knock and the other to positive, have also tested ground, no luck
When I connected a bare Piezo disk to my Uno, I put a circuit between to protect the Uno pins. Piezo makes high voltage spikes but they are tamable.
The crystal layer in the disk when compressed makes a voltage difference that the metal faces pick up. One wire becomes + and the other -, which drives current if they are connected. When released the + side becomes -, the - becomes + and current flows back.
I think of a Piezo disk as a capacitor that can be charged by squeezing. There is probably a circuit in there...
What I did:
I put 2 diodes on each Piezo wire. One diode points into the wire and the other points out. Both inward pointing diodes got connected to ground, that takes care of -V that Ardiono IO pins should never get.
The 2 outward pointing diodes, one on each Piezo wire, those are the signal lines. The diode will do much to flatten the spikes but now the signal is weak, I fed mine to a cheap transistor (BJT) that made 5V flow to my "Piezo sensor pins". The 5V fed to the BJT collector went through 2200 ohm resistor to limit the current that would flow, it was enough to make a LOW pin HIGH.
The harder the knock, the longer the flow. I used that to charge a short jumper between the BJT emitter and Arduino pin with no pulldown, the charge stayed in the wire. The Arduino pin was digitally read at high frequency, each read drained 1 microamp of charge from the wire to empty it quickly. All that my sketch knew was pin goes high and how many reads before it goes low. Hardest hit made > 2000 reads, just to touch made 50 to 100, a soft touch made 10 to 30.
You could probably feed the piezo outputs to an opto-isolator and not hurt it, but that is only probably. It would certainly be simpler/easier than the diodes, resistors and BJT's I used. You won't get the release data but you should get knocks.
Thanks, any diagram? I need the sensor to give me a range of values so i can condition the functions in the nano
Thank you
No, I'm not set up to do diagrams here.
First I saw this years ago:
The harder the touch, the brighter and longer the flash. I don't know how hard the knocks you want to sense are though.
Then I saw this, it has a rectifier circuit and spike-eating capacitor.
See the circuit? Depending on how hard the piezo is tapped you may want a different value capacitor.
Very probably you can sense the voltage across the cap and put a (guessing) 100K resistor across the cap leads to slow bleed the charge then you have both averaged voltage at any instant and time over some threshold to infer hit energy.
I started with the diodes set up as a full wave rectifier then split that so I could read press and release on different pins.. because I could.
Very basic with good explains. The capacitor eats spikes. A full wave rectifier would almost double the efficiency
A full wave rectifier (2nd video) would almost double the efficiency. As shown it throws the release surge away.
Hi,
Have you googled arduino automotive knock sensor
Tom.... 
yes, i did, did not find what im looking for.
in the code, one part is ground and the other input to the arduino to read voltage.
just is a pot/resistor enough to get a stable signal? as just pluging in it goes from 0 to above 1000 randomly without doing nothing to it
have done the "knock" sketch and wiring to it, no luck at all.
i have seen the examples and with the piezo in the videos works,i am using a car knock sensor and it might doesnt work the same way...did hit it hard and no reading to arduino
Danny1000:
yes, i did, did not find what im looking for.
in the code, one part is ground and the other input to the arduino to read voltage.
just is a pot/resistor enough to get a stable signal? as just pluging in it goes from 0 to above 1000 randomly without doing nothing to it
Did you take into account, as mentioned previously, the pulse is AC and you need to rectify it and perhaps filter it with a capacitor before trying to read the voltage on the Arduino.
Paul
Hi,
An automotive knock sensor is not just a piezo pickup, it has been manufactured to respond to the "engine knock" or more accurately "pinging" which is not a "thud".
I has a specific frequency response.
So just thumping the sensor will not produce the required "knock" output.
Tom... 
Danny1000:
Well i have hit it quite hard the thing is that by just connecting the the sensor y goes from 0 to over 1000 randomly.
I have set it it pin a1 to knock and the other to positive, have also tested ground, no luck
Uh huh, not used in a car but hit for other purpose. To me, the car part is a black box with unknown elements, easier to use the simple.
That's why I say get yourself piezo disks on eBay. They're cheaper in bags of 10 but take care as to size and quality.
If you want to detect knocks on the other side of a door from the pickup then use cheap transistors (BJT) to give the signal boost, no higher V will exit the emitter than flows into the collecter, the output is pin-safe regardless of piezo spike.
You won't need diodes, BJT's are made of diodes. Since Piezo wires switch polarity, one NPN and one PNP per Piezo lead could boost all of the Piezo output ,which through a door may be faint. You will know when the door gets rattled.
Hi
I need it to be a car sensor because it will meassure th engine knocks, i have tested the sensor with a dmm and giving it some force it gives up to 4v, resting reads 0, strange is thst the arduino even the unit resting reads random values and with a small resistor...always 0.
What code would you suggest? Maybe something wrong with my coding
Thanks
Hi,
Try a 1M or 10M resistor across the sensor and measure what you get out of it.
The output will be a ringing AC voltage.
The piezo devices are high output sensors, so will load down very easily.
Have you googled arduino automotive knock sensor
Tom.. 
Yes, did google it and dis not fint what it i need.
I did try to clean signal with a capacitor and it reads constant 0 
I managed it once to work without any res or caps, 2nd time i had again all the spikes... checked the connections and they are ok...will try again and see what i have missed.. cheers
Are trying to get the Arduino to produce a voltage display like an oscilloscope? Or are you trying to determine if there is a "knock" or "no knock".
Without seeing your entire code, hard to determine.
Paul
Danny1000:
Yes, did google it and dis not fint what it i need.
Didn't any of the links show you how to get the sensor signal to be read by the controller?
Start there, don't go looking for complete code to do all you need.
This link to an old SiliconChip article shows a block diagram need to extract the "knock" signal.
http://archive.siliconchip.com.au/cms/A_108910/article.html


Tom... 
For students, hobbyists and professionals we offer the Knock Shield for Arduino. It offers them the possibility to learn how to implement a programmable knock detection sensor in their products or projects. Check out our example code on GitHub. Watch the getting started video on YouTube.
Hi,
Thank-you for the input, interesting shield.
Tom... 