hello
je suis justement à jouer avec une balance.
tu as essayé de faire un code avec l'exemple de la librairie.
c'est un bon réflexe, mais on voit que tu ne comprends pas tout de ce que tu fais.
l'instruction pinMode sert donner une affectation ( un role ) à une pin de la platine arduino:
pinMode(2,OUTPUT); passe la pin D2 en sortie.
cette fonction ne sert pas pour passer une valeur à une pin. pour cela il y a:
DigitalWrite(2,HIGH); passe la valeur HIGH à la sortie D2.
pour l'endroit ou ton prg bloque, (n'en parlons pas) 
revenons à la balance,
chaque mécanisme à ses résistances et contraintes. chaque HX711 à ses caractéristiques qui lui sont propres.
il faut donc "étalonner cette partie. il y a des programmes qui permettent de trouver la valeur à passer à la librairie . il faut préparer un poids connu( chez moi, 200gr), puis lancer le prg d'étalonnage. au moment voulu, tu dois mettre les 200gr sur la balance. le prg calcule et affiche la valeur que tu devras mettre en dur dans le prog: scale.set_scale(-416); (chez moi, cette valeur est -416).
je te passe:
ton prog qui fonctionne, attention j'ai changé la déclaration du cablage (D2 et D3) et la vitese de com avec le moniteur à 115200.
libre à toi de corriger soit le hard soit le soft.
// HX711 library for Arduino - example file
// https://github.com/bogde/HX711
// MIT License
// (c) 2018 Bogdan Necula
#include <Arduino.h>
#include "HX711.h"
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = A1;//2;
const int LOADCELL_SCK_PIN = A2;//3;
const int ledrouge = 5; // indique que la ledrouge est connectée sur la broche 5 (nombre entier).
const int ledverte = 6; // indique que la led verte est connectée sur la broche 6.
double poids_lu = 0.0;
HX711 scale;
void setup() {
Serial.begin(115200); //vitesse de com avec le moniteur
Serial.println("HX711 Demo"); //la meme vitesse doit etre reglée en bas du moniteur
digitalWrite(ledrouge, LOW); //la led sera éteinte
digitalWrite(ledverte, LOW); // la led sera éteinte
pinMode(ledrouge, OUTPUT); // la led rouge est une sortie
pinMode(ledverte, OUTPUT); // la led verte est une sortie
Serial.println("Initializing the scale"); // initialisation de la balance
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(1071.49); // le rapport a été calculé avec un autre sketch "calibration" . le résultat est 1071,49 O.K.
scale.set_scale(-416); // 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:");
}
void loop() {
poids_lu = scale.get_units();
Serial.print(poids_lu, 1);
Serial.print('\t');
if ((poids_lu > 240.0) && (poids_lu < 260.0)) { // si le poids est compris entre 240.0 et 260.0
digitalWrite (ledverte, HIGH); // la led verte s'allume.
digitalWrite (ledrouge, LOW); // la led rouge est éteinte.
Serial.println(F("led verte ON et led rouge OFF"));
}
else // sinon
{
digitalWrite(ledverte, LOW); // la led verte est éteinte.
digitalWrite(ledrouge, HIGH); // la led rouge s'allume.
Serial.println(F("led verte OFF et led rouge ON"));
}
delay(2000);
}
une copie d'écran , avec depose d'un poids >240 gr puis <240gr
et le programme de calibration de la balance
(nota: il en existe d'autres avec dialogue sur le moniteur, la valeur finale est la meme)
/**
HX711 library for Arduino - example file
https://github.com/bogde/HX711
MIT License
(c) 2018 Bogdan Necula
## How to calibrate your load cell
1. Call `set_scale()` with no parameter.
2. Call `tare()` with no parameter.
3. Place a known weight on the scale and call `get_units(10)`.
4. Divide the result in step 3 to your known weight. You should
get about the parameter you need to pass to `set_scale()`.
5. Adjust the parameter in step 4 until you get an accurate reading.
**/
#include "HX711.h"
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = A1;
const int LOADCELL_SCK_PIN = A2;
HX711 scale;
void setup() {
Serial.begin(115200);
Serial.println("HX711 Demo");
Serial.println("Initializing the scale");
// Initialize library with data output pin, clock input pin and gain factor.
// Channel selection is made by passing the appropriate gain:
// - With a gain factor of 64 or 128, channel A is selected
// - With a gain factor of 32, channel B is selected
// By omitting the gain factor parameter, the library
// default "128" (Channel A) is used here.
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
/*
1. Call `set_scale()` with no parameter.
2. Call `tare()` with no parameter.
3. Place a known weight on the scale and call `get_units(10)`.
4. Divide the result in step 3 to your known weight. You should
get about the parameter you need to pass to `set_scale()`.
5. Adjust the parameter in step 4 until you get an accurate reading.
*/
scale.set_scale();
//scale.set_scale(2280.f); // 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 ("vous avez 5 secondes pour mettre 200gr sur la balance");
delay(5000);
Serial.println (scale.get_units(10));
Serial.println(scale.get_units(10) / 200); //diviseur est le poids connu
Serial.println(F("mettre la valeur affichée à l'écran dans la ligne suivante dans le programme"));
Serial.println(F("puis relancer le programme"));
scale.set_scale(-416);//2244);
Serial.println(F("enlever le poids"));
delay(5000);
scale.set_scale(-416);//2244);
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(-414.15);
//scale.set_scale(2280.f); // 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), 2); // print the average of 5 readings from the ADC minus tare weight, divided
// by the SCALE parameter set with set_scale
Serial.println("Readings:");
}
void loop() {
Serial.print("one reading:\t");
Serial.print(scale.get_units(), 2);
Serial.print("\t| average:\t");
Serial.println(scale.get_units(10), 2);
scale.power_down(); // put the ADC in sleep mode
delay(5000);
scale.power_up();
}
si tu as des questions, n'hésite pas.