Reading a positive voltage spike between 0 and 5 volts

I have a project that requires an analoge input on an Arduino 101 to read a positive voltage spike on one of the analog inputs. I was wondering if I can get a little help.


Connect your 5V Arduino to a PC.

Open up the Arduino IDE and under the File menu choose Examples -> 03.Analog -> AnalogInOutSerial

Under Tools choose your board.

Under Sketch, choose Upload.

To see the program output, under Tools choose Serial Monitor. Make sure it is set for 9600 baud.

You might want to connect something to be measured to the analog input.

Hi jremington,

As you mentioned with AnalogInOutSerial sketch, I think that this sketch can not get the voltage spike in real time. Because the sketch used a loop which will take a time for each loop. Plus the function analogRead() also takes about 100us to read an analog input. So that the total time in order to get one value will be at least 100us. During that time if there is another voltage peak, then it will be missed.

Is there another method to get the voltage peak without missing the peak events if it happened?


Why don't you attach the input to an interrupt pin (2 or 3 on the Uno(, and set an interrupt service routine that looks for a rising edge?

Thanks for the input so far. Let me elaborate my needs a little more. What I have is a force sensor that is being struck with a mallet. I need to be able to read the voltage spike from the sensor which in turn will trigger the apprpriate set of LEDs and MP3 tracks. Think of it just like a strenght meter at a carnival.

Striking a force sensor with a hammer is an extremely slow even for an Arduino.

I would read an analogue input frequently in void loop(), and hold it's peak value for a certain amount of time.

The "knock Sensor" example that comes with the IDE might give you some ideas. Leo..

You might consider a [u]peak detector[/u].

I use a peak detector for my sound-activated lighting effects. It allows the processor to go-off and do some other things and read the audio level less frequently.

You might want to take a look at Nick Gammon's excellent tutorial on ADC conversion in the Arduino By changing the prescaler the analogRead() can be made significantly faster. There are also ways to make the function non blocking and automatically triggered. There is a nice example of 50Khz timer triggered analog data acquisition.

There is also a free running mode documented in the ATmega 328 datasheet.