Digital Kitchen Scales
Digital Kitchen Scales - as long they are, they annoyed me. Either their maximum weight only was up to 1 kg or their resolution was less than one gram.
Indeed, I have an (old) scale from a notable manufacturer that can only weigh up to 1 kg, starting at 64 g only with 2 g resolution, merely 9 bits. As long as I put only light plastic bowls on it, it will be enough to make cakes but if I put on the stainless steel bowl of my kitchen machine it already comes to its limits and adding weight becomes illusive.
So, I just wanted to play around a bit and ordered a 10 kg load cell together with a suitable circuit. The later, I would of course better have made myself since there is a great AD converter named HX711, having 24 bits of resolution and being explicitly designed for weight scales. Unfortunately, i found it nowhere to buy and so I had to acquire the board from SparkFun where it is mounted together with a few obligatory parts on a, let's say, mean layout. Incomprehensible but that's the way it is.
With this project I would also like to emphasize, I never came into touch with load cells in my life. This is my first weigh scales and neither the construction nor the circuit may be optimal. It is just an experiment, a game. Maybe you can do it better, just try! Especially what construction concerns, may be a bowl hanging only on three strands as you may know from diamond scales might be better since it avoids uncontrolled torques, but it would also be much more inconvenient.
My final construction showed that it doesn't matter where you place the weight. The cell seems to compensate torques quite well.
If you can do it better, please send me an email and tell me about your way.
My circuit has six digits, that's kg down to 10 mg per Digit, how many of them might be useful, future will show... but, we have a 24 bit converter which would achieve 7½ digits!
This time, I made the circuit in plain THT since I originally just wanted to build a breadboard. But finally it showed that especially if you can see it later, a professionally produced board is just cooler :-)
For the the layout, I decided for KiCad
(version 5.1.9) this time.
For a long time I wanted to see how this open source program
would compete in practice.
KiCad caused great cleavage in my mind.
It has incredibly great features as an open source program like
differential pairs, length tuning and the interactive router that just shoves traces away
as you draw new ones.
As a bonus, you get a 3D-viewer that shows thfile://///UMBRIEL/robert/hp_pub/scale/doc/lpic/scale3d_1267.pnge completed board in a quite good representation.
The seven segment display and the white tab of the regulator still look a bit bumpy
but you would know what they should be.
In the current version 8, together with a few self-made models (e.g. seven-segment display, resistors), it already looks much better.
But KiCad also misses natural functions like polygons on copper layers. I did not find even a function to enter coordinates directly. In any case, it is not intuitive in many points. Some functions only exist if you set the canvas to OpenGL, some only on default, why? I'm a layouter, not a programmer. I don't care for a canvas. If it has to switch to a different one it should be done automatically. I would tolerate a slight color change...
Constructing irregular parts or e.g. circular boards is massively complicated with missing copper polygons. (Well, it can be done at least if you can write python scripts or you are very patient but anyway it looks like shit!)
I created some parts for this project from scratch. Unfortunately they did not comply to the (meanwhile very strict) design rules for approval to the official library. That's why I offer them here for Download.
One rule violating my principals is the pin 1 rule
:
Pin 1 has to be the origin and has to be left top
.
Pin 1? Why should any part have to have a pin 1 at all?
A diode has A
and C
, an electrolytic capacitor has Plus
and Minus
, a pushbutton has CO
, NC
and NO
.
A CE pin 1
!)
What a mess but so you can keep simple rules.
Even if the display turns up to be rotated by 90° or the button is bottom up, don't matter. All I can say for this is simple minds, simple pleasures.
I would never build my library like this! Pin 1 is just as important as pin 3 or any other, why should it get a special position? Why should it be marked, consider a resistor as an example? It is not marked in the schematic, why should it be marked in the layout? This may well make sense for connectors or ICs but for a Button? Or a display or a resistor? For many parts, only the geometric center is useful as an origin, or another meaningful position like the axis of a button, the center of a LED etc. The position of pin 1 is really meaningless.
In fact I also mark pin 1 in my library by a square shaped pad while all the others are circular but not to use it as origin but only to know from where I have to start counting when I want to measure some signal. Imagine a capacitor, 5 mm dia, 3.5 mm pitch. Where would you set the origin? Surely not at pin 1 but at the center of the 5 mm. Only then the capacitor would stay where it is when you rotate it and would not cause unnecessary trouble.
For a button, I would always chose the touch point as origin, for a display the center of the display area (or may be, the top left corner) and for a resistor the geometrical center what is strangely enough also mandatory for KiCad's SMD parts since there is no other possibility to specify the pick up point for the pick-and-place machine...
Indeed, an experienced layouter would probably never directly use any part directly from the KiCad library, not knowing if it will be the same at the next version (or with the next design rules). He would copy it into his MyLibrary or MyCompanyLibrary, adopt it to meet his preferences or simply create it from scratch, whatever would be easier.
In practice, this also is the main barrier to change to a better system. If you worked for years or decades with a certain system, there is a library containing all the parts you have been using over and over again. This would be void if you change over (I have never seen any perfectly working library import into any other system) and all the work would start again.
Of course, you can also use the parts from the new library (as far as they exist) but the look and feel of your work would get lost. This is not what a layouter wants, layouter are also artists! The layout has to be somehow beautiful at the end.
In fact, there is no urge (and no reason) to directly use the KiCad library. It is just a source of ideas, not more and nothing less. Make your own library and pay a shit for design rules you did not develop at your own or that really seem to make sense!
KiCad simply perverts the power of simple design rules without regarding meaning or usability.
Even in manufacturer package-
In earlier times, when monitors were 4:3, only little but since actual monitors have
an aspect ratio of 16:9 this is nearly a factor of two (by width, making nearly a factor
of four in pixel count).
If you align the part horizontally, you get a four times higher detail level than vertically.
For me this is enough of a reason to silently ignore the Pin1-
After designing PCBs over decades, I moved to align parts, pads and even complete PCBs horizontally. This just makes life easier. The position of pin 1 is meaningless nowadays.
In earlier times, when all of the pins were kept in a 0.1" grid and also the simple autorouters were fixed to this grid, it was desirably to put them on grid.
Today it doesn't role a dice if pin 1 is on grid. All of the others are off grid anyway. Consider a 5 mm terminal block, a 2 mm connector or a 0.5 mm LQFP. The origin is set where it makes most sense. Often in the geometrical center or another point of significance.
Even for a 0.1"-
Depending on whom you meet as KiCad's librarian, he may tolerate useful violations or may not... In fact, you might fail on automated checks before you could present it at all.
3d-Models
As far as the 3d-
KiCad didn't want my model, so here you can get it. Of course without warranty of usability in the next KiCad version!
Load Cell
The load cell I used has a range of 0..10 kg and is made of an aluminum block having strain gauges glued to it. They form a bridge circuit and deliver some mV at full load. That's what we want to measure, obtaining a precision in sub per mill resolution! The target is to measure 10 kg at a resolution of 0,1 g or better.
The datasheet is, let's say, poor. It specifies a maximum overload of 120% (so more than 12 kg may already degrade or destroy the cell, but it doesn't tell how much the cell will bend or if it is possible to add a mechanical stop to protect it.
In fact, the load cell only bends for a few tenths of a millimeter. A mechanical stop is practically impossible. It would have to be adjusted at some 10 µm precision and you'd have to protect it from dust and dirt since a grain of dust could make the difference of an overload protection and a mismeasurement because of limited movement.
So in my construction the load cell is not protected against overload. I know it is damageable and I take care for it. In a consumer product you would have to think about other possibilities, e.g. a biased spring to raise the freedom of movement up to a degree where a mechanical stop can be applied. The most simple solution would be two springs over the mounting screws that would start acting at ~10,5 kg and allow the plate to stop at some screws if you happen to have those springs in stock.
Of course, you may also use a different load cell, e.g. one with 200 kg to build a bathroom scales (or one with 50 t for trucks where you can weigh its load at 500 g precision). May be, you'll have to adopt limits for calibration. This might also apply for digital filtering. For me it should not take much more than a second to know what's on, for a truck scales it might be o.k. to wait for five or ten seconds until the driver comes in and wants the bill.
AD Converter
The ADC has a resolution of 24 bits and a PGA amplifying the signal by a factor of 32, 64 oder 128.
This sounds just fantastic but 24 bits make only 300 nV per bit. Noise can be much more than this easily, the PGA not only amplifies the signal but noise as well (even its own) and make 24 bits illusory.
The load cell specifies only 1 mV/V, at 5 V this makes a signal of only 5 mV at full load. Being amplified by a factor of 128 this is just 640 mV so we cannot use the full range of the ADC. At 10 kg this gives us about 6 mg per bit. (Ideally, 24 bits would give us about 0.6 mg per bit.)
So you cannot expect to get 24 bits of accuracy with every measurement but you'll have to filter the signal to get most out of the hardware.
This results in a significant reduction of the measurement rate. For a kitchen scales, one or better two measurements per second are absolutely o.k.
Since the ADC only delivers 10 measurements per second, even this method appears rather limited.
I implemented three different methods for filtering. Have a look at software to learn more.
Noise: The datasheet of the HX is quite confusing. It specifies 50 nV at a gain of 128. This means 6.4 µV at the ADC. This would result in about 21 counts or 4.4 bits. With respect to the 640 mV of the useable range we get 7.7 bits!
So we don't get 24 bits of precision but only 16.3, giving about 100,000 counts or five digits!
Controller
Again, I used an Atmel AVR, the ATmega 48. It is the cheapest ATmega controller having the necessary count of I/O pins. Although it is still too powerful for our application.
Meanwhile, the code has become too big to fit into the ATmega48's flash so at least an ATmega88 is necessary (which is compatible, though). Alternatively, you can also chose an ATmega8 which I ordered in error.
If you would abandon some gimmics of the UI and some other functions (like doing the calibration with a special firmware), the ATmega48 may do it well.
A thought of getting it cheap: might be, you can find an eight pin controller that is so much cheaper that you can save money even if you'd have to add two 19 cent shift registers to achieve the necessary pin count and so your solution would be a bit cheaper. Bur they need more PCB area, that costs again. Calculating big quantities is a really tricky thing...
Display
After decades of abstinence I used a 7 segment display here for the first time again. Even nowadays, I find them simply more elegant than an OLED or a TFT for displaying numbers, better readable without glasses (in 15 years from now, you will understand what I mean) and simply functional. A nostalgic component might also be present.
Why should I try to reproduce 48 segments on a tiny 320x160 OLED that would be no longer available in two years from now? 7 segment displays exist since I can think of them and they probably will in ten or twenty years, even probably pin compatible... An OLED is, e.g. on Ebay, neither cheaper nor more functional than a 7 segment display.
I have been asked, why not LCD? It would consume less power. Well, that's right but on one hand, a LED is better readable and on the other hand, the battery is good for three years. Because of the self discharge this could hardly be topped with LCD.
Of course, you could also add a backlight to the LCD...
Six digits are good to display weights up to 10 kg with a resolution of 10 mg, although the last digit might not be reliable.
In fact, even the second digit of the raw value only showed random numbers but it was one target of this project to find out what the ADC can do and what not.
It is really astounding that there are modern LEDs that produce glistering brightness at one mA but 7 segment displays still need 20 mA per segment. I used a superbright orange type here which claims a bit less. In spite of this, we use 20 mA as well, but in a multiplex rate of 1:6 what makes effictively 3.3 mA for each of the 48 segments. In worst case, the LEDs alone consume about 160 mA from our 5 V supply!
But this is still less than one watt, so nothing to worry about. Only for operating on battery this means we must take some measures to save energy.
With 100 Ohms in series I measured 16 mA per segment. This is in a save region for the LED as well as the port pin and the display is pretty bright. If you start baking your cake at nighttime perhaps even too bright but I did not use a light sensor. If you like it even brighter, use 82 Ω instead. The LEDs will tolerate it.
Although a display reading of 8.8.8.8.8.8. seems rather improbable, it is not uncommon that several segments are on for a long time and make a load of 100% for the port pin.
The readability of the display can be significantly improved by placing orange or red acrylic glass over it, but it is well ok without it, increasing the technical look. However, a completely open construction is more prone to soiling and in a commercial product we had to create some form of box around it. I'm using compressed air spray from time to time to keep it clean...
This works quite good as long as I'm weighing only non-conductive powders like flour and sugar.
Button
A single button was necessary, just to switch it on.
In the production version the button could also be hidden under the PCB so you can switch it on by pressing the display, here I used a simple Shadow Digitast which has a professional appearance and feels comfortable.
Especially with cheap buttons I frequently noticed that the click
has nothing
to do with the switching action.
The button is not only for switching on, its state can (and must) also be read by the controller. Powering off is done by a port pin if the weight is not significantly changing for some time. This is absolutely necessary at least if you power the device by battery. When you use a wall wart, you may select continuous operation by jumper. The device will then stay powered up until you shut down the supply.
After power up as well as after a medium long (>2 s) key press, the weight is set to zero. This can be used as a tare weighing function.
A really long press of the button (>10 s) activates the calibration procedure (for not to activate it by error). The display reads CAL then. Have a look at the software page to learn about details.
Energy saving
To save battery, the display is turned off if the weight does not change significantly. After 15 seconds the display is dimmed darker and darker to show beginning boredom. After four minutes, the scale switches off.
You can reactivate it by pressing the button shortly while it is dimmed and the timeout is reset. Measurement continues all the time and accuracy is not affected. It will also be reactivated if the load changes. So you do not need to press the button, just add weight or shortly press on the scale and the display will come back again.
No problem if you have to go down to the basement to fetch some flour...
After four minutes of inactivity, the scale will power off. The weight is forgotten then and if you switch it on again, it will read 0.0 kg.
In this state, the scale will not draw any current from the battery (except the leakage of the MOSFET of a few µA ) and will give us a battery life of more than five or ten years. So we don't need a separate switch for powering off.
Energy saving mode can be deactivated by placing a jumper from pin 4 to pin 6 of the programming interface connector. The display will not be dimmed and the scale will not power off until the supply is shut down. Powering off via button is not provided. The number of actions you can (reasonably) do with a single button is limited...
Accelerated Power Off
To save even more battery life, another procedure has been implemented to switch power off after 15 s if there is no load, i.e. if no more than 5 g are on the tray, the scale will power off after 15 s. So if you want a rapid power down, reset the scale when you're done (press the button for two seconds) and it will power down after 15 s. This also means, if you want to add weight, reset the scale only when the stuff is ready!
Current Consumption
At full brightness, the scale consumes about 65 mA from a 9 V supply. This can be reduced by suppressing leading zeroes as long as the weight is small enough. 0.073.12 consumes about 81% more energy (!) than 73.12 as you can easily tell by counting the lit segments. So it gives a good return to spend some bytes of memory for this. Together with dimming this reduces to 50 mA or 30 mA in the most dimmed step. We cannot reduce it much more, the rest is simply going into the load cell and the controller. Only powering off is cheaper.
A 9 V battery has a capacity of about 400 mAh and thus would survive about 6 hours actively operating.
This may sound somewhat disillusioning but a complete cycle of 15 s times 65 mA plus 50 s times 50 mA plus 210 s times 30 mA only make 2.2 mAh, so the battery would stand for about 180 measurements. How frequently do you bake? At one cake per week this would be roughly three years. The battery wouldn't make it much longer even without loading. In the manual, we can safely specify a battery life of one year, considering lithium batteries even two years.
First Tests
... were rather disillusioning. I displayed the raw HX value. The last digit only showed random numbers and even the next-to-last changed from -3 to +3. So the lower six bits were just noise. Moving the load cell from one point of my desktop to another resulted in a difference of some hundred counts! Only noise? The force of a milligram is damn' small (because of the gravity of the earth about 10 µN). Forces resulting from temperature changes of the load cell or from changes in its support points can make a multiple of this.
For really precise measurements, the whole device has to be operated in a small, encapsulated space (something like a pie cover) to eliminate forces by moving air or changes in temperature and you'll have to wait until it reached a thermal balance, i.e. all parts of the scale have the same temperature.
But... the noise barely changes if you measure the second input with the pins tied to the ground plane, or the first input with a lump of solder between them. It really looks as if the HX can only measure 16 or 17 bits reliable, at least with the Sparkfun layout and without additional means. Noise is not from the sensor or its wiring, the converters noise is about seven bits!
At 6 mg per bit this would mean that a resolution of more than 1 g is not possible! So four digits would have been enough. How rapidly the 24 bits we hoped to achieve would reduce to mere 17, how rapidly seven digits shrink to four...
Assuming Gaussian noise, we can increase resolution by averaging. Since we get only 10 measurements per second, we would have to wait one second to get the fifth digit, 10 s for the sixth.
Longer Integration Interval
Experiments showed that a longer integration interval (i.e. averaging more than eight, let's say 64 measurements) reduces noise down to a few digits. However, it takes more than six seconds until the display is stable. This is way too long for a kitchen scales but if you want precision it may be worth considering this.
Anyway, the reading slowly but steadily drifts away for some 100 mg. This is probably because of thermal changes and airflow.
Resolution
How high is it? One kilogram makes about 210,000 counts of the ADC so over the whole range well two million versus nearly 17 millions that would make 24 bit. At least the last digit is noise so we can reliably display 100 mg. Well, this was about the target of this project so I feel quite satisfied with it.
Allow me to make a comparison: Imagine 5 V would mate the roughest sea, with waves 10 m in height. With 24 bit we want to see waves as low as half of a thousandth of a millimeter! Even if we reduce it to two million counts, we want to measure the height of a 10 m wave with a resolution of 0.005 mm. We must be crazy...
This simple comparison also explains the noise. A few splashes fly meters above without doing any harm, the main wave goes a bit below (and surely makes you seasick). A short view cannot tell the real height. We have to use averaging to get it.
Side Effects
I knew from the beginning that it would be tricky to measure 10 kg with a resolution of 100 or even 10 mg. But I found it interesting, if you put 1 g on the tray and take it away, the scale reads 0 again but if you press with your hand, the zero of the scale gradually drifts away. This is probably because you warm up the tray with your hand and thereby also warm up one end of the load cell which makes it expand. The strain gauges cannot decide whether that's because of an external force or just by changing temperature. For precise measurements, the whole apparatus has to be in thermal balance and the applied weights must not be much warmer or colder or else must be thermally isolated against the scale (maybe by glueing a cork tile on the tray). Even airflow may degrade the measurement. That's why precision scales are encapsulated in a glass cage and are normally operated inside air-conditioned rooms.
A well suited hint may be to use nylon screws and distance rolls for mounting to minimize thermal influence.
Well, I surely didn't build a precision scales like e.g. one from Mettler but the results and issues were valuable to me and I hope for you, too.
I wanted a scale that measures 10 kg with a sub gram resolution and I have it now. Sometimes, I don't just want to bake a cake but to weigh some other light things.
For what else would you need a resolution like this? Well, a scale counter could be a possible application. But we would need a few addidional keys, even better a number keypad. Then you could count a bag of parts, each weighing only a few 10 mg in one piece accuracy
I expected some more from the ADC's promise but it didn't keep to it.
Mechanical Construction
I used two aluminum front panels (19", 42 TE, 3 HE, that were on our stock...), that I mounted staggered around the load cell so that on the bottom plate was enough space to mount the PCB and the battery holder. The two holes left top and bottom are normally for mounting the panel. Not really beautiful but I can't help, they were there...
Five self adhesive rubber pads (four at the corners and one in the center to reduce bending) make the support to the kitchen table. On cragged surfaces you may not expect precise measurement!
I soldered all wires to the bottom of the PCB. This makes sure, they will not touch the upper plate and thus influence accuracy.
You could also use two breakfast boards and if you have some experience in woodwork it might look really good... Also, wood would be advantageous as far as shock absorption and heat distribution is concerned.
However, this construction does not protect the load cell from overload, especially not from a pulse load. Even if a relatively light object, like a tablespoon, drops onto the tray the allowable load of 12 kg might be exceeded and thus permanently damage the load cell! Sometimes this may have no effect, sometimes you can recalibrate the scales but sometimes it will be broken. Maybe it still shows the weight but it never may achieve the desired accuracy.
It is essential to fix all wires to the bottom plate (Kapton tape would probably be the first choice). Do not keep them longer as necessary, we don't need reserves. Shorten all wires so that they are not longer than necessary. None of the wires must touch the upper plate since this would degrade accuracy.
In the previous photo you can see how I fixed them to the plate with duct tape. The battery wires were not soldered at this point. Unavoidable reserve has been fixed at a 90° angle. None of the wires must stand away and possibly touch the upper plate.