Thứ Năm, 5 tháng 3, 2020

Load Cell and a Microcontroller

In this project, we're making a weighing scale using a C8051 microcontroller development kit, a load cell, and the Simplicity Studio IDE. The measured weight will be displayed on an LCD screen

In this project, we'll build a weighing scale using a C8051 microcontroller development kit, a load cell, and the Simplicity Studio IDE. The measured weight will be displayed on an LCD screen.

LCD Display

The LCD used in the project is part of the Silicon Labs CP2400DK development kit.

Figure 1. Silicon Labs CP2400DK development kit (C8051 microcontroller and LCD controller). Image courtesy of Digi-Key.

The manufacturer part number of the LCD device itself (figure 2) is VIM-878-DP-RC-S-LV. If you include the decimal point and the apostrophe (for each digit), this "14-segment" LCD display becomes a 16-segment display. And when summing all the 16-segments of the eight digits together, we see a total of 128 segments. Such a 128-segment display mandates the use of a 128-segment driver, and Silicon Labs has decided to use driver p/n CP2400 (Figure 3).

Figure 2. LCD screen with 16 segments for each of the eight digits (total of 128 segments). Image courtesy of Digi-Key.

Figure 3. 128-segment LCD driver. Images courtesy of Silicon Labs (pages 1 and 22).

Load Cell

The load cell that I chose to use is made by Uxcell, model # a14071900ux0057.

Figure 4. Load cell. Image courtesy of Amazon.

This particular load cell is commonly referred to as a straight bar load cell or a parallel beam load cell. Such load cells are typically available in many rated loads (i.e., maximum loads); the one utilized in this project is rated for a maximum weight of 10kg (or 22 pounds). Its advertised rated output is 1±0.15mV/V. This means that when the load cell has its maximum rated weight applied (10kg in this case), then the output voltage will be 1mV (±0.15mV) per every 1V applied to the load cell's excitation (see figure below). And when I say the voltage is "applied to the load cell", the voltage is actually being applied to the Wheatstone bridge strain gauge's excitation leads. Similarly, it's the Wheatstone strain gauge the produces the output voltage (see figure below).

Figure 5. The load cell's Wheatstone bridge strain gauge schematic.

For this project I'll be applying 5.0VDC as the excitation; therefore, when a 10kg load is applied to the load cell, its VOUT will be 5.0mV (±0.75mV). And because 5.0mV is such a small voltage, it will need to be amplified prior to being sent to the microcontroller.
Side note: Some microcontrollers—not the one used in this project—have differential ADC inputs; single-ended inputs are considered standard for most microcontrollers. When using a microcontroller with a single-ended ADC input and when the sensor in question provides a differential output signal, a differential amplifier must be utilized. This type of amplifier converts a differential signal into a single-ended signal that can be measured using a standard single-ended ADC.

Instrumentation Amplifier

The differential amplifier that I chose to use is actually called an instrumentation amplifier, or in-amp. I began this project using the INA126PA in-amp from Texas Instruments—I purchased this device from Digi-Key for $3.15. However, when it failed to perform as advertised and after troubleshooting it for about an hour, I decided to move to Plan B: use the AD627 (from Analog Devices), which I had also purchased. I bought this part—quantity one—from Digi-Key for a whopping price of $8.45! I had no idea that these in-amps cost so much money! Fortunately, this device worked flawlessly. Hence, I think I'll be using in-amp devices from Analog Devices in the future as opposed to TI parts, although generally speaking, I'm a fan of parts, and prices, from TI. Setting the gain for both of these in-amps is simple: all that’s required is one external resistor. Also, both the TI and the Analog Devices part are advertised as single- or dual-supply devices, and I much prefer to use a single-supply.

Figure 6. Analog Devices instrumentation amplifier (AD627) simplified schematic. Image courtesy of Analog Devices (page 14).

