Panel Cookies
Arduino Body Scale - code
Help me by sharing this post

The code is quite simple. You can go below and download it and you will also have links for the libraries for the LCD screen and the HX711 ADC. In the code we first wait for the ADC value to cahnge a lot. That means the calibration mass was placed on the scale. Then we create a loop and calibrate the scale based on that calibrated mass. Change the "y1" value to the value (in grams) of your calibrated mass. Then in the code, we just read the value and print it on the LCD or serial monitor. We also have interuptions for the two push buttons to detect when we press the mode or Tara buttons. The Tara will set the scale to 0, and the mode will change from g, to mm and to oz. Install the libraries, compile and upload to the Arduino.







schematic arduino body scale LCD



#include "HX711.h" //Download here: https://electronoobs.com/images/Arduino/tut_115/HX711-master.zip

// HX711.DOUT - pin #D3
// HX711.PD_SCK - pin #D2

HX711 scale(D3, D2); 

void setup() {
 Serial.begin(9600);
 Serial.println("HX711 Demo");

 Serial.println("Before setting up the scale:");
 Serial.print("read: tt");
 Serial.println(scale.read()); 

 Serial.print("read average: tt");
 Serial.println(scale.read_average(20)); 

 Serial.print("get value: tt");
 Serial.println(scale.get_value(5)); 

 Serial.print("get units: tt");
 Serial.println(scale.get_units(5), 1); 

 scale.set_scale(2280.f); 
 scale.tare(); 

 Serial.println("After setting up the scale:");

 Serial.print("read: tt");
 Serial.println(scale.read()); 

 Serial.print("read average: tt");
 Serial.println(scale.read_average(20)); 

 Serial.print("get value: tt");
 Serial.println(scale.get_value(5)); 

 Serial.print("get units: tt");
 Serial.println(scale.get_units(5), 1); 
 Serial.println("Readings:");
}

void loop() {
 Serial.print("one reading:t");
 Serial.print(scale.get_units(), 1);
 Serial.print("t| average:t");
 Serial.println(scale.get_units(10), 1);

 scale.power_down(); 
 delay(5000);
 scale.power_up();
}








yt_link
insta_link
fb_link
twitter_link

Arduino Scale




Affiliate Disclosure

ADVERTISERS



PCBWAY PCB service





Curso Arduino Online nivel Intermedio