#include<HX711.h>
const int ld_cell = 2;
const int ld_sck = 4;
float acceleration_due_to_gravity = 9.81; // Aceleração devido à gravidade em m/s²
HX711 scale;
const int redPin = 23;
const int greenPin = 22;
const int bluePin = 21;
void setup() {
Serial.begin(115200);
scale.begin(ld_cell,ld_sck);
scale.set_scale(419.8);
scale.tare();
pinMode(13, INPUT);
Serial.println("iniciando...");
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
if (digitalRead(13)==HIGH) {
float weightNewton = measure();
if (weightNewton >= 40) {
colorRGB(255, 0, 127);
}
else {
colorRGB(32, 168, 170);
}
}
delay(1000);
}
void colorRGB(int red, int green, int blue) {
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
float measure() {
if(scale.is_ready()){
Serial.println("Removendo o peso da tara...");
delay(500);
Serial.println("Tara feita.");
Serial.println("Agora coloque peso.");
delay(500);
long reading = scale.get_units();
float weight_in_newtons = reading * acceleration_due_to_gravity; // Converte para Newtons
Serial.print("Peso em Newtons: ");
Serial.println(weight_in_newtons, 2);
return weight_in_newtons;
}
}