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: