i’m having trouble coding my project and nothing has worked , i want to make a load cell based scale which display the weight on an lcd , of the weight goes above a set threshold a buzzer will buzz until that weight is no longer detected . there are also two tactile switches to adjust the threshold manually. here is the schematic , need help with the code
Post the code, using code tags, and describe the problem you are having with it.
What have you done?
Read the forum guidelines to see how to properly post code and some information on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
What do you need help with?
Why the urgency?
Is this homework?
If I google "load cell based scale which display the weight on an lcd arduino" I get like 1.2 million hits. Have a look at what others have done.
Hi,
looks like a school project to me.....
No you need to break your project into logical steps. The first is to write a program to be able to read the two switches and report the changing status on the serial monitor.
Second, you need to get your buzzer working and be able to control it with a program you write.
Third, you need to get your LCD operating and understand how to clear it, how to position the cursor and how to write text and how to write numeric values to it.
Fourth, you need to write a program to exercise the load cell and report all output on the serial monitor.
FINALLY, now you can intelligently write a program to do all tht your project is supposed to be doing, using all you have learned from the four steps.
That is how you do a project with devices that are new to you.
Good luck and let us know if you get stuck.
1. Check that your hardware setup (wiring connection) agrees with Fig-1. (Your diagram of post #1 is not readable at all!)
Figure-1:
2. Now, write a sketch so that when you press switch-B1 the following message appears on the Topline of the LCD starting at cursor position 2. The same message will also appear on the OutputBox of the Serial Monitor.
B1 is pressed
3. Now, tell us what function (s) you want to add/remove with/from the sketch of Step-2. For example:
(1) 10-sec average counts (C1) from Load Cell when you place 2 kg weight (W1) on Load Cell.
(2) 10-sec average counts (C2) from Load Cell when you place 5 kg weight (W2) on Load Cell.
(3) From the readings of Step-3(1) and 3(2), find the gain (m) and offset (k) of the input system (Load Cell + HX711). Use m and k to calculate the unknown weight (W) placed on the Load Cell using the following formula for W:
Given: A(W1, C1); B(W2, C2); P(W, C) //W1, W2, C1, and C2 are known parameters
==> (W1-W2)/(C1-C2) = (W2-W)/(C2-C)
W = mC + k //where: C = 10-sec average count for unknown weight W
4. Place 2.5 kg weight on the Load Cell. Show the value of W on Serial Monitor and LCD with 3-digit after the decimal point. Consult technical specifications of the Load cell and find that the error tolerance (+/- n gm) agrees with the displayed weight; otherwise, use swicth-B1 (to increase) or swicth-B2 (to decrease) to adjust the weight.
float W = mC + k;
Serial.println(W, 3);
lcd.print(W, 3);
I wrote this code #include "HX711.h"
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal_h lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int IN1 = A0;
int IN2 = A1;
int over_val;
int data;
int g_weight;
int Weight;
const int buzzer = 13;
void setup()
{
pinMode(buzzer, OUTPUT);
pinMode(IN1, INPUT);
pinMode(IN2, INPUT);
Init_Hx711();
Serial.begin(9600);
Serial.print("Ready!\n");
Get_Maopi();
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" MUHAMMAD ANSAR ");
lcd.setCursor(0,1);
lcd.print(" 0337-8655465 ");
delay(1000);
lcd.clear();
}
void loop()
{
Weight = Get_Weight();
g_weight = Weight-data;
lcd.setCursor(0,0);
lcd.print("Weight:");
lcd.print(g_weight);
lcd.print("g ");
if (digitalRead(IN2) == LOW){data=Weight;}
if (digitalRead(IN1) == LOW){over_val=g_weight;}
if (g_weight<=over_val)
{
lcd.setCursor ( 0, 1 );
lcd.print("Max Weight:");
lcd.print(over_val);
lcd.print("g ");
digitalWrite(buzzer,LOW);
}
else if (g_weight>over_val)
{
Serial.println("overload");
lcd.setCursor ( 0, 1 );
lcd.print("...OverLoad!!...");
digitalWrite(buzzer,HIGH);
}
delay(50);
}
Hello chwaxy
Post your current sketch, well formated, with comments and in so called code tags "</>" and a schematic, not a Fritzy diagram, to see how we can help.
Have a nice day and enjoy coding in C++.
Дайте миру шанс
#include "HX711.h"
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal_h lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int IN1 = A0;
int IN2 = A1;
int over_val;
int data;
int g_weight;
int Weight;
const int buzzer = 13;
void setup()
{
pinMode(buzzer, OUTPUT);
pinMode(IN1, INPUT);
pinMode(IN2, INPUT);
Init_Hx711();
Serial.begin(9600);
Serial.print("Ready!\n");
Get_Maopi();
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" MUHAMMAD ANSAR ");
lcd.setCursor(0,1);
lcd.print(" 0337-8655465 ");
delay(1000);
lcd.clear();
}
void loop()
{
Weight = Get_Weight();
g_weight = Weight-data;
lcd.setCursor(0,0);
lcd.print("Weight:");
lcd.print(g_weight);
lcd.print("g ");
if (digitalRead(IN2) == LOW){data=Weight;}
if (digitalRead(IN1) == LOW){over_val=g_weight;}
if (g_weight<=over_val)
{
lcd.setCursor ( 0, 1 );
lcd.print("Max Weight:");
lcd.print(over_val);
lcd.print("g ");
digitalWrite(buzzer,LOW);
}
else if (g_weight>over_val)
{
Serial.println("overload");
lcd.setCursor ( 0, 1 );
lcd.print("...OverLoad!!...");
digitalWrite(buzzer,HIGH);
}
delay(50);
}
how do I read the diagram
See post #6.
#include "HX711.h"
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal_h lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int IN1 = A0;
int IN2 = A1;
int over_val;
int data;
int g_weight;
int Weight;
const int buzzer = 13;
void setup()
{
pinMode(buzzer, OUTPUT);
pinMode(IN1, INPUT);
pinMode(IN2, INPUT);
Init_Hx711();
Serial.begin(9600);
Serial.print("Ready!\n");
Get_Maopi();
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" MUHAMMAD ANSAR ");
lcd.setCursor(0,1);
lcd.print(" 0337-8655465 ");
delay(1000);
lcd.clear();
}
void loop()
{
Weight = Get_Weight();
g_weight = Weight-data;
lcd.setCursor(0,0);
lcd.print("Weight:");
lcd.print(g_weight);
lcd.print("g ");
if (digitalRead(IN2) == LOW){data=Weight;}
if (digitalRead(IN1) == LOW){over_val=g_weight;}
if (g_weight<=over_val)
{
lcd.setCursor ( 0, 1 );
lcd.print("Max Weight:");
lcd.print(over_val);
lcd.print("g ");
digitalWrite(buzzer,LOW);
}
else if (g_weight>over_val)
{
Serial.println("overload");
lcd.setCursor ( 0, 1 );
lcd.print("...OverLoad!!...");
digitalWrite(buzzer,HIGH);
}
delay(50);
}
#include "HX711.h"
#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal_h lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int IN1 = A0;
int IN2 = A1;
int over_val;
int data;
int g_weight;
int Weight;
const int buzzer = 13;
void setup()
{
pinMode(buzzer, OUTPUT);
pinMode(IN1, INPUT);
pinMode(IN2, INPUT);
Init_Hx711();
Serial.begin(9600);
Serial.print("Ready!\n");
Get_Maopi();
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" MUHAMMAD ANSAR ");
lcd.setCursor(0,1);
lcd.print(" 0337-8655465 ");
delay(1000);
lcd.clear();
}
void loop()
{
Weight = Get_Weight();
g_weight = Weight-data;
lcd.setCursor(0,0);
lcd.print("Weight:");
lcd.print(g_weight);
lcd.print("g ");
if (digitalRead(IN2) == LOW){data=Weight;}
if (digitalRead(IN1) == LOW){over_val=g_weight;}
if (g_weight<=over_val)
{
lcd.setCursor ( 0, 1 );
lcd.print("Max Weight:");
lcd.print(over_val);
lcd.print("g ");
digitalWrite(buzzer,LOW);
}
else if (g_weight>over_val)
{
Serial.println("overload");
lcd.setCursor ( 0, 1 );
lcd.print("...OverLoad!!...");
digitalWrite(buzzer,HIGH);
}
delay(50);
}
1. Do you have a load Cell? If yes, then mount it on the bench as per Fig-1.
Figure-1:
2. Do you have a HX711-type amplifier? If yes, then connect it with the load cell and UNO as follows:
(1) E+ point of the amplifier with E+ wire of the load cell.
(2) E- point of the amplifier with E- wire of the load cell.
(3) GND-pin of the amplifier with shield wire of the load cell.
(4) A+ pin of the amplifier with sig+ wire of the load cell.
(5) A- pin of the amplifier with sig- wire of the load cell.
//-------------------------------------------------------------------------------------------
(6) VDD-point of the amplifier with 5V-pin of UNO.
(7) GND-point of the amplifier with GND-pin of UNO.
(8) DT-point (Data Line) of the amplifier with A1-pin of UNO.
(9) CLK-point of the amplifier with A0-pin of UNO.
There is no need to connect LCD at the moment.
i did that, whats next
Take a picture of your setup and post it here to get the next help.
Thank you!
Please, show me the Load Cell that you have mounted on the wooden bench using screws as per Fig-1 of post #17. This is a cantilever-type load cell that you have shown in post #1.
use different colors for the wiring.
This is the kind of hurrying that leads into accidential errors
that will cost you more extra time to analyse them than you need to search
carefully for different wirecolors
Vcc-wires: red or orange
GND-wires: black or blue
Data line / Clk different colors for easy distinguishing which is what