Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

January 6, 2023

Step-by-step guide on how to interface load cell using Arduino.

  • Load cells are basically used to measure the weight of an object or a body. We can find these load cells in weighing machines, industry scales and several testing machines.
  • Definition: A Load Cell is a transducer that converts force such as pressure, torque, compression, or tension into measurable electrical output.
  • Some common types of load cells are Strain Gauges, Pneumatic Load cells, Hydraulic load cells, etc.
Types of Load Cell
  • Strain gauge load cells are often found in industrial equipment. Load cells have strain gauges placed inside them. The body of these load cells is made up of aluminum, alloy steel, or stainless steel which makes it sturdy but also minimally elastic. When force is applied on one end of the load cell, the spring element present inside the load cell gets slightly deformed and changes its shape. It results in the alteration of resistance in the strain gauges which can be measured as voltage. Thus the change in voltage is proportional to the applied force which can be calculated from the load cells output. The working of the strain gauge load cell can be summarized in the below diagram.
  • A single strain gauge can detect a small change in resistance hence it is difficult to measure the accurate changes. Increasing the number of strain gauges can magnify these small changes into a more measurable quantity. A set of 4 strain gauges placed in a particular fashion in a circuit is called a Wheatstone bridge. The below figure shows a Wheatstone Bridge for 4 balanced resistors.
  • Here, Vex is the constant excitation voltage and Vo is the output voltage. R1, R2, R3, and R4 are 4 resistors placed in Wheatstone bridge formation. Here, if all resistors are balanced i.e., R1/R2=R4/R3 then the output voltage will be zero. Now even if the resistance of one resistor changes the Vo will eventually change. This change in Vo can be calculated using Ohm’s law. Output Voltage Vo can be expressed as:
Output Equation
  • In load cells, these resistors are replaced with strain gauges and are arranged in alternating tension and compression formation.
  • Now, we will see how to make a digital weighing scale using the Arduino Development board.
  • Components required:
    1] Load cell: Here we will consider a simple Beam-type load cell as shown in the below figure.
Load Cell

2] Arduino Uno Board: Arduino Uno Development board can be used for less complex operations such as weighing scale. We can select Arduino based on a number of I/O pins, input and output voltage, size, cost, etc.

Arduino UNO

3] Jumper wires: Jumper wires are used to connect different points in a circuit. They are divided into 3 types: male-female, male-male, and female-female.

Jumper Wire

4] HX711 Interface Module: The output of the load cell is in the range of millivolts, hence we need to amplify this signal into a higher level signal and then transform it into a digital signal for processing. For this purpose, we use the HX711 interface module which will amplify the low voltage output of the load cell and send it to Arduino to calculate the weight. The below figure shows the HX711 interface module.

HX711

5] USB cable: It is used to establish the connection between the computer and the Arduino board.

  • First, we will mount the load cell in a unique way between two fixed surfaces as shown in the below figure:

A load cell has 4 holes and a label that shows the direction of the force. The side without the label on it must be mounted to the fixed surface and the side with the label must be mounted to the moving surface. Place standoffs or washers between the mounting plates and load cells.

  • Connections:

Below figure shows circuit connections for interfacing load cells using Arduino:

1] Load Cell has 4 wires:
Red: E+
Black: E-
White: A-
Green: A+

2] Connect load cell to HX711 and HX711 to Arduino as shown in the above figure. Then connect the USB cable between Arduino and Computer.

3] Open Arduino Software and install HX711 libraries.
4] Calibrating the load cell is the most complex task in the complete operation. Here, I will share a simple method to calibrate the load cell which will work on every load cell and give the most precise and accurate output.
5] After downloading all the libraries, run the below code on Arduino Software:

#include “HX711.h”
#include <Wire.h>

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 4;
const int LOADCELL_SCK_PIN = 5;

HX711 scale;

void setup() {
Serial.begin(9600);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
}

void loop() {

if (scale.is_ready()) {
long reading = (scale.read())*100;
float grams = (float)(reading) / 100000 ;
Serial.print(grams);
} else {
Serial.println(“HX711 not found.”);
}
delay(1000);
}

Run the above code and open the console window from the top-right corner. Here, you will see random readings and as we place different weights on the load cell the readings will eventually change.
Now, we write the reading and applied weights in the table as shown below:

Here, I have used 5 different weights and received 5 different readings. We can increase the applied weights to get a more accurate output.
Now add these readings to an Excel sheet and plot a linear graph as shown below:

