Bed with a scale

Sun 10 September 2017

Arduino, Elektronik, Haushalt, Mechanik, Raspi

Translations: DE

This web site shows the progress of integrating a digital scale into a bed frame. This is only a hobbyist project and as such cannot be compared with commercial offerings.

**Note:**This is currently a work in progress, so stay tuned.

DISCLAIMER: This is a hobbyist project that is not meant for use as a medial instrument. This is a purely informational assistant system that does not guarantee for accuracy. I cannot claim any liability for its use, if you choose to replicate this build, you are doing so at your own risk!!

About

Even today a scale is still pretty primitive, yes you can hook it up to your phone and upload even more of your private data to the cloud, but this is about it. Most of the time you end up jotting down your weight and dates and try to keep on schedule doing so. Then getting everything plotted right is another disaster to happen if you don't want to push everything to the internet. Also getting everybody in the household to get the weight measured on a regular basis can be challenging, especially when you have cats.

This led the author to the idea to fit an automated digital scale to a bed frame of a large internationally acting Scandinavian furniture distributor.

Functional description

The MALM series bed frame was already in use and therefore lend itself to be fitted in the project. The project itself should be pretty easy to be transferred to different beds or even other furniture.

Four load cells of chinese origin going under the name of "TS-606", distributed by SparkFun amongst others, make the sensors for this build. These little puck type compression load cells are supposed to withstand up to 200 kg each. It is especially practical, that these are in full bridge configuration which makes thermal compensation and part-to-part variations basically a non-issue. Custom brackets fit around the bed frame and are fastened to the load cells.

The interface for sampling these cells consists of an Arduino Nano Clone and four HX711 A/D-Converters that are purpose build to use in digital scales. These offer integrated preampfification, 24bit of resolution and have a very simple two wire practically quasi mono directional synchronous serial interface. Using four A/D converters avoid having to switch low differential voltages (ΔU = ~1mV).

To quickly reach a working prototype stage, because of potential harm to the WAF Arduino Nano was used. Sampling all HX711 at once required some rewrite of the aptly named library thankfully provided by SparkFun. My parallized version is available on (http://www.github.com/ptwz/HX711). The sampling rate is approximately ten samples per second, the Arduino taking 10 averages leads to an effective sample rate of about one sample set (four sensors) per second.

Overall schematic

Module schematicCircuit board installed

Mechanical structure

The following criteria where elevant to the mechanical design:

  1. Easy assembly: No need for a lot of woodworking, which the author lacks the experience in and minimize the unavailability of a sleeping place at home which could potentially lead to unwanted friction with the wife.
  2. Stability: The whole contraption should not fail under normal loading conditions. Furthermore it should not be wobbly or somehow uncomfortable.
  3. Water resitant: When cleaning, contact with water should not make the system fail.

To fulfill the above mentioned critera each foot consists of three major parts:


  • A U-shaped aluminium profile, which slides on the bed frame. M3x16 counter sunk bolts fasten it to the sensor module.

  • The sensor module itself is fastened onto the underside of the U-shaped profile. The force is measured by the stub (diameter 2.5mm), to avoid damage to the fooring it sits in the cup below.

  • The cup serves multiple purposes. First of all it gives the sensors stub a guidance which will prevent the whole contraption from sliding around uncontrolled. Furthermore to some extent prevents water from reaching the sensor.

The finished assembly looks like this: Aussenansicht

Code for the micro computers

The Arduino's job is rather simple, take a ten samples per ADC, calculate their individual averages and relay this information to the host via UART over USB. In this case the host is implemented using a Raspberry PI that was in the home network anyway.

The HX711 library that SpakFun recommends using has been modified to accommodate for up to eight load cells that can be queried in parallel. This ensures all load cells are sampled at the same time, so shifting loads are properly measured. Also this enable a constant sample rate of ten samples per second. The original library would have required reading each ADC individually which would have slowed down things by a factor of 1/4th.

The Raspberry Pi's software is much more elaborate. First of all, the values read from the UART are converted to floating point numbers in kg units. These four resulting values are inserted into ring buffers (dequeues) with a length of twenty samples each. Then after inserting the new value into the buffer, an average and standard deviation is calculated per channel.

If the sum of all channels standard deviations is below a threshold of 50g, the value is considered stable. If the last round was considered unstable and has just stabilized the sum of all sensors is taken as the newest weight reading. If this in turn has changed less than two kilogram the new value is saved but not output. This makes for an automatic drift compensation. If the step is more than two kilograms in turn, the value is output to a log file with a timestamp and its standard deviation.

Fine, so now we have the weight changes on the bed over time, but how to determine whose weight has been observed. In a perfect world (at last from a programmers view), every inhabitant will enter and leave the bed in appropriately spaced intervals and not go to bed on the same time. Going to bed at the same time unfortunately is quite often practiced by the author and its wife, so this is not a perfectly simple world. Even worse, the cats tend to flee the bed whenever it is evident that someone is about to get up, so getting up is not a good time to determine individual weights

To assign the weight changes amongst all people and animals living at home, the current weights are kept in a file. When processing a new weight change, all possible combinations of the inhabitant are made into sum of current weights. The closest of these values is considered realistic if the difference is below 500g absolute and three percent relative.
If there is more than one individual observed, the weight gain/loss is distributed evenly among them. This might offload some of the humans weight gain after e.g. a work dinner to the cats but this effect will cancel itself out quite quickly.
This way the algorithm works itself through the dataset and spits out names and their weights at certain time points. This data can then finally be processed using e.g. gnuplot or flott.js/plot.py when feeling up to something more modern. See the gnuplot generated sample below, note that the y axis is distorted in a non linear way for privacy reasons.

Downloads

All sources are available from https://github.com/ptwz/bedscale.