Electronic – arduino – hx711 voltage measurements

adcarduinovoltage divider

I wanted to use HX711 24-bit adc standalone to measure voltage range of 2mv – 20mv.

Problem is:

  1. I cannot interpret the adc readings as it is in 2's compliment.
  2. What should I do in my code (code below) so that it prints voltages not decimal values.

Tried with different values of voltages (shared below), and I am totally confused with the readings I am getting. I don't know how to convert these values in voltage. What is the logic behind. Please help!


   0mv  ---  5219,
 1.1mv  ---  5095,
 2.3mv  ---  4981,
 2.5mv  ---  4960,
 2.9mv  ---  4918,
   5mv  ---  4693,
10.6mv  ---  4075,
15.1mv  ---  3597,
22.7mv  ---  2700,
40.7mv  ---   562,
5volts  --- -8388608,
-5volts --- -8388607.

Board is arduino leonardo, and a simple voltage divider is used for voltage generation(for testing only).

A bogde/HX711 library is used: https://github.com/bogde/HX711

/#include "HX711.h"
/#define DOUT  3
/#define CLK  2

HX711 scale(DOUT, CLK);

void setup() {

void loop() {
  long avg = scale.get_value(60);
  Serial.print("Digital Code = ");

Circuit Diagram

Best Answer

A good plan is to start by drawing a graph. If you start by assuming the ADC is OK, then a graph will tell you what sort of offset, gain, polarity you have. Just whacking the first few numbers you posted into a spreadsheet, and doing an XY graph, yields this.

The general equation for a straight line is y=mx+c. A good ADC will have a straight line relationship between the input voltage and the output code.

The spreadsheet has two columns, one the actual input voltage, the other y=mx+c, where x is the ADC reading. I've roughly adjusted m and c to give a reasonable fit over part of the curve. I've left the offset off a bit so you can see all of both traces.

You will notice that you need to multiply the ADC reading by a small floating point number. Whether you can do this with your particular compiler, and exactly how, is a programming exercise for you.

enter image description here

As you see, the points do not fit a straight line. It might be the ADC is non-linear. It might be your voltage measurements are non linear. You will need to investigate which before you put your trust in this system.

I would suggest swinging the voltage from -FSD to +FSD (is it designed to go between +/- 5v ?) in a dozen or so steps, and then drawing a similar graph. When you can see what's happening on the large scale, examine smaller ranges. Notice where the ends of the valid range are, and see what code it outputs when it overloads. Try to understand where any discrepancies from linear are coming from.