The LoadCell Project
So I just finished my first draft code for the Load cell with Arduino and decided to share it. Feel free to make any modifications on it or create your own. Also, I decided to use the LCD module instead of the MCUFriend as i didn't want a lot of functionality in it.
This is the code i used. It's pretty simple.
/*
* Chemwen0
* By Doreen Chemweno
* Load Cell HX711 Module Interface with Arduino to measure weight in Kgs
Arduino
pin
5 -> HX711 CLK
6 -> DOUT
5V -> VCC
GND -> GND
Almost any pin on the Arduino Uno will be compatible with DOUT/CLK.
The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.
*/
#include "HX711.h" //You must have this library in your arduino library folder
#include <LiquidCrystal_I2C.h>
#define DOUT 6
#define CLK 5
LiquidCrystal_I2C lcd(0x3F,18,2); //important for display to work. Set the LCD Address and the dimensions of your LCD in terms of Columns and Lines.
HX711 scale(DOUT, CLK);
//Change this calibration factor as per your load cell once it is found you many need to vary it in thousands
float calibration_factor = 102420; // 102420 worked for my 30Kg max scale setup
// global Variables
int count;
//float sum = 0.00000;
float data,sum,newData;
void stabilisingTime();
void stabilizingTime(){
// lcd.setCursor(1,2);
lcd.print("Please Wait...");
delay(1000);
lcd.clear();
// lcd.setCursor(1,2);
lcd.print("Place Item");
delay(1000);
lcd.clear();
}
void readData();
void readData(){
sum = 0.0;
for (count = 0; count<100; count++){
// Serial.print("Weight: ");
data = scale.get_units(); //Up to 3 decimal points
// Serial.println(data);
sum = sum + data;
// Serial.println(data); //Change this to kg and re-adjust the calibration factor if you follow lbs
lcd.setCursor(5,1);
lcd.print(data);
}
lcd.clear();
// Serial.print("Sum Is ");
// Serial.println(sum);
// Serial.print("count is ");
// Serial.println(count);
newData = sum / count;
// Serial.print("Averaged Data = ");
Serial.print(" ");
Serial.print(newData);
Serial.print(" kg "); //Change this to kg and re-adjust the calibration factor if you follow lbs
Serial.print("|"); //separator for the App functioning. separates data entries.
lcd.setCursor(1,0);
lcd.print("Measured value is ");
lcd.setCursor(4,1);
lcd.print(newData);
lcd.setCursor(9,1);
lcd.print(" kg ");
delay(10000);
lcd.clear();
delay(10);
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
Serial.println("Press T to tare");
stabilizingTime();
scale.set_scale(102420); //Calibration Factor obtained from first sketch
scale.tare(); //Reset the scale to 0
}
void loop() {
readData();
//===================================================
You will need some modules which you will be required to add to your library.
I will leave the links to my GitHub repositories where you will be able to get the ones that worked for me. You can also search the net for more, any that will suit your needs.
modules required:
HX711-master
LiquidCrystal_I2C
The project file:
load cell Project
Have fun.
awesome
ReplyDeleteyeah so much. hope you've tried it out.
ReplyDeleteHy, can you tell the circuit diagram for lcd.
ReplyDeleteI have another lcd that why I need circuit diagram or can you help me for these.
ReplyDeleteI used I2C module instead of making the connections directly. It's easier with the I2C module rather than using all the pins of the LCD directly.
DeleteThis is a helpful article on I2C - https://lastminuteengineers.com/i2c-lcd-arduino-tutorial/
DeleteThe LCD with I2C library has info of the two connections for the SDA and scl pins depending on the board you are using. the two other pins go to gnd and vcc