How to Measure Voltage Difference (Between Min. & Max.)?

Since I don't know what "scaling" you're using and I don't know the maximum, let's just work with the raw ADC readings (0-1023).

Initialize Min & Max to their "opposites extremes" (at least one of these values will be updated on the 1st read/loop):

Min = 1023;   //Highest possible value
Max = 0;      //Lowest possible value

Then in a loop:

if (X < Min)    // Update if new reading is less than old Min
   Min = X;   

if (X > Max)   // Update if new reading is greater than old Max 
    Max = X;

let's say a sine wave is applied, whose peak and trough is unknown.

A sine wave has a negative peak equal to it's positive peak, and it crosses-through zero twice per cycle, so the minimum (absolute value) is zero. The Arduino can't read negative voltages, but fairly it's common to bias the input at 2.5V . Then, you can optionally subtract-out the bias.

1 Like