I have a 100 gram load cell with the hx711 amplifier board. I have it wired up to an arduino nano with an NRF24L01 module to send the raw value to another arduino nano. The problem is that when I aply a force to the loadcell, the value gets larger until a certain point where it becomes negative and starts to get bigger from that negative number again. So for example:
- No load : 500
- Force aplied: 1000
- More force: 1500
- More force: 2000
- More force: -2000
- More force: -1500
- More force: -1000
It is really weird. Everything worked before. I have updated the code a few times and made it simpler. I even had it set up so that the arduino only reads the value and sends it to serial monitor. That gave exactly the same behaviour. To give you a feeling for how much force is needed to reach this sort of limit. About 2 playing cards it can measure in the positive range en from 3 to 4 it becomes negative again. Then stacking to 5 or 6 it becomes positive and when 7 or 8 playing cards are on top of the loadcell the value becomes negative again.
I hope my description of the problem is sort of understandable. If more information is needed, let me know!
What could be the problem here?
EDIT: Thanks for the comments. I have found the problem: I had changed a variable in my code from long to int. That caused the problem. Here is the fixed code for anyone who is interested:
#include "HX711.h"
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;
HX711 scale;
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
void setup() {
Serial.begin(57600);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
long reading;
int taredone = 0;
long tarenumber;
void loop() {
if (taredone == 0){
Serial.print("15 seconds to tare");
delay(15000);
tarenumber = scale.read_average(20);
Serial.print("Tarevalue: ");
Serial.println(tarenumber);
Serial.print("zero value: ");
Serial.println(scale.read()-tarenumber);
reading = 1234567890
radio.write(&reading, sizeof(reading));
taredone = 1;
}
if (scale.is_ready()) {
while (true) {
reading = scale.read_average(10)-tarenumber;
Serial.println(reading);
radio.write(&reading, sizeof(reading));
delay(10);
}
}
else {
Serial.println("HX711 not responding or no loadcell connected");
}
delay(500);
}