Arduino ADC and analogRead()

Arduino analogRead() - reading different analog-in pins in quick succession

I wanted to sample the waveform from a piezo disk after it was hit with a stick (tapped with a ballpoint pen). I copied Todbot's piezo hookup (http://todbot.com/blog/2006/10/29/spooky-arduino-projects-4-and-musical-...) since it looks like he had the same concern I did about high voltage from the piezo destroying the analog input on the Arudino. He shunted the piezo with a 5.1V zener and a 1M resistor to keep the input voltage reasonable

I hooked it up like this and saved the piezo data at the Arduino loop rate (no delays in the code) if I detected a reading above some threshold value. After recording the data I printed it in the serial monitor window. I got maximum readings of about 250 ADU (analog-to-digital units) out of 1023, or 1.2 volts (reference was on a 5 volt regulator). (This is also where I learned that the ATMega168 has only 1024 bytes of SRAM after trying to use a 500-value int data array. I used a 100 point array, which was plenty large enough.)

As an aside experiment, I read the voltage on a 50K audio taper pot on another pin, printing the results to the serial monitor window as they came in. This worked well but I noticed an interesting side effect.

Increasing the potentiometer voltage above about 780 ADU (out of 1023) triggered piezo data recording as if the piezo had been tapped, even though it wasn't. Thinking this might be a problem with settling in the ADC, I added some delays and got things sane again. The waveform printout was odd, though, having decreasing integers from 10 to 1 (and I still haven't tracked this down; probably won't).

This phenomenon is explained in this forum post: http://forums.adafruit.com/viewtopic.php?f=25&t=11597. There is only one ADC (analog-to-digital converter) on the ATMega168 and it's switched (multiplexed) to the six analog input pins. A call to analogRead() swtiches the pin onto the ADC and then the ADC reads it. I'm guessing that after switching from the relatively high voltage on the potentiometer there was still enough voltage on the ADC integrator to trigger the piezo data-recording loop.

The next experiment is to find out how long it takes for the ADC to discharge after being at full 5 volts.

We also learn that the ATMega168 ADC has an input impedance of 10K ohms so maybe the zener and resistor aren't needed at all.