Whats wrong with this code?

pls help
#include <LiquidCrystal.h>
#include "HX711.h"
#include <Wire.h>

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();

void loop()

if (digitalRead(IN2) == LOW) {data = Weight;}
if (digitalRead(IN1) == LOW) {over_val = g_weight;}

if (g_weight <= over_val)
{

else if (g_weight > over_val)
{
Serial.println("overload");

digitalWrite(buzzer, HIGH);

}

delay(50);
}

#include "hx711.h"

long HX711_Buffer = 0;
long Weight_Maopi = 0,Weight_Shiwu = 0;

//****************************************************
//初始化HX711
//****************************************************
void Init_Hx711()
{
pinMode(HX711_SCK, OUTPUT);
pinMode(HX711_DT, INPUT);
}

//****************************************************
//获取毛皮重量
//****************************************************
void Get_Maopi()
{
HX711_Buffer = HX711_Read();
Weight_Maopi = HX711_Buffer/100;
}

//****************************************************
//称重
//****************************************************
unsigned int Get_Weight()
{
HX711_Buffer = HX711_Read();
HX711_Buffer = HX711_Buffer/100;

Weight_Shiwu = HX711_Buffer;
Weight_Shiwu = Weight_Shiwu - Weight_Maopi;				//获取实物的AD采样数值。

Weight_Shiwu = (unsigned int)((float)Weight_Shiwu/4.11); 	
	//计算实物的实际重量
	//因为不同的传感器特性曲线不一样,因此,每一个传感器需要矫正这里的4.30这个除数。
	//当发现测试出来的重量偏大时,增加该数值。
	//如果测试出来的重量偏小时,减小改数值。
	//该数值一般在7.16左右。因传感器不同而定。
	//+0.05是为了四舍五入百分位

return Weight_Shiwu;

}

//****************************************************
//读取HX711
//****************************************************
unsigned long HX711_Read(void) //增益128
{
unsigned long count;
unsigned char i;
bool Flag = 0;

digitalWrite(HX711_DT, HIGH);
delayMicroseconds(1);

digitalWrite(HX711_SCK, LOW);
delayMicroseconds(1);

count=0; 
while(digitalRead(HX711_DT)); 
for(i=0;i<24;i++)
{ 
  	digitalWrite(HX711_SCK, HIGH); 
	delayMicroseconds(1);
  	count=count<<1; 
	digitalWrite(HX711_SCK, LOW); 
	delayMicroseconds(1);
  	if(digitalRead(HX711_DT))
		count++; 
} 
digitalWrite(HX711_SCK, HIGH); 
count ^= 0x800000;
delayMicroseconds(1);
digitalWrite(HX711_SCK, LOW); 
delayMicroseconds(1);

return(count);

}

#ifndef HX711__H
#define HX711__H

#include <Arduino.h>

#define HX711_SCK 8
#define HX711_DT 7

extern void Init_Hx711();
extern unsigned long HX711_Read(void);
extern unsigned int Get_Weight();
extern void Get_Maopi();

#endif

it's not using code tags ? :grimacing: :thinking:
(it's missing { or } in many places)


Hello, do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

It's not in code tags.

Just for starters, use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

You will see that the setup() function is not closed with a }. The loop() function is closed early, leaving the rest of the code outside of any function. The loop() function is not closed so the Init_Hx711() function definition is inside of loop() which is not legal.

Also, you include the LiquidCrystal library but do not create an instance of an LCD.

That is as far as I got. You have some work to do fixing your curly brackets, at least . The autoformat tool will be a big help with that.

Tell us why you think something is wrong with it.

Where do you think the setup() function ends?

You include "HX711.h" at the top of the file and "hx711.h" in the middle of the file. At the bottom of the file you seem to have inserted the contents of "HX711.h".

Here is a version that compiles without error or warning. I don't know if it will do what you want.

#include <LiquidCrystal.h>
#include <Wire.h>

int IN1 = A0;
int IN2 = A1;
#define HX711_SCK 8
#define HX711_DT 7
const int buzzer = 13;

int over_val;
int data;
int g_weight;
int Weight;

void setup()
{
  pinMode(buzzer, OUTPUT);

  pinMode(IN1, INPUT);
  pinMode(IN2, INPUT);
  Init_Hx711();
  Serial.begin(9600);
  Serial.print("Ready!\n");
  Get_Maopi();
}

void loop()
{
  if (digitalRead(IN2) == LOW)
  {
    data = Weight;
  }

  if (digitalRead(IN1) == LOW)
  {
    over_val = g_weight;
  }

  if (g_weight > over_val)
  {
    Serial.println("overload");
    digitalWrite(buzzer, HIGH);
  }

  delay(50);
}


long HX711_Buffer = 0;
long Weight_Maopi = 0, Weight_Shiwu = 0;

//****************************************************
//初始化HX711
//****************************************************
void Init_Hx711()
{
  pinMode(HX711_SCK, OUTPUT);
  pinMode(HX711_DT, INPUT);
}

//****************************************************
//获取毛皮重量
//****************************************************
void Get_Maopi()
{
  HX711_Buffer = HX711_Read();
  Weight_Maopi = HX711_Buffer / 100;
}

//****************************************************
//称重
//****************************************************
unsigned int Get_Weight()
{
  HX711_Buffer = HX711_Read();
  HX711_Buffer = HX711_Buffer / 100;

  Weight_Shiwu = HX711_Buffer;
  Weight_Shiwu = Weight_Shiwu - Weight_Maopi;        //获取实物的AD采样数值。

  Weight_Shiwu = (unsigned int)((float)Weight_Shiwu / 4.11);
  //计算实物的实际重量
  //因为不同的传感器特性曲线不一样,因此,每一个传感器需要矫正这里的4.30这个除数。
  //当发现测试出来的重量偏大时,增加该数值。
  //如果测试出来的重量偏小时,减小改数值。
  //该数值一般在7.16左右。因传感器不同而定。
  //+0.05是为了四舍五入百分位

  return Weight_Shiwu;
}

//****************************************************
//读取HX711
//****************************************************
unsigned long HX711_Read(void) //增益128
{
  unsigned long count;
  unsigned char i;
  // bool Flag = 0;

  digitalWrite(HX711_DT, HIGH);
  delayMicroseconds(1);

  digitalWrite(HX711_SCK, LOW);
  delayMicroseconds(1);

  count = 0;
  while (digitalRead(HX711_DT));
  for (i = 0; i < 24; i++)
  {
    digitalWrite(HX711_SCK, HIGH);
    delayMicroseconds(1);
    count = count << 1;
    digitalWrite(HX711_SCK, LOW);
    delayMicroseconds(1);
    if (digitalRead(HX711_DT))
      count++;
  }
  digitalWrite(HX711_SCK, HIGH);
  count ^= 0x800000;
  delayMicroseconds(1);
  digitalWrite(HX711_SCK, LOW);
  delayMicroseconds(1);

  return (count);
}

I want it to buzz when it exceeds a certain weight and showing the weight on the LCD screen


chwaxy

1dpost #8

I want it to buzz when it exceeds a certain weight and showing the weight on the LCD screen

I would put some code in loop() to read the weight and print that weight to the LCD.

how?

For reading weight, I would find an HX711 library and start with the provided examples.

For displaying to an LCD, I would look at the examples provided with the Liquid Crytal library.

can you add that to the code you wrote? I cant find it

can you check my most recent post? did your corrections