Discrepancy in load cell values between serial monitor and Blynk labeled value widget when using load cells

Hello everyone,

Please forgive my complete lack of coding ability. I’m learning-but very slowly. haha

Here’s the predicament:

I am a cosponsor of a beekeeping club at a local high school. Yesterday, we lost a swarm of bees (which is valued at over $100) because nobody from the club was there to see the mass exodus. The next time a swarm leaves one of our hives, it would be nice if we could get notified about it in time to go capture the swarm. Therefore, I am attempting to use 4 load cells in a Wheatstone Bridge configuration wired to an HX711 amplifier which is connected to an Arduino MRK WiFi 1010 to determine the weight of a beehive. The Franken-code I have haphazardly cobbled together from others’ sketches works in the serial monitor. But, when I use the labeled value widget in the Blink app on my Android phone, the values are completely different. Here is the (awful) code:

"/* 
 Example using the SparkFun HX711 breakout board with a scale
 By: Nathan Seidle
 SparkFun Electronics
 Date: November 19th, 2014
 License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

 This example demonstrates basic scale output. See the calibration sketch to get the calibration_factor for your
 specific load cell setup.

 This example code uses bogde's excellent library:"https://github.com/bogde/HX711"
 bogde's library is released under a GNU GENERAL PUBLIC LICENSE

 The HX711 does one thing well: read load cells. The breakout board is compatible with any wheat-stone bridge
 based load cell which should allow a user to measure everything from a few grams to tens of tons.
 Arduino pin 2 -> HX711 CLK
 3 -> DAT
 5V -> VCC
 GND -> GND

 The HX711 board can be powered from 2.7V to 5V so the Arduino 5V power should be fine.

*/

#define BLYNK_PRINT Serial

// Use Virtual pin 5 for uptime display
#define PIN_UPTIME V5

#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "E0riUQXZw4qR0lOxDwLnMP20SAIdITHs";



// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "The Lair of the Weeping Angels";
char pass[] = "TheDoctor";


// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.

#include "HX711.h"

#define calibration_factor -1875.0 //This value is obtained using the SparkFun_HX711_Calibration sketch

#define DOUT  3
#define CLK  2


HX711 scale;

void sendloadcell()
{
  Blynk.virtualWrite(V1,String(scale.get_units(1870),1));
}

// This function tells Arduino what to do if there is a Widget
// which is requesting data for Virtual Pin (5)
BLYNK_READ(PIN_UPTIME)
{
  // This command writes Arduino's uptime in seconds to Virtual Pin (5)
  Blynk.virtualWrite(PIN_UPTIME, millis() / 10000);
}
BlynkTimer timer;

// This function sends Arduino's up time every 10 second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 10000);
}

void setup() {
  Serial.begin(9600);
  
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(10000, myTimerEvent);
  
    
    Serial.println("HX711 scale demo");

  scale.begin(DOUT, CLK);
  scale.set_scale(-1870); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0

  Serial.println("Readings:");

  }

void loop() {
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
  
  Serial.print("Reading: ");
  Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
  Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
  Serial.println();
  }"

Also, I have tried using both Blynk’s Virtual Pin 6 and my analog pin 3 and neither of them match the data shown in the serial monitor. When I use pin A3, the numbers are around 200 lbs. higher than they should be in the Blynk app and they bounce all over the place. When I use pin V6, the values in the Blynk app start off at around 1 or 2 but climb steadily with every data push dispite the fact I’m adding no weight. I’ve looked at the script until my eyes have gone crossed and I’ve exhausted just about every idea I’ve had/found trying to avoid having to ask for help but I’m legitimately stumped. Would some kind soul be willing to help a brother out? I would like to be able to understand all this well enough eventually to be able to teach the students in our club how to make their own DIY hive scales.

Not sure whether it will help but, just in case, I have also uploaded the clone QR code to my Blynk app-in case anybody needs it and I’ve attached a link to screenshots of both my serial monitor and my Blink app that were taken simultaneously:

https://photos.app.goo.gl/LCSy5fTMi7zCoDUC8

I really don’t know where your problems at as I’m new to all this. But if you use:

Blynk.virtualWrite(V1, 1234);

Can you get 1234 in Blynk app?

Move

Blynk.virtualWrite(V1,String(scale.get_units(1870),1));

Down into your timer loop so it will run every 10 seconds.

void myTimerEvent()
{
Blynk.virtualWrite(V1,String(scale.get_units(1870),1));

Blynk.virtualWrite(V5, millis() / 10000);
}

Or maybe I missed it, but I don’t see where sendloadcell() is called from.

@uktenore please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

1 Like

Oops. Sorry. Done.

The reality is that one of your hives swarmed because you allowed the bees to become overcrowded and raise new queen cells. That’s bad beekeeping and this Blynk solution is the beekeeping equivalent of having an alert to tell you that your horse has bolted from the stable, as opposed to ensuring that the stable door isn’t left open in the first place. :racehorse:

A better use of Blynk may be to use it as a tool to record hive inspections and the results of those inspections, and to alert you when inspections are overdue - especially in spring and early summer. But, on to your question…

There are so many things wrong with your code, and with what you’ve said about the results you’re seeing that it’s difficult to know where to start.

Your app currently has one widget set-up, which is a labeled display connected to pin V6 with the label “Current Hive Weight”
image

Your code has a function, which presumably is meant to write weight readings to this widget, called sendloadcell

void sendloadcell()
{
  Blynk.virtualWrite(V1, String(scale.get_units(1870), 1));
}

However, there are a number of problems with this function:

  1. Your code has no mechanism for calling this function. You need something like timer.setInterval(5000, sendloadcell); in your void setup to call it every 5 seconds
  2. This function is sending data to pin V1, not pin V6. You have no widgets connected to pin V1
  3. The command (scale.get_units(1870), 1) tells the scale to take 1870 readings and average them, whereas the command in your void loop (scale.get_units(), 1) is asking for just one reading.

I’m not even going to discuss the issues with the uptime counter, as it’s not relevant to you getting your weight reading working, and I’d suggest that you rip it out of your code to reduce the clutter.

You might want to have a read of this topic:

@christophebl has done a lot of similar work, but his weight readings aren’t aimed at detecting swarms but at being able to know how much the hive weighs to estimate the health of the colony and the amount of honey in the supers.
In a recent message he was telling me that he’s having reliability issues with the LORA network that he moved to (post #20), and that he’s now exploring the possibility of using a TTGO T-Call board instead.

Pete.