Analog Sensor Calibration

Using a simple mathematical formula, it is possible to calibrate analog sensor readings. If you are using a COTS analog sensor, and have access to a high quality, or more reliable sensor, taking several readings can provide a coefficient and offset for calibration.

In this example, a voltage sensor is implemented with a voltage divider. A digital multimeter is used to glean more accurate readings, and a coefficient/offset is generated with Octave/MATLAB.

All source code can be found on GitHub.




  1. Install all software for the MPIDE and the Max32. Make sure you can program ‘Blink’.
  2. Make the circuit as shown in the schematic: voltage_bb
  3. Load the source code in Verify, upload, and open the serial port at 9600 baud. You should see a screen crawl like so:Screen
  4. At this point, the ‘slope_modifier’ and ‘offset_modifier’ in “Voltage_Example.ino” are based off my calculations. Set them to 1 and 0 respectively. Verify, upload, open serial port.
  5. Once the code is running, attach your Digital Multimeter (DMM) to GND and Vin on your circuit, and set to voltage reading.
  6. You can now attach various voltages to the Vin. Annotate the voltage output from the Max32, as well as the output from the DMM. Full hookup example with a bench DC power supply:IMG_2251
  7. The above hookup uses 3 DC power samples, 3.3V, 5v, and 12V. If you have a variable power supply and can get more readings, all the better.
  8. In the calibration script, edit the ‘dmm’ and ‘chipkit’ variables to have their respective values for each reading. Once complete, run the script with Octave or MATLAB. The result should show the ‘slope_modifier’ and the ‘offset_modifier’ along with some error information.
  9. Copy/paste the two modifiers into the .ino file in their respective places. Verify, compile, and open the serial port.
  10. Running the same test through the different DC values should show more precise readings from the Max32.


Using simple mathematical methods, this example shows a process to increase the precision of an analog sensor reading. This method will work for any analog sensor, e.g. analog pressure differential or temperature.


Leave a Reply