I have a HX711 sensor load cell and esp32 wroom. I had connected them with the blynk application cloud ,the device gauge of virtual pin V0 is online but not showing the result .Any one of you can send me a code to connect my hx711 and node mcu32s with blynk gauge,And thank you for help
You can search the forum.
How have you configured the V0 datastream? What are the min/max values that you’ve specified?
Are you using Edgent?
If so, what board type have you un-commented, and have you checked your Settings.h for pin conflicts with this board type and the pins used for your sensors?
Pete.
yes i configured the V0 datastrem , the max are 20000 and min is 0
no i don’t using edgent . my board is Esp32wroom the nodemcu32s and i had checked settings.h
my code is :
#define BLYNK_TEMPLATE_ID "TMPLJNl10xzz"
#define BLYNK_DEVICE_NAME "Weight"
#define BLYNK_AUTH_TOKEN "XVeyTrlWsk6ktfDaWQl7UPdlkmSl35I2"
char auth[] = "XVeyTrlWsk6ktfDaWQl7UPdlkmSl35I2";
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#include <HX711.h>
#include <dummy.h>
#include <HX711_ADC.h>
#include "HX711.h" // HX711 connects controller to loadcell
#include <WiFi.h> // Library to connect ESP32 to WiFi. Includes WiFiUDP
#include "driver/adc.h" // Needed to power down ADC
#include <esp_wifi.h> // Needed to turn off WiFi radio
#include <esp_bt.h> // Needed to turn off BT radio
#include <BlynkSimpleEsp32.h> //Library for uploading data to to Blynk
//Define HX711 load sensor interface pins
#define DOUT 18
#define CLK 19
HX711 scale;
float weight;
float calibration_factor = 103.65; // by calibration
const char *ssid = "Topnet 2020";
const char *password = "28031992";
void setup() {
Serial.begin(115200);
delay(2000);
Serial.println();
setCpuFrequencyMhz(80);
Serial.println("CPU Frequency set to 80 Mhz");
adc_power_on();
Serial.println("ADC power ON");
scale.begin(DOUT, CLK);
scale.set_scale(calibration_factor);
Serial.println("Taking 100 weight measurments and will use last one ...");
weight = scale.get_units(100);
Serial.print("Weight: ");
Serial.print(weight, 1); //number indicates # of decimal places
Serial.println(" g ");
WiFi.persistent( false );
delay( 1000 );
WiFi.mode(WIFI_STA);
Serial.print("WiFi on and connecting ...");
WiFi.begin(ssid, password);
// Keep track of when we started our attempt to get a WiFi connection
unsigned long startAttemptTime = millis();
// Keep looping while we're not connected for 10 sec (10,000 millisec)
while (WiFi.status() != WL_CONNECTED &&
millis() - startAttemptTime < 10000) {
delay(10);
}
// If not connected, serial print notification and move on.
if (WiFi.status() != WL_CONNECTED) {
Serial.println("FAILED WiFi CONNECTION");
}
// If connection successful, show IP address and update BLYNK.
else {
Serial.println();
Serial.print("Connected to ");
Serial.println(WiFi.SSID()); // Tell us what network is connected
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address to serial monitor
Serial.print("RSSI: ");
Serial.println(WiFi.RSSI());
delay(1000);
Serial.println("Connecting to Blynk...");
Blynk.config(auth); // in place of Blynk.begin(auth, ssid, pass);
Blynk.connect(2000);
Blynk.connected() == true;
Serial.println("Blynk connected");
delay(500);
Blynk.virtualWrite(V1, "Weight");
Blynk.run();
delay(1000);
}
}
void loop() {
Blynk.run();
}
and monitor serial show that
CPU Frequency set to 80 Mhz
ADC power ON
Taking 100 weight measurments and will use last one ...
Weight: 32069.3 g
WiFi on and connecting ...
Connected to Topnet 2020
IP address: 192.168.1.103
RSSI: -66
Connecting to Blynk...
Blynk connected
@Gha 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:
```
I’d also suggest that you copy the exact text from your serial monitor and paste it - also with triple backticks at the beginning and end.
Pete.
ok it’s done, please help i need this for my graduation
You don’t use Blynk.connected() in this way, it may make more sense if it were part of an if statement.
Having this in your void setup is unlikely to work, as it will execute before Blynk has actually completed the connection process. Also, if your gauge is connected to V0 as you said, writing the value to V0 rather than V1 would be a good start.
The code seems to be written as though you are planning to use deep sleep, but there is no deepsleep command. At the moment, a weight reading will only be taken once, at start-up.
its difficult to understand more without seeing your actual serial output generated by this sketch, and understand exactly what it is that you are trying to achieve.
Pete.
thank you for your help pete
i’m not good in programing but i need just to show weight from sensor on the blynk gauge device but i’don’t know how
Answering some of my questions would be a start.
Pete.
ok thankyou again , i need your help to know where is the problem in this code.
if you can tell me the basic code for having a resulat
Try this
#define BLYNK_TEMPLATE_ID "TMPLxxxxxx"
#define BLYNK_DEVICE_NAME "Device"
#define BLYNK_AUTH_TOKEN "YourAuthToken"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include "HX711.h"
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = " ";
char pass[] = " ";
BlynkTimer timer;
const int LOADCELL_DOUT_PIN = D3;
const int LOADCELL_SCK_PIN = D4;
HX711 scale;
float weight;
float calibration_factor = 3.85;
void setup()
{
// Debug console
Serial.begin(115200);
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
// scale.tare(); //Reset the scale to 0
long zero_factor = scale.read_average(); //Get a baseline reading
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
// Setup a function to be called every second
timer.setInterval(1000L,sensor);
}
void loop()
{
Blynk.run();
timer.run()
}
void sensor()
{
weight = scale.get_units(5);
Blynk.virtualWrite(V1, weight);
Serial.print("Weight: ");
Serial.print(weight);
Serial.println(" KG");
Serial.println();
}
}
If you won’t share information about exactly what you want the code to do, and won’t share information about the actual serial output or which virtual pins you are really using then it’s impossible to provide sensible guidance.
Pete.
thanks pete. my problem is solved but i have another one if you can tell me why blynk dosen’t connect . i try to control 4 relay by blynk with this code but is failled
#define BLYNK_TEMPLATE_ID "TMPLYlD0nOwm"
#define BLYNK_DEVICE_NAME "Relay"
#define BLYNK_AUTH_TOKEN "YX0xrsTSudCk-O0rhVgVZmQkI4kOp1HD"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#include <dummy.h>
#include <BlynkSimpleEsp32.h>
// You should get Auth Token in the Blynk App.
#include <WiFi.h>
#include <WiFiClient.h>
#define relayPin1 33
#define relayPin2 25
#define relayPin3 26
#define relayPin4 27
int relayState1 = 1;
int relayState2 = 1;
int relayState3 = 1;
int relayState4 = 1;
char auth[] = "YX0xrsTSudCk-O0rhVgVZmQkI4kOp1HD";
// Your WiFi credentials.
char ssid[] = " Abir2";
char pass[] = "Abir75294188";
BLYNK_WRITE(V1) {
if (relayState1 = param.asInt()){
digitalWrite(relayPin1, relayState1);
}
}
BLYNK_WRITE(V2) {
if (relayState2 = param.asInt()){
digitalWrite(relayPin2, relayState2);
}
}
BLYNK_WRITE(V3) {
if (relayState3 = param.asInt()){
digitalWrite(relayPin3, relayState3);
}
}
BLYNK_WRITE(V4) {
if (relayState4 = param.asInt()){
digitalWrite(relayPin4, relayState4);
}
}
BLYNK_CONNECTED() {
// Request the latest state from the server
Blynk.syncVirtual(V1);
Blynk.syncVirtual(V2);
Blynk.syncVirtual(V3);
Blynk.syncVirtual(V4);
}
void setup()
{
WiFi.begin(ssid, pass);
// Keep track of when we started our attempt to get a WiFi connection
unsigned long startAttemptTime = millis();
// Keep looping while we're not connected for 10 sec (10,000 millisec)
while (WiFi.status() != WL_CONNECTED &&
millis() - startAttemptTime < 10000) {
delay(10);
}
// If not connected, serial print notification and move on.
if (WiFi.status() != WL_CONNECTED) {
Serial.println("FAILED WiFi CONNECTION");
}
// If connection successful, show IP address and update BLYNK.
else {
Serial.println();
Serial.print("Connected to ");
Serial.println(WiFi.SSID()); // Tell us what network is connected
Serial.print("IP address:\t");
Serial.println(WiFi.localIP()); // Send the IP address to serial monitor
delay(1000);
Serial.println("Connecting to Blynk...");
Blynk.config(auth); // in place of Blynk.begin(auth, ssid, pass);
Blynk.connect(2000);
Serial.println("Blynk connected");
delay(500);
Blynk.run();
delay(1000);
}
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(relayPin1, OUTPUT);
pinMode(relayPin2, OUTPUT);
pinMode(relayPin3, OUTPUT);
pinMode(relayPin4, OUTPUT);
//On power ON all Relays in OFF state
digitalWrite(relayPin1, relayState1);
digitalWrite(relayPin2, relayState2);
digitalWrite(relayPin3, relayState3);
digitalWrite(relayPin4, relayState4);
}
void loop()
{
Blynk.run();
}
Copy the serial output that you see from boot-up, and paste it between triple backticks.
Pete.
the serial output dosen’t show anythinh
Move your Serial.begin command to the beginning of your void setup.
Pete.
the monitor serial still show nothing
Change your Serial.begin command to use 115200 and use the same baud rate in your serial monitor.
If you still don’t see anything then restart your PC check the connections, try a different USB cable, ensure you have the correct serial port selected, disconnect all the wiring from your board except the USB connection etc etc.
If you still don’t see anything then your ESP is probably dead.
Pete.
the code is correct or not ? because i need to control relay with device switchs in blynk console an blynk iot
You haven’t shared any information about what the code is supposed to do, so it’s difficulty to say.
You do some rather strange thigs, like this…
This…
This…
This…
And this…
As I’ve said multiple times in this topic, if you want assistance with a project then you need to explain in detail exactly what it’s supposed to achieve, or have sufficient in-code documentation to explain the logic and methods you are using.
Throwing together random pieces of code from different sources without understanding their function, and without doing any structured iterative testing to ensure that your code blocks function as expected isn’t the way the write code.
The most valuable debugging tool you have during this process is the serial monitor, and getting that working correctly, adding appropriate Serial.print statements and studying the results that appear in the serial monitor is the best way forward.
Pete.
.