Good evening, I need help with my project.
I have an ESP32S board with an HX711 and a DHT11 and I want to transmit temperature, humidity and weight data to Blynk.
I don’t realize what I’m missing to be able to transmit the weight of the HX711 module. I’m attaching the program and another piece of information I can give is that it works perfectly on the serial monitor.
I hope you can help me.
#define BLYNK_TEMPLATE_ID "TMd2__0eG7"
#define BLYNK_TEMPLATE_NAME "balan temp"
#define BLYNK_AUTH_TOKEN "GMgLX8HSoxx_qqU8fDqPjiBibW8Z"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
BlynkTimer timer;
char network[] = "Jaio";
char password[] = "delueve";
#include "DHT.h"
#include <DHT_U.h>
int SENSOR = 17; // pin DATA de DHT22 a pin digital 2
int TEMPERATURA;
int HUMEDAD;
DHT dht(SENSOR, DHT11);
#include "HX711.h" // incluye libreria HX711
#define DT 16 // DT de HX711 a pin digital 16
#define SCK 18 // SCK de HX711 a pin digital 18
HX711 celda; // crea objeto con nombre celda
void readSensor(){
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Blynk.virtualWrite(V2,(celda.get_units(5), 1));
Blynk.virtualWrite(V0,h);
Blynk.virtualWrite(V1,t);
Serial.print(F("Humedad: "));
Serial.print(h);
Serial.print(F("% Temperatura: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print("gramos: "); // texto descriptivo
Serial.println(celda.get_units(5), 1); // muestra el valor obtenido promedio de 20 lecturas
celda.power_down(); // apaga el modulo HX711
delay(3000); // demora de 3 segundos
celda.power_up(); // despierta al modulo HX711
}
void setup() {
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN,network,password);
dht.begin();
celda.begin(DT, SCK); // inicializa objeto con los pines a utilizar
celda.set_scale(2100.f); // establece el factor de escala obtenido del primer programa
celda.tare(); // realiza la tara o puesta a cero
timer.setInterval(2000L,readSensor);
}
void loop() {
Blynk.run();
timer.run();
}
you should follow the same principal as you have with the temperature and humidity, where you assign the reading to a variable (t and h) then write that value to Blynk, as well as printing it to your serial monitor.
That way, you can see the results of the weight reading in the serial monitor and understand if the result makes sense and also matches what you are seeing in Blynk.
Obviously, if you start-up your device with a weight on it, doing a tare in void setup() will zero the scales, so subsequent reading with the same weight on the scales won’t make much difference to the reading, other than the minor drift that occurs in the Hx711.
As @Madhukesh said, you need to remove the delay, and instead increase the BlynkTimer time.
I’m not sure why you’re doing the power up at the end of the process, it doesn’t make much sense.
Also, what type of subscription do you have (free, maker, pro)?
If it’s free, what does the billing screen show about the maximum number of available templates?
Good morning and thanks for the response.
My account is free but I have no problem with the templates.
I pass the modified program.
Now I am showing the value of float (r) on the serial monitor and I see the same as in blynk (it shows a value of 1)
With the first program on the serial monitor the scale worked perfectly
#define BLYNK_TEMPLATE_ID "TMPL2d2__0eG7"
#define BLYNK_TEMPLATE_NAME "balanza temp"
#define BLYNK_AUTH_TOKEN "GMgLX8HSoxx_qqU8fDqPjiBmmpzibW8Z"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
BlynkTimer timer;
char network[] = "Jaimico";
char password[] = "delunoalnueve";
#include "DHT.h"
#include <DHT_U.h>
int SENSOR = 17; // pin DATA de DHT22 a pin digital 2
int TEMPERATURA;
int HUMEDAD;
DHT dht(SENSOR, DHT11);
#include "HX711.h" // incluye libreria HX711
#define DT 16 // DT de HX711 a pin digital 16
#define SCK 18 // SCK de HX711 a pin digital 18
HX711 celda; // crea objeto con nombre celda
void readSensor(){
float r = (celda.get_units(5), 1);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Blynk.virtualWrite(V2,r);
Blynk.virtualWrite(V0,h);
Blynk.virtualWrite(V1,t);
Serial.print(F("Humedad: "));
Serial.print(h);
Serial.print(F("% Temperatura: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print("gramos: "); // texto descriptivo
Serial.println(r); // muestra el valor obtenido promedio de 20 lecturas
//celda.power_down(); // apaga el modulo HX711
// delay(3000); // demora de 3 segundos
celda.power_up(); // despierta al modulo HX711
}
void setup() {
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN,network,password);
dht.begin();
celda.begin(DT, SCK); // inicializa objeto con los pines a utilizar
celda.set_scale(2100.f); // establece el factor de escala obtenido del primer programa
celda.tare(); // realiza la tara o puesta a cero
timer.setInterval(2000L,readSensor);
}
void loop() {
Blynk.run();
timer.run();
}
So that you can help me better, I will tell you the project.
I practice falconry and I am training a falcon.
This program must be able to control weight throughout the day to know the right time to feed.
I wasn’t suggesting that you did have a problem with templates.
I need to know what type of free account you have, and going to the billing screen and telling me what the maximum allowable number of templates for your account is will tell me what type of free account you have.
Can you explain the logic, as you see it, of the power_up() command for the scale?
and if you were going to power a device up, at what point in the process do you think you’d do that?
Do you normally turn your computer on after you’ve finished using it?
I forgot to take out that line.
I already fixed it and I still have exactly the same problem.
If you know how to arrange the program, please tell me how it would be most convenient.
#define BLYNK_TEMPLATE_ID "TMd2__0eG7"
#define BLYNK_TEMPLATE_NAME "balanza temp"
#define BLYNK_AUTH_TOKEN "GMgSoxx_qqU8fDqPjiBmmpzibW8Z"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
BlynkTimer timer;
char network[] = "Jaico";
char password[] = "delnueve";
#include "DHT.h"
#include <DHT_U.h>
int SENSOR = 17; // pin DATA de DHT22 a pin digital 2
int TEMPERATURA;
int HUMEDAD;
DHT dht(SENSOR, DHT11);
#include "HX711.h" // incluye libreria HX711
#define DT 16 // DT de HX711 a pin digital 16
#define SCK 18 // SCK de HX711 a pin digital 18
HX711 celda; // crea objeto con nombre celda
void readSensor(){
float r = (celda.get_units(5), 1);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Blynk.virtualWrite(V2,r);
Blynk.virtualWrite(V0,h);
Blynk.virtualWrite(V1,t);
Serial.print(F("Humedad: "));
Serial.print(h);
Serial.print(F("% Temperatura: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print("gramos: "); // texto descriptivo
Serial.println(r); // muestra el valor obtenido promedio de 20 lecturas
//celda.power_down(); // apaga el modulo HX711
// delay(3000); // demora de 3 segundos
// celda.power_up(); // despierta al modulo HX711
}
void setup() {
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN,network,password);
dht.begin();
celda.begin(DT, SCK); // inicializa objeto con los pines a utilizar
celda.set_scale(2100.f); // establece el factor de escala obtenido del primer programa
celda.tare(); // realiza la tara o puesta a cero
timer.setInterval(2000L,readSensor);
}
void loop() {
Blynk.run();
timer.run();
}