Ks0087 keyestudio DIY Electronic Scale
keyestudio DIY Electronic Scale
Introduction
Electronic scale is commonly seen in our daily life, with function of weighting. Professional scales on market have more functions and its precision is higher. Is there any possibility for enthusiasts to DIY their own electronic scale with what they have learned? Absolutely you can! It is easy to make an open source electronic scale. You just need a weighting module, an AD chip (hx711) specialized in weighting, and Arduino with corresponding library. Everything becomes so easy!
Principle
Electronic scale weigh force according to slight deformation causing by pressing metal. It uses the most commonly used strain gauge to measure deformation. In a typical application, utilize the strain gauge adhered on face of this sensor, to measure the force bore by the sensor. HX711 is a chip of 24 bit A\D converter, designed for high precision weighing sensor. Compared with other same-type chips, this chip features high integration, quick response and strong anti-interference, integrated external circuit needed by other chips including stabilized voltage supply and on-chip clock oscillator. It decreases cost of complete machine of the scale, and in the same time improve its performance and reliability. The interface and programs of this chip and MCU chip are very simple. All control signals are driven by pins, without programming register of inner chip. Input and select switch to choose arbitrarily channel A or B, connecting it to a low-noise programmable amplifier. The gain in channel A is 128 or 64 bit, and its corresponding amplitude of different input signals in full loaded is respectively ±20mV or ±40mV. The gain in channel B is fixed 32, used to detect system parameters. Stabilized voltage supply offered by chip can directly supply power for external sensor and A\D converter, there no need for additional analog power on main board. Clock oscillator doesn't need any external device. Automatic reset simplifies initialization when opening up.
Features
Channel A or B can choose different input.
The gain is 64 or 128 in the low-noise programmable amplifier.
Stabilized voltage supply offered by chip can directly supply power for external sensor and A\D converter.
Clock oscillator doesn't need any external device. If necessary, it can use external crystal oscillator or clock.
Automatic reset function
All control signals are driven by pins, without programming register of inner chip.
Alternative 10Hz or 80Hz of output data rate
Kit List
Connection Method
1)VCC can be any value among 2.6-5.5 . Because we use Arduino, just connect to 5V, and to GND.
2)Connect SCK to Pin 9, DT to Pin 10 on Arduino; you can change the pins in program.
3)Connect E+ to positive driving voltage, E- to negative, A+ to positive output voltage and A- to negative on bridge sensor.(E+ to red wire, E- to black wire, A+ to green or blue wire , A- to white wire )
4)Connect B+ and B- to sensor of channel B, or connect to power supply through partial pressure circuit, in order to detect supply voltage. If not, you had better connect to GND. But disconnect GND is OK.
Connection Diagram
Debugging Step
Open sample codes in Arduino, and you can see they are very easy:
#include <HX711.h> // including library HX711 hx(9, 10); // digital pins definition void setup() { Serial.begin(9600); } void loop() { double sum = 0; // in order to decrease error, taking the average of 10 values for (int i = 0; i < 10; i++) // the more the cycling the higher the precision, and the more time sum += hx.read(); // accumulating Serial.println(sum/10); // averaging to get mean deviation } These sample codes are very simple, but there are a lot of sample without function: HX711(byte sck, byte dout, byte amp = 128, double co = 1); // define SCK and DOUT pin, gain factor(default 128) and correction factor(default 1) void set_amp(byte amp); // changing gain factor and corresponding channel, and invoking read() at least one time to work bool is_ready(); // whether turning beck hx711 is useful, and it is invoked in read() long read(); // turning beck sensor voltage value, if hx711 not working, the program stops this function double bias_read(); // turning beck:(read() - deviant) * correction factor void tare(int t = 10); // adding tare to deviant and influencing the invoking of read() void set_co(double co = 1); // modifying correction factor(default 1) void set_offset(long offset = 0); // modifying deviant (default 1) , you can see hx711 also can use 4 parameters mode to define, and stipulate gain factor and correction factor. You can change gain and correction factor at any time during program running , and utilize deviant to remove tare. The only one needed to explain is the first function HX711 hx(9, 10); // only defining SCK and DOUT pin, the default of gain of AMP in channel A is 128 bit, the default of correction factor is 1; HX711 hx(9, 10, 64); // defining SCK and DOUT pin, the default of gain of AMP in channel A is 64 bit, the default of correction factor is 1; HX711 hx(9, 10, 32, 1.4); // defining SCK and DOUT pin, the default of gain of AMP in channel A is 32 bit, the default of correction factor is 1.4;
As for choosing channel and gain factor mentioned in materials, The gain in channel A is 128 or 64 bit, and its corresponding full-load voltage is respectively ±20mV or ±40mV. The gain in channel B is fixed 32 and full-load voltage is 80mV. Input voltage of each channel can’t be more than their full-load voltage. Of course, you can change channel and gain factor at any time, as long as you use function of set_amp(amp) during programming, but the value of amp only can be 128, 64 or 32.
Stressing again, if you choose gain factor of 32 bit, the data read out is of channel B.
The following is a specific applied sample:
Parameters of sensor shown as following:
Full-range Output Voltage=Excitation x Sensitivity 1.0mV/V
For example: 5V supply voltage multiplied by 1.0mV/V sensitivity equals to 5mV full-range.
In fact when supply voltage of the module I choose is 5V, supply voltage of sensor is 4V, so full-range voltage of my sensor is 4mV. I can choose 128 bit , the highest gain factor in channel A , to get highest precision.
In the picture , the module connected to sensor is HX711, Arduino UNO is in the lower right corner, bridge sensor is hung on lazy arm(my connection mode is to use sling to measure tension value). The shorter the wire between HX711 module and sensor the better. If it is too long, the module will get disturbed and it has better exceeding 30cm. If necessary to lengthen, you maybe can use wire that can shield electromagnetism and signal amplifier.
Firstly, use samples coming with library to test, and you can see the value after hanging on 1kg weight on a tray:
1315588.75
1315597.75
1315607.37
1315606.75
1315604.75
1315589.62
1315579.62
1315594.25
1315588.75
1315580.25
1315589.00
1315584.25
1315605.50
1315596.12
1315592.25
1315607.75
1315585.75
1315582.87
1315568.75
1315574.75
1315578.00
1315583.12
1315604.62
1315573.50
1315584.25
After a 500g weight is taken out, the value are:
742865.50
742847.87
742869.00
742879.12
742873.68
742858.81
742867.81
742843.37
742862.18
742844.87
742856.50
742834.31
742831.31
742825.12
742842.31
742821.31
742816.12
742846.00
742844.00
742826.87
742818.12
742812.87
742807.18
742835.00
Calculating roughly: 1315500 - 742800 = 572700
so the correction factor is about 500 / 572700 = 0.00087305 Then the codes are (at the moment you can decrease properly reading rate, and add “delay” , like reading value at 30 seconds at one time):
#include <HX711.h> HX711 hx(9, 10, 128, 0.00087305); void setup() { Serial.begin(9600); } void loop() { delay(500); double sum = 0; for (int i = 0; i < 10; i++) sum += hx.read(); Serial.println(sum/10); }
After compiling codes into Arduino, take out all weights, and just keep the body, you can get:
169640.70
169632.59
169632.90
169640.90
169632.79
169623.59
169649.79
169610.40
169615.20
169659.40
169619.90
169624.79
169614.79
169624.29
169617.79
169629.20
169604.00
169617.50
169628.20
169589.40
169602.29
169598.40
169596.40
169604.00
169612.40
169592.20
That means the deviant approximates to 169600. So we can invoke the function of deviant in setup(using bias_read() to read value with correction factor and deviant, compared with read() as a reference)
#include <HX711.h> HX711 hx(9, 10, 128, 0.00087305); void setup() { Serial.begin(9600); hx.set_offset(169600); } void loop() { delay(500); double sum0 = 0; double sum1 = 0; for (int i = 0; i < 10; i++) { sum0 += hx.read(); sum1 += hx.bias_read(); } Serial.print(sum0/10); Serial.print(" "); Serial.println(sum1/10); }
The data read out is changed into:
169615.20 0.01
169616.70 0.02
169613.40 0.02
169636.50 0.03
169620.70 0.02
169638.09 0.04
169625.29 0.02
169620.50 0.02
169612.29 0.01
169609.79 0.01
169624.40 0.02
169625.20 0.02
169630.00 0.03
169628.29 0.03
169606.29 0.00
169617.79 0.02
169637.90 0.03
169603.70 0.00
169605.29 0.01
169636.50 0.03
Check again the data after putting on a 500g weight:
742492.68 500.16
742499.81 500.17
742503.81 500.17
742505.18 500.18
742507.18 500.17
742499.31 500.17
742499.50 500.17
742512.37 500.18
742521.87 500.19
742497.87 500.17
742518.12 500.18
742518.81 500.18
742520.87 500.19
742520.68 500.19
742530.18 500.20
742532.87 500.20
742543.00 500.20
742540.12 500.21
742517.00 500.19
Putting on another 500g weight:
1315286.75 1000.25
1315304.62 1000.25
1315296.62 1000.25
1315302.25 1000.26
1315302.12 1000.26
1315294.25 1000.25
1315310.00 1000.26
1315277.37 1000.24
1315283.75 1000.24
1315280.25 1000.23
1315286.75 1000.24
1315293.25 1000.25
1315309.87 1000.26
1315299.50 1000.25
1315307.12 1000.26
1315304.50 1000.25
1315301.50 1000.25
1315296.75 1000.25
1315284.50 1000.23
1315284.37 1000.24
1315308.75 1000.26
1315291.62 1000.25
1315312.75 1000.26
1315312.25 1000.26
You can see the first decimal has changed for 0.2. That means reading correction factor is not precise enough, but it fits completely precision at 1g.
Next, it is to perfect program and increase removing tare function. Install a button on Arduino. In order to prevent electromagnetic interference and mistakes, we use a button usually inputting high level. When we press button, it inputs low level. Connect this button to D0 port:
#include <HX711.h> HX711 hx(9, 10, 128, 0.00087305); void setup() { Serial.begin(9600); hx.set_offset(169600); } void loop() { if(digitalRead(0) == LOW) hx.tare(); double sum0 = 0; double sum1 = 0; for (int i = 0; i < 10; i++) { sum0 += hx.read(); sum1 += hx.bias_read(); } Serial.print(sum0/10); Serial.print(" "); Serial.println(sum1/10); } Every time you press the button, tare is removed. One more code added 1602 liquid crystal #include <HX711.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> HX711 hx(9, 10, 128, 0.00127551); LiquidCrystal_I2C lcd(0x27,16,2); void setup() { Serial.begin(9600); hx.set_offset(41562); lcd.init(); // initialize the lcd lcd.backlight(); lcd.begin(16,2); } void loop() { if(digitalRead(0) == LOW) hx.tare(); double sum0 = 0; double sum1 = 0; for (int i = 0; i < 10; i++) { sum0 += hx.read(); sum1 += hx.bias_read(); } lcd.clear(); lcd.setCursor(2,0); lcd.print("keyes-scale"); lcd.setCursor(5, 1); lcd.print(sum1/10); lcd.print("g"); delay(10); }
Because of influences of different factor ,such as temperature, environment, wires and ect., actual error is about +-0.5.
Result
Put a 50g weight on tray, and the result is showed as below.