Item #Description / SourceCost (each)Other Information
1 C2400DK development kit$148.75
 User Guide
 Quick-Start Guide
 C8051F930 datasheet
 Note: schematics are on pages 25-31 of the
 User Guide.
2 Breadboard$8.98 or equivalent
3 Jumper wire kit$6.20 or equivalent
4 10kg load cell$8.14 or equivalent
5 Instrumentation amplifier$8.45 Datasheet
6 1 kΩ potentiometer$2.41 Datasheet
7 Machine Screws (M4-0.7 x 25mm).
 Qty 2
$0.76 or equivalent
8 Machine Screws (M5-0.8 x 25mm).
 Qty 2
$0.76 or equivalent

Making the Connections / Schematic

The microcontroller uses the SPI interface (SPI channel 1) for communicating to the LCD driver—figure 7 below shows Simplicity Studio's hardware configuration GUI for how the C8051's SPI is configured.
 
Figure 7. SPI interface configuration

Choosing the Gain for the Instrumentation Amplifier

As mentioned before, the excitation voltage applied to the load cell is 5.0VDC, which will produce an output voltage of 5mV (at full load of 22 lbs). Though the microcontroller's ADC has an input range of 0 to 3.30VDC, I want 3.00VDC to correspond to the full load (22 lbs). This will provide some headroom for the load cell's overload, which is 120% of full load, or 26 lbs. Given these conditions, I can calculate the necessary gain for the in-amp, and then choose the appropriate value of the gain resistor (RG).
5mVGain=3000mV
Gain=3000mV5mV=600
RG equation (per AN627 datasheet page 22):
RG=200kΩGain5
RG=336Ω

Figure 8. Connection diagram. It's important that the decoupling capacitor (C1) be placed as close to the AD627's power pin as possible. Click to enlarge.

Configuring the Microcontroller Development Kit

Prior to powering up the microcontroller development kit, after all the connections have been made, be sure to configure it as follows:
Jumpers:
  • J11: VBAT to WALL_PWR
  • J12: VDD to VIO
  • J17: VBAT_PIN to VBAT
Switches:
  • SW4: set to "2 CELL"
  • Power switch (SW5) to "OFF" position
Cables:
  • Connect the ribbon cable debug adapter to J9
  • Connect the USB debug adapter to your PC.
  • Apply 5.0VDC to connector P2.

Attaching the Load Cell Base Plates

The load cell itself has holes with, to my surprise, screw threads. This makes it very handy when attaching the load cell to base plates. Again, to my surprise, one set of holes is larger than the other. Hmmm, I'm not sure why the manufacturer did this but, nonetheless, I was able to find the appropriate screws at the local hardware store.
  • Quantity two: machine screws, M4-0.7 x 25mm
  • Quantity two: machine screws, M5-0.8 x 25mm
  • Note: the length of these four screws (25mm) is dependent upon the thickness of the spacers and of the base plates themselves.

Figure 9. Load cell mounted to base plates. Click to enlarge.
 

Figure 10. The completed load cell system (sans 5VDC power supply). Click to enlarge.

The Firmware