By double clicking on the line on the graph, we will get the equation of the graph which we will add to the Code. Here, the equation is:
y=461.62x-209.77

Now, make respective changes in the code as below:

#include “HX711.h”
#include <Wire.h>

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 4;
const int LOADCELL_SCK_PIN = 5;

HX711 scale;

void setup() {
Serial.begin(9600);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
}

void loop() {

if (scale.is_ready()) {
long reading = (scale.read())*100;
float grams = ((float)(461.62*reading-209.77))/100000 ;
//float grams = (float)(reading) / 100000 ;
Serial.print(grams);
} else {
Serial.println(“HX711 not found.”);
}
delay(1000);
}

Run the above code again and add weights and you will get the correct reading in the console window.

You can also connect the LCD+I2C display to get the output on the LCD.

In this way, we can interface Load Cell using Arduino.

Like, Share and Follow me if you like my content.
Thank You.

Arduino

1] ARDUINO is an open-source electronic prototyping platform that enables users to create interactive electronic projects using both hardware and software.
2] Using different ARDUINO boards we can control different input/output, activate a motor, read and write messages, turn ON/OFF LED, display on LCD, etc.
3] To do so, we can use the ARDUINO programming language and the ARDUINO IDE software.
4] These Arduino boards are made using a variety of microprocessors and controllers and contain sets of digital and analog input/output(I/O) pins that may be interfaced using external wires such as jumper wires or header pins.
5] These boards also feature some serial communication interfaces, including Universal Serial Bus(USB) which can be used for loading programs.
6] Most Arduino boards consist of Atmel 8-bit AVR microcontroller such as ATmega8, ATmega168, ATmega328, and ATmega2560 with varying amounts of flash memory, pins, and special features.

  • SOFTWARE download:

1] The open-source Arduino Software (IDE) can be used to write code and upload it to the board. This software can be used for all Arduino Boards.
2] Below link shows the link to download ARDUINO IDE software:
https://www.arduino.cc/en/software

  • HARDWARE:

1] Arduino is a PCB-mounted microcontroller that can be programmed according to the required function.
2] An Arduino development board consists of a core microcontroller and other components such as digital and analog I/O pins, different interfacing ports such as Universal Serial Bus(USB), and I/O Power ports.
3] Some of the Arduino boards are:
- Arduino UNO
- Arduino Nano
- Arduino Mega
- Arduino Robot
- Arduino ESPLORA
- Arduino Leonardo

4] Basic parts or components of Arduino boards will vary from board to board, depending on the controller used and features.
5] Here, we will be looking at Arduino UNO as an example to understand the components and parts of Arduino Development Boards.

6] In the Arduino UNO board, the ATMega328P is the main component. It is the 28Pin DIP version that allows you to upload the program to the Arduino using the USB directly. It operates on a clock signal which is provided by a 16MHz resonator.
7] The USB port on Arduino performs 2 functions:
1] For communication purpose between the computer and Arduino to load the Code.
2] To power the Arduino Board directly.
8] 2 ICSP pins are provided to code and boot the Arduino from an external source.
9] Reset pin is used to reset the ATMega328P microcontroller using a simple circuit operation.
10] Arduino UNO has a maximum input voltage of around 5V or 3.3V. It can accept 7–12V through the DC Barrel Jack or the Vin pin. Hence, to step down this voltage two regulators are present on the board. One is a 5V regulator and the other is 3.3V.
11] We can connect a 12V DC adapter or 9V DC adapter to the DC Barrel jack to power the Arduino Board.
12] Arduino UNO has 14 Digital I/O pins and 6 Analog Pins. These Analog Pins can be also used as Digital Pins.
13] Total of 4 LEDs are present on the Board each with different functionality. Two LEDs are used to show the activity of Rx and Tx, one is used to indicate power and one is simply used as an indicator to test the Arduino board.

  • Advantages of using Arduino:
    - Can be used in thousands of projects and applications from beginner level to complex projects.
    - Arduino programming language is easy to understand.
    - Arduino IDE software is easy to handle and can run on Mac, Windows, and Linux operating systems.
    - Arduino boards are relatively less expensive compared to other microcontroller-based boards.

In the upcoming blogs, I will explain how to connect different electronic components to Arduino Boards.

Like, Share and Follow me if you like my content.
Thank You.

Explore Our Topics!

Check out the extensive list of topics we discuss:  Communication Protocols: -  USB   - RS232   -  Ethernet   -  AMBA Protocol: APB, AHB and...