Hi,
I have two force sensors connected to an ESP32 microcontroller. When the data from the force sensor is printed in an Arduino IDE, I get the output. But the same when it is connected to through Blynk Application, I am not getting output in the Arduino IDE and in the Blynk Application. My code is as mentioned below.
#define BLYNK_TEMPLATE_ID "TMPL*&^*&*^&*"
#define BLYNK_TEMPLATE_NAME "Smart Seating Detection System"
#define BLYNK_AUTH_TOKEN "C26g*******%%^%^&******"
#define SENSOR_PIN1 4 // The ESP32 pin connected to the first sensor
#define SENSOR_PIN2 2 // The ESP32 pin connected to the second sensor
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "C26g*******%%^%^&******"; // Get this from the Blynk App
char ssid[] = "<My SSID>"; // Your WiFi SSID
char pass[] = "<My Password>"; // Your WiFi password
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
}
int condition(int s1, int s2)
{
int cnt;
if(s1 > 30)
{
if(s2 > 30)
{
cnt = 0;
}
else
{
cnt = 1;
}
}
else
{
if(s2 > 30)
{
cnt = 1;
}
else
{
cnt = 2;
}
}
return cnt;
}
void loop() {
int OccupancyCount;
int ForceSensor_1 = analogRead(SENSOR_PIN1);
int ForceSensor_2 = analogRead(SENSOR_PIN2);
OccupancyCount = condition(ForceSensor_1, ForceSensor_2);
Serial.println(ForceSensor_1); // Print sensor value to serial monitor
Serial.println(ForceSensor_2); // Print sensor value to serial monitor
Serial.println(OccupancyCount);
Blynk.virtualWrite(V1, ForceSensor_1); // Send sensor value to Blynk app
Blynk.virtualWrite(V2, ForceSensor_2); // Send sensor value to Blynk app
Blynk.virtualWrite(V3, OccupancyCount); // Send sensor value to Blynk app
Blynk.run();
delay(1000); // Adjust delay as needed
}
I have tried debugging the code. When " Blynk.begin(auth, ssid, pass);" line is compiled and executed, I am getting an error. Could you please advice what could be done to sort this issue out. I have tried with the below also and still is does not work.
I have tried with the below code instead of " Blynk.begin(auth, ssid, pass);"
Alternate code which I have tried:
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Blynk.config(auth);
Blynk.connect();