Similar to another project of mine (Adding an LCD and Keypad to a Tachometer and Speedometer), for this project I heavily leveraged Silicon Lab's example LCD project (CP240x_LCD_Example), which made my firmware-writing task much easier.
The output of the in-amp is connected to port 0.6, which is the input to the microcontroller's ADC. Below is a list of features/goodies that I've incorporated into the firmware:
  • The firmware takes and averages 200 samples of the measured voltage prior to sending the data to the LCD screen.
  • If the applied load is greater than or equal to 23 lbs, the LCD will display "OVERLOAD."
  • When the system is first energized, the firmware will display the tare weight (i.e., the weight at startup becomes the zero weight).
  • The LCD is configured to display one digit following the decimal point.
   //----------------------------------
   // Main Application Loop
   //----------------------------------
   while (1)
   {

         //-----------------------------------------------------------------------
         // Measure Analog Value
         //-----------------------------------------------------------------------
         //
         // Take ADC conversion.
         //

         // Initiate a Conversion
         AD0INT = 0;                         // clear ADC0 conv. complete flag
         AD0WINT = 0;                        // clear window detector flag
         AD0BUSY = 1;                        // initiate conversion

         // Wait for conversion to complete
         while(!AD0INT);


         //                           Vref (mV)
         //   measurement (mV) =   --------------- * result (bits)
         //                       (2^10)-1 (bits)

         mV =  ADC0;
         mV *= VREF;
         mV /= 1023;
         lbs = (float) (mV * 22.0 / 300.0); // The multiplying factor is actually 22lbs/3000mV, but 300
         // is used for displaying one digit after the decimal point.
         if(zero_scale == 0)      // Used for zeroing the scale during power-up.
         {
          zero_offset = lbs;
          zero_scale = 1;
         }
         lbs = (lbs - zero_offset);
         AverageAccumulator += lbs;     // Add the current lbs measurement to the accumulator.
         AverageMeasurements--;      // Decrement the measurement counter.
         if(AverageMeasurements == 0)
         {
   // Calculate the average value: divide the summed AverageAccumulator by the
   // number of measurements.
   lbsAverage = (AverageAccumulator / 200.0);


   AverageAccumulator = 0;    // Reset
   AverageMeasurements = 200; // Reset
   if(lbsAverage >= 230)    // If the measured weight is greater than equal to
         // 23.0 lbs, then display "OVERLOAD" on the LCD screen.
         // The load cell is rated at 10kg (or 22 lbs), with
         // safe overload of 120%, or 12kg (26 lbs).
   {
    sprintf(display_string, "OVERLOAD");
   }
   else sprintf(display_string, "d lbs ", (unsigned int) lbsAverage);
         }

         //-----------------------------------------------------------------------
         // Update LCD
         //-----------------------------------------------------------------------
         //
         // Update the LCD Display
         //
         LCD_OutString(display_string);
   }
All the code for this project can be downloaded from the link below.

Building and Loading the Code, and Verifying the Accuracy of the Scale

After downloading, building, and loading the code, I used my kitchen scale as a reference/comparison for taking weight measurements. As seen in the video (below), I place various weight samples (my old textbooks from college!) first on the kitchen scale and then on the load cell system. And as you can observe, both scales are extremely close in their displayed measurements.

Next Steps for Making a Real Product

If you, or I, decide to make an actual weight-measuring system based on this project using a customized PCB design, be sure to follow the grounding and layout recommendations as described in the datasheet (page 20). Also, replacing the wooden base plates with metal plates would increase the stability and robustness of the physical design.

Build Your Own Digital Weighing Machine

This article describes how to build a simple and low-cost digital kitchen weighing machine, which can measure weight of up to five kilograms. This digital weighing machine is easier to design. For a heavy-duty weighing machine like your bathroom scale, just change the load cell or strain gauge. Everything else remains the same.

Circuit and working

Circuit diagram of the weighing machine is shown in Fig. 2. It is built around 5V voltage regulator 7805 (IC1), analogue amplifier HX711 (IC2), ATmega328 microcontroller (IC3), load cell (strain gauge) for up to 5kg and a few discrete components. The author’s prototype is shown in Fig. 1.
Author’s prototype
Fig. 1: Author’s prototype
Circuit diagram of weighing machine
Fig. 2: Circuit diagram of weighing machine
HX711 is used here because it gives a digital output, is low-cost and has an Adafruit header file for Arduino, which makes it easy to use. HX711 has input channel A (A+ and A-) and channel B (B+ and B-). Here, channel B is left unused. If you want to add one more load cell to take average, you can connect it to channels B- and B+. HX711, along with male bergstrip connectors, as shown in Fig. 3.
Analogue amplifier HX711
Fig. 3: Analogue amplifier HX711
Load cell. Details of the load cell are shown in Fig. 4. The weighing scale has a metallic structure surrounded by strain-relieving frames, which pick up the strain when subjected to weight. Strain gauges are arranged in Wheatstone bridge configuration. Voltage is applied on one side, while the other side measures the change in voltage depending on the strain it suffers.
Load cell
Fig. 4: Load cell
Load or weight is applied at the free end. Strain gauges are applied on all three sides to pick up compressions and expansions. These are nothing but load signals that are processed and measured for weight measurements. Output is clubbed into four wires. Functions of the colour codes of the four wires are given in the table.
A yellow wire, if present, is the shield wire that must be connected to ground.

