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;-).
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:
#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)); }
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(); }
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!?!)