Hi,
On last attempt, i made a huge mistake with my Arduino UNO, 1KG load cell and, HX7111 Amplifier where my soldering quality was really-really bad.
But now the build (Weight sensor) is working after major revamps and tweaks, so here's my question:
-
My sensor will refresh every 300miliseconds in the loop and I can see the measurement seems to be flactuating (in minute amount) Eg: 160.1g and sometime 160.3g (probably because of wind interference from ceiling fan?) . So how can I check within the loop, if the weight is consistent after 5 readings (300milisecs) then the system will play a buzzer?
-
I already bought a wifi module and my goal is to once the buzzer goes on, the code will then get the value and send it to a PHP file and Database. I plan on creating a dashboard using PHP where all stored weight can be seen there in my index.php file. Is there any good tutorial you can recommend?
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/arduino-load-cell-hx711/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
// Calibrating the load cell
#include "HX711.h"
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 4;
const int LOADCELL_SCK_PIN = 5;
HX711 scale;
void setup() {
Serial.begin(57600);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
}
void loop() {
if (scale.is_ready()) {
scale.set_scale();
Serial.println("Tare... remove any weights from the scale.");
delay(5000);
scale.tare();
Serial.println("Tare done...");
Serial.print("Place a known weight on the scale...");
delay(5000);
long reading = scale.get_units(10);
Serial.print("Result: ");
Serial.println(reading);
}
else {
Serial.println("HX711 not found.");
}
delay(1000);
}
//calibration factor will be the (reading)/(known weight)
*/
#include <Arduino.h>
#include "HX711.h"
#include <LiquidCrystal_I2C.h>
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 4;
const int LOADCELL_SCK_PIN = 5;
LiquidCrystal_I2C lcd(0x27, 16, 2);
HX711 scale;
void setup() {
Serial.begin(57600);
Serial.println("HX711 Demo");
Serial.println("Initializing the scale");
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
Serial.println("Before setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC
Serial.print("read average: \t\t");
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
Serial.print("get value: \t\t");
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)
Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided
// by the SCALE parameter (not set yet)
scale.set_scale(895.640);
//scale.set_scale(-471.497); // this value is obtained by calibrating the scale with known weights; see the README for details
scale.tare(); // reset the scale to 0
Serial.println("After setting up the scale:");
Serial.print("read: \t\t");
Serial.println(scale.read()); // print a raw reading from the ADC
Serial.print("read average: \t\t");
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
Serial.print("get value: \t\t");
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare()
Serial.print("get units: \t\t");
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided
// by the SCALE parameter set with set_scale
Serial.println("Readings:");
lcd.begin();
//lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Welcome");
lcd.setCursor(0, 1);
lcd.print("3");
delay(1000);
lcd.setCursor(0, 0);
lcd.print("Welcome.");
lcd.setCursor(0, 1);
lcd.print("2");
delay(1000);
lcd.setCursor(0, 0);
lcd.print("Welcome..");
lcd.setCursor(0, 1);
lcd.print("1");
delay(1000);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Suu Balm");
lcd.setCursor(0, 1);
lcd.print("Smart Sensor");
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Ready: Please");
lcd.setCursor(0, 1);
lcd.print("remove bottle");
delay(5000);
}
void loop() {
float i = scale.get_units();
if (i < 1)
{
i = 0.00;
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SB Smart Sensor");
lcd.setCursor(0, 1);
lcd.print("Vol = ");
lcd.print(i,1);
lcd.print(" g");
delay(300);
//if value consistent after 5 readings, buzzer will play and LCD show measurement complete
//then it will upload the value (i) into Database that can be displayed using PHP file
//I know how code in PHP and have my own hosted DB as well (with a domain name) so i wont use XAMPP or WAMPP
}
Best,
Azree