Software

The software consists of Arduino sketch (my_load_cell.ino), HX711 header files and other related libraries. First, add the library files (floatToString, HX711 and writeAnything) to Arduino IDE library and then run the sketch. To calibrate the probe, press the push button once. To reduce the number of readings for averaging, change the following script:
x=scale.get_units(25)×45.3592 ; //convert to gram for 25 readings
scale.read_average(5); //to read 5 average
The first line takes 25 readings and averages it five times using the second line of code. To increase the speed of reading, reduce the number of averages. If input is blank, it will not take any average.
Software is built on Arduino onboard principle. After uploading the code into ATmega328 using Arduino Uno, take ATmega328 IC out and put into the PCB board.
Initial readings may have errors, as the system is not yet calibrated. Press push button S1 connected to pin 16 (PB2) of IC3 once and the system will self-calibrate. Initial reading of 0.0 will be shown on LCD1. The zero_set figure will then be stashed into the inbuilt EEPROM of Arduino.
Next time when you restart it after switch off operation, zero_set reading will be read from the EEPROM and internal calibration will be adjusted accordingly. It will be shown on the top line of LCD1. The second line will show 0.0.
If the readings reduce with increase in load, reverse the white and green wires, and the problem will be solved.

Download source file

Construction and testing of Digital Weighing Machine

An actual-size PCB layout for the weighing machine is shown in Fig. 5 and its components layout in Fig. 6. After assembling the circuit, enclose it in a suitable box. Attach one end of the load cell in a fixed frame. The other end should be used for placing the load or object for weight measurement.
Fig. 5: PCB layout of the weighing machine circuit
Component Layout of the PCB design
Fig. 6 Component Layout of the PCB design

Download PCB and component layout PDF: click here

Calibration

Calibration is an important part of measuring devices. For HX711 there is one calibration factor 7050 that works well for Adafruit modules. Therefore it has not been changed. The other is zero_set factor for which provision should be made to do it dynamically during operations. After each calibration, zero_set figure goes into EEPROM memory of Arduino. Next time when you restart the circuit, this value will be fetched from EEPROM and zero_set achieved.
However, to change zero-set reading, like for weighing milk (in a container), you would not be interested in measuring the container weight and then deducting it. So, put the container on the scale and press S1. Container weight will be added to zero_set reading and a new zero reading will be shown. Now, pour milk in the container and read the weight. To remove the container weight from zero_set reading, remove the container and press S1 again.

Multiplying factor

Change this factor suitably by putting a known weight on the load tray the first time. Once this is done, your machine will work fine. This is explained in the source code very clearly.

Fitting of the scale

If you look at the load cell, it has strain gauge attached on all three sides with suitable strain-relieving frames inbuilt in the design. Attach a suitable tray on the load end of the load cell for holding the object for weight measurement. Put a thick washer between the base plate of the tray and the load cell, and tighten firmly. Your weighing machine is ready for use.



MỚI NHẤT

Cân sàn điện tử - cân trang trại 1 tấn - 3 tấn

 Tải trọng MAX : 500kg/1 tấn/ 2 tấn/3 tấn Kích thước tiêu chuẩn : 0.8mx1m2 / 1m2x1m5 /1m2x2m//1m5x2m. Các kích thước khác khách hàng có thể ...

XEM NHIỀU NHẤT