Since I got into Home Automation System, I have always wanted a central system with as much as information about me starting from my food habit to each and everything that can be measured or collected. You can say that it is greatly influenced by JARVIS of Iron Man which came around my Engineering days. Coming to the topic, I recently managed to connect a regular bathroom weighing scale to my Home Automation System (OpenHAB) using MQTT. So basically this post is all about how to do that. For the weighing scale, I went with a cheap bathroom scale that comes around rupees 600 and readily available in Amazon or Flipkart in India. You might think why not to use a smart scale already available like the MI Scale, that also features a lot of other parameters like body fat etc. It is due to issues like not all the scale comes with open API (I have not checked all scales though..), and I wanted full control. Sadly though the scale I got doesn't have any easy to connect interface or port to connect external microcontrollers or to fetch data. That's why I had to connect an external Load Cell amplifier to the load cells available in the scale. I used the HX711 load cell amplifier module. The load cells the scale came with have three terminals and are connected in a bridge. The HX711 load cell amplifier has two input channels, and the bridge can be straightaway connected to the S+, S-, E+, and E- pins of the module by using only one channel. The scale has a PCB that has marked the above-said pins making the connections easy. To interface with microcontroller HX711 comes with a serial interface having Data and Clock pins. If you want to know in detail check the datasheet of the amplifier. It comes with 24-bit resolution. To interact with the amplifier using Arduino, I used the HX711 library by bogde with an Arduino UNO. The sketch with the UNO is used to calculate the calibration factor to fetch weight from the amplifier. You can find the sketch from here. Check the video for detail. I used UNO as it is pretty easy to program, you can use the same sketch with ESP8266/ WeMOS though.
After obtaining the calibration factor and getting the accurate weight in the serial terminal, it was time for connecting the amplifier to the WeMOS module and publish the data using MQTT. If you are new to MQTT and want to learn about this, you can check this article. To publish weight data using MQTT, first I tried the pubsub library by Nick O'Leary which I use abundantly in my home automation nodes, but sadly that did not work, and the Wemos crashed repeatedly. Then I moved to the asyncmqtt library by Marvin ROGER which served the purpose. As shown in the video you can use MQTTLens a chrome app to view MQTT messages. But make sure you have a broker installed in your network to enable MQTT messages. If you don't have one you can simply use mosquittohttp://bit.ly/2Mid81nMQTT broker, and it is available for all sort of operating system, and the installation is also pretty easy. Check out the video below on this for detail. The complete sketch is provided below.
You can certainly let me know if it can be upgraded in any ways. Cheers!!!!!