Onset Detection Peak Picking
compute RMS from audio signal to get power
do AGC (automatic gain control)
perform "discrete differentiation" (the simplest is 1st order: $y[i] = x[i] - x[i-1]$)
if the value is greater than certain threshold, it means we have an onset. You have to determinate the threshold experimentally or use adaptive algorithm. Obviously you also need some kind of lowpass filter to filter the noise.


You may want to swap steps 2 and 3.

If you can use software libraries, check out aubio.

Possible duplicate of https://stackoverflow.com/questions/294468/note-onset-detection