Browse over 10,000 Electronics Projects

ESP8266: Turn a $9 Body Scale into a Smart Scale – Part 1

ESP8266: Turn a $9 Body Scale into a Smart Scale – Part 1

The complete hardware setup

The following diagram shows you how to connect all the components together. As suggested earlier I recommend that you wire everything up on a breadboard first. In the next chapter we will to a first smoke test and also a quick calibration of the sensors. Let me know when you are ready;-).

Smart Scale Setup: HX711 - ESP8266 (Wemos D1 Mini) - SSD1306/ SH1106 - LiFePo4 battery

Smart Scale Setup: HX711 – ESP8266 (Wemos D1 Mini) – SSD1306/ SH1106 – LiFePo4 battery (click to zoom)

Smoke Test and Calibration

While I use the term “smoke test” quite often in my daily software engineering routine I only learned recently that the expression originates from electronics: if you turn the device on and there is no smoke coming from the circuit you passed the first phase.

Let’s do a bit more and use a little program to see if the load cells are responding. While the “real” smart scale project will be using the Platformio environment I decided to use the Arduino IDE for this smoke test. This way you will have a starting ground even if you don’t get adjusted to the Platformio IDE. OK? So let’s get started:

  1. If you haven’t done so, install the latest Arduino IDE. I am currently using 1.6.9
  2. Download this library as zip file: https://github.com/bogde/HX711 and add the zip to the Arduino IDE by Sketch > Include Library… > Add .ZIP library…
  3. For the testing of the OLED display also make sure you have my OLED library installed: Sketch > Include Library > Manage libraries… Search for “ESP8266 Oled Driver for SSD1306 display” by Daniel Eichhorn and Fabrice Weinberg. At the time of writing the last version is 3.2.6
  4. Compile and upload the following code:
    #include <HX711.h>
    
    // Scale Settings
    const int SCALE_DOUT_PIN = D2;
    const int SCALE_SCK_PIN = D3;
    
    HX711 scale(SCALE_DOUT_PIN, SCALE_SCK_PIN);
    
    void setup() {
      Serial.begin(115200);
      scale.set_scale();// <- set here calibration factor!!!
      scale.tare();
    }
    
    void loop() {
      float weight = scale.get_units(1);
      Serial.println(String(weight, 2));
    }
    
  5. Now check the serial monitor. If you see some non-static numbers then the HX711 is probably setup correctly.
  6. Now to calibration. Basically you have to use a known weight and adjust the values by a certain factor. I used my kitchen scale and two tetra packs of milk which weight 2.120kg. Put the same weight on the body scale, take the readings and use the result of the reading divided by the expected value as factor in set_scale(..). If that was confusing, check out the following pictures. Note: at a later stage you should repeat calibration with bigger weights than just two kilograms, e.g. your own weight. This should increase accuracy…

Uncalibrated output. You have to call the set_scale with the proper factor



Advertisement1


Uncalibrated output. You have to call the set_scale with the proper factor (click to zoom)

 

Kitchen Scale with two tetra packs of 2.12kg as a calibration value

Kitchen Scale with two tetra packs of 2.12kg as a calibration value

 

Calibrated output. Now the serial monitor shows the correct values in kg

Calibrated output. Now the serial monitor shows the correct values in kg (click to zoom)

And now as a last step of the smoke test let’s use the OLED display to show the weight:

// change if your are using SSD1306
//#include <SSD1306Wire.h>
#include <SH1106Wire.h>
#include <OLEDDisplayFonts.h>
#include <HX711.h>


// Scale Settings
const int SCALE_DOUT_PIN = D2;
const int SCALE_SCK_PIN = D3;

// Display Settings
const int I2C_DISPLAY_ADDRESS = 0x3c;
const int SDA_PIN = D6;
const int SDC_PIN = D7;

HX711 scale(SCALE_DOUT_PIN, SCALE_SCK_PIN);

// change if your are using SSD1306
SH1106Wire        display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN);
//SSD1306Wire      display(I2C_DISPLAY_ADDRESS, SDA_PIN, SDC_PIN);

void setup() {
  Serial.begin(115200);
  display.init();
  display.flipScreenVertically();
  scale.set_scale(-47941.0 / 2.122);
  scale.tare();
}

void loop() {
  String weight = String(scale.get_units(1), 2);
  Serial.println(weight);
  display.setFont(ArialMT_Plain_24);
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  display.clear();
  display.drawString(0, 0, weight);
  display.display();
}

Simple weight output on the OLED display. Smoke test successful!

Simple weight output on the OLED display. Smoke test successful!

If you see now a frequently updated number on the OLED display then: congratulations! You have successfully destroyed a working body scale, removed a lot of parts and put new ones in and it works again! (Why did we do this again!?!)

Pages: 1 2 3 4 5

 


Top