Loading...
Searching...
No Matches
AnalogDifferential.ino

Measures the voltage between two pins twice a second, with analogReadDifferentialMillivolts():

  • A3 - A4: true differential; the on-board ADC samples both pins at the same instant, so noise common to both cancels. ±1024 mV in 0.5 mV steps.
  • A0 - A1: computed from two readings a few µs apart; fine for slow signals.
Wiring
The two points to measure between, e.g. the ends of a resistor, on A3 and A4 (each 0-2.048 V) or A0 and A1 (each 0-3.3 V).
Output
Serial Monitor at 115200 baud, for example:
A3 - A4: 251 mV A0 - A1: -12 mV
// Measures the voltage between two analog pins, e.g. across a resistor or
// a sensor bridge, twice a second.
//
// A3 - A4: true differential. The on-board ADC samples both pins at the same
// instant, so noise common to both cancels. Range ±1024 mV in 0.5 mV steps
// (a larger difference is measured as two separate readings).
// A0 - A1: computed from readings taken one after the other, a few µs apart.
// Fine for slow signals, but noise on both pins does not cancel.
//
// Keep every pin between 0 V and its full scale (A0-A2: 3.3 V, A3-A5: 2.048 V).
void setup() {
Serial.begin(115200);
while (!Serial) {}
analogReadAveraging(16); // steadier readings
}
void loop() {
Serial.print("A3 - A4: ");
Serial.print(" mV A0 - A1: ");
Serial.println(" mV");
delay(500);
}
SerialUSBClass Serial
USB serial port, the one the Serial Monitor uses.
void analogReadAveraging(uint8_t samples)
Sets how many samples are averaged for each analog result, on every analog pin.
int32_t analogReadDifferentialMillivolts(pin_size_t plus, pin_size_t minus)
Voltage between two analog pins, plus minus minus.
void loop(void)
Written by the sketch: runs over and over after setup(), on core 0.
void setup(void)
Written by the sketch: runs once after reset, on core 0.
void delay(unsigned long)
Waits a number of milliseconds.