Reading voltage from a wheatstone bridge with an HX711

I'm trying to build a wheatstone bridge using only resistors for now (I will use strain gauges once I fix this issue). I've attached an image with my setup here:

I'm using an HX711 connected to the 5V and GND ports of an Arduino UNO and four 220 ohm resistors for the Wheatstone bridge; the measured excitation voltage of the HX711 is around 4.15 V. First, to see if the connections are correct I have directly measured voltages in different points of the circuit, and even used different values of resistors and they seem alright. However, when I try to obtain a voltage from the readings of the DT and SCK ports of the HX711, there seems to be a problem. This the code I'm using:

#define GAIN_128 25
#define GAIN_64 27
const int doutPin = 4;
const int sckPin = 5;

void setup() {
  Serial.begin(57600);
  pinMode(doutPin, INPUT);
  pinMode(sckPin, OUTPUT);
}
void loop() {
  unsigned long raw = readHX711();
  Serial.println(raw);
  delay(500);
}
unsigned long readHX711(){  
  unsigned long data = 0;
  uint8_t dout;
  
  while(digitalRead(doutPin)){}  // wait until value is available
  for (uint8_t i=0; i<GAIN_128; i++){   //highest Gain
digitalWrite(sckPin, 1);
    digitalWrite(sckPin, 0);
    if (i < (24)){
      dout = digitalRead(doutPin);
      data = (data << 1) | dout;
    }
  }
  data = data ^ 0x800000; // flip bit 23
  
  return data; 
}
void powerDown(){
  digitalWrite(sckPin, LOW);
  digitalWrite(sckPin, HIGH);
}
void powerUp(){
  digitalWrite(sckPin, LOW);
}

The readings I obtain are in two complements, being '16,777,215' the maximum value, '0' the minimum value, and '8,388,608' the two complements zero. I have assumed that these values are proportional to the measured voltage between the A+ and A- connections, like this: [(Vmax-Vmin)/(2^24bits)]*reading+Vmin, being Vmax=4.15 V and Vmin=-4.15 V.

When A+ and A- measure the voltage difference between the excitation points E+ and E-, I do obtain a reading I expected of either '16,777,215' or '0' (+4.3 V or -4.3 V respectively, I suppose), and when A+ and A- are not connected to the breadboard I get '8,388,608' (I assume an expected value of 0V). However, when I connect A+ and A- to the wheatstone bridge, the values I read are mainly either '16,777,215' or '0', irrespectively of whether I change the value of one of the resistor or not.

What may be the problem? I'd appreciate any kind of help.

Thank you in advance,
L.

I will take a SWAG and say you have your excitation polarities reversed. I cannot tell from your picture, a schematic is always better.

With gain set at MAX, maybe the offset error from your bridge is driving the HX711 out of bounds. Start at lowest gain and work your way up.

1 Like

...then you applied a differential voltage of 4.15v to A+ and A-. The full-scale input range is about 16 mV (<-- that's from 0.5 x 4.15 v / 128 gain)...positive or negative. Any differential voltage larger than 16 mV will give you 16,777,215 or zero. Since you applied a huge differential, of course you will get 16,777,215 or zero. Which number you get depends on whether the differential is positive or negative...swap A+ for A-, and the output will change from 16,777,215 to zero, or vice versa.

...then A+ and A- are floating, so the output is meaningless.

...so take your DMM, measure the voltage across A+ and A-. If it reads more than about 16 mV (either positive or negative), then you are certain to get '16,777,215' or '0', since 16 mV is the full scale input range, above which the output will "clip" at '16,777,215' or '0'.

1 Like

@lammiae
You may exercise the following setup for study purposes:

Sketch:

/* This program takes 10 samples from LC + HX710B at
   1-sec interval and then computes the average.
*/

unsigned long x = 0, y=0;
unsigned long dataArray[10];
int j = 0;
void setup()
{
  Serial.begin(9600);
  pinMode(A1, INPUT); //data line  //Yellow cable
  pinMode(A0, OUTPUT);  //SCK line  //Orange cable
}

void loop()
{

  for (int j = 0; j < 10; j++)
  {
    digitalWrite(A0, LOW);//SCK is made LL
    while (digitalRead(A1) != LOW) //wait until Data Line goes LOW
      ;
    {
      for (int i = 0; i < 24; i++)  //read 24-bit data from HX711
      {
        clk();      //generate CLK pulse to get MSB-it at A1-pin
        bitWrite(x, 0, digitalRead(A1));
        x = x << 1;
      }
      clk();
      Serial.println(x, HEX);
      y = x;
      x = 0;
      delay(1000);
    }
    dataArray[j] = y;
  }

  Serial.println("===averaging process=========");
  unsigned long sum = 0;

  for (j = 0; j < 10; j++)
  {
    sum += dataArray[j];
  }
  Serial.print("Average Count = ");
  sum = sum / 10;
  Serial.println(sum, HEX);
  //float W = (float)0.90*(sum-901002)/946560 + 0.75;//0.005331 * sum - 1146.176;
  //W = (float)W / 1000.00; 
  //Serial.println(W, 2);
}

void clk()
{
  digitalWrite(A0, HIGH);
  digitalWrite(A0, LOW);
}
1 Like

Hi Sir,

All your remarks have been of great help, and I think I get a much clearer image of how this works now. Staying within range is indeed what I had to do.

Thank you very much!

This is indeed something to consider and has been helpful. Thank you very much!

Hi Sir,

Thank you very much for taking the time to add the schematics and code for this topic. Averaging the last 10 readings is indeed a very good idea, especially since the readings I am now obtaining are not very stable.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.