Help needed with code (beginner)

Hi, I am building a hx711-based weight scale that displays the measured weight on an LCD, along with the weight the LCD shows a "max weight" If weight>max weight the buzzer will buzz. I have written code to perform these functions but, it code seems to be stopping function around the 30th line. ANy help is appreciated! I will include the schematic and code below

Imgur

#include "HX711.h"

#include <Wire.h>

#include <LiquidCrystal_I2C.h>



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

}


Is that the 30th line of actual code, or line 30 of the source with all the blank lines?

There's no need to test the inverse of that condition in the else clause.

Are we not seeing some of your code?

Does this project not seem familiar?
https://forum.arduino.cc/t/help-needed-for-project-due-6-3/992517/37

The Arduino has no ground connection.

Also maybe not a good idea to post your real name and phone number.

well I have the libraries hx711.h and hx711.cpp

#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 2
#define HX711_DT 3

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

#endif

That's lucky. It would have been a tough job for you to write the library code.

yeah indeed, any insight on the code issues?

Can you indicate which line you think the code is failing on, and how you determined this, please?

1 Like

around there, nothing else is displaying on the LCD or on anything else

But how do you know it is "there"? So, it prints, "Ready!" and then freezes? Does anything get printed to the LCD before that?

Is this a different program/project from your previous lengthy thread?

no there isnt, i dont for sure that's where the issue lies, I thought I coded it to display the name at the beginning but that isn't working

So, the LCD doesn't work at all? Have you tested it separately?

i have, its kind weird though, it turns on and doesn't display anything no matter what it says its undetected even though its plugged the the correct places

Even with an LCD library example sketch?

ill try that now !

no im not i swear im sorry if it came across that way sir

this code served its intended purpose

//...............JehanKandy........................
//...........www.jehankandy.com....................
//........www.github.com/JehanKandy................

//include liquidCrystal_I2C.h 
//Tools -> Manage Libraries and type liquidCrystal_I2C

#include <LiquidCrystal_I2C.h>

//define I2C address......
LiquidCrystal_I2C lcd(0x27,16,2);


void setup() {
  lcd.init();
  lcd.clear();
  lcd.backlight();

  lcd.setCursor(2,0);
  lcd.print("Hello World");

  lcd.setCursor(2,1);
  lcd.print("JehanKandy");

}

void loop() {


}
//.........coded by : JehanKandy....
//...........Thank You..............

What have you done to find the problem?

I ran a code and figured out the LCD itself works, I have this LCD

I'm gonna try out a new library

alright just fixed it, thanks for the help:)

tips how to improve your posting style