-->
Page 1 of 1

Adafruit HUZZAH ESP8266 + HX711 + Load sensors

PostPosted: Sat Feb 03, 2018 9:25 pm
by YshkChn
Hey guys,

I was wondering if you have any insights or input into this problem. We are developing a system to monitor the climate and the weight of a sample.

The components used are -
Adafruit HUZZAH ESP8266 Breakout
SparkFun Load Cell Amplifier - HX711
SparkFun Load Sensor Combinator
Adafruit BME280 I2C

Everything seems to be working fine except the load cells, the values jump around quite a lot, even with nothing being weighed and no change in weight. They are bouncing/drifting anywhere from -10 grams to 30g, at 0g weight added. Then, we added a large bucket of water, and the error was the same (about 30-40g in either direction) but because the weight was around 9900g, the % error was less with a larger weight. Apparently the data isn't linear at low weights, but that doesn't account for the changing data even when the weight added isn't changing.

We are thinking some of the error might be because we oriented the direction of the load cells wrong, but any orientation gives the same results. Also, we could find no resources anywhere about orientation direction, so maybe it doesn't actually matter.

Attached are the photos, fritzing diagram, and code used for the system. There is a slight variation in the HX711 module used and the one displayed in the fritzing since I could not find the newer model of the HX711 in the fritzing library. The photos attached should clear any confusion regarding that.

Does anyone here any information or ideas regarding load cell orientation, error calculations, or what the problem may be? Any input will be deeply appreciated.

Thanks!

Code: Select all#include <ESP8266WiFi.h> // ESP8266WiFi.h library
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <HX711.h>

Adafruit_BME280 bme;

const int SCALE_DOUT_PIN = 13;
const int SCALE_CLK_PIN = 12;

HX711 scale(SCALE_DOUT_PIN, SCALE_CLK_PIN);
float calibration_factor = -21.545;

const char* ssid     = "**********"; //network ssid
const char* password = "**********"; //network password
const char* host = "api.thingspeak.com";
const char* writeAPIKey = "**********";


void setup() {

  Serial.begin(115200);
  scale.set_scale(calibration_factor);// set calibration factor
  scale.tare();
   
// Initialize sensor
bool status = bme.begin(); 
    if (!status) {
        Serial.println("Could not find a valid BME280 sensor, check wiring!");
        while (1);
    }
    delay(1000);

//  Connect to WiFi network
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
}

void loop() {

 printValues();
 float humidity = bme.readHumidity();
 float temperature = bme.readTemperature();
 float weight = scale.get_units(15);

 delay(15);
 
 if (isnan(humidity) || isnan(temperature) || isnan(weight) ) {
    return;
  }

// make TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    return;
  }

  String url = "/update?key=";
  url+=writeAPIKey;
  url+="&field1=";
  url+=String(weight);
  url+="&field2=";
  url+=String(humidity);
  url+="&field3=";
  url+=String(temperature);
  url+="\r\n";
 
  // Request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
    delay(1000);
}

void printValues() {

    float weight = scale.get_units(15);
    delay(15);

    Serial.print("Weight = ");
    Serial.print(String(weight, 2));
    Serial.println(" g");

    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");

//    Serial.print("Pressure = ");
//
//    Serial.print(bme.readPressure() / 100.0F);
//    Serial.println(" hPa");
//
//    Serial.print("Approx. Altitude = ");
//    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
//    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");

    Serial.println();
}