Help please i cannot connect my nodeMCU32 with blynk

i am trying to make a gas sensor but it seems it cannot connect at all . (the serial monitor is blank)

#define BLYNK_TEMPLATE_ID "TMPLVE5VHKY0"
#define BLYNK_DEVICE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "lRoRyr52ZZomiPLKEPaCoiha1MHDVpI6"


/* WiFi credentials */
char ssid[] = "bajingan";
char pass[] = "bajing522";
 
SimpleTimer timer;
 
int mq135 = A0; // smoke sensor is connected with the analog pin A0 
int data = 0; 
void setup() 
{
  Serial.begin(115200);
  Blynk.connect ();
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(1000L, getSendData); // new data will be updated every 1 sec 
}
 
void loop() 
{
  timer.run(); // Initiates SimpleTimer
  Blynk.run();
}
 
/***************************************************
 * Send Sensor data to Blynk
 **************************************************/
void getSendData()
{
data = analogRead(mq135); 
  Blynk.virtualWrite(V4, data); //
 
  if (data > 500)
  {
    Blynk.notify("Smoke Detected"); 
  }
 
}



Your sketch doesn’t have any # include <> statements for the Blynk libraries, so its impossible for it to compile as it stands.

You’re also using SimpleTimer instead of BlynkTimer, but you don’t have a # include <> statement for that library either…

This line doesn’t belong in this sketch…

and this won’t work with Blynk IoT because it’s a Legacy command…

Even if it did work, or you replaced it with the IoT equivalent (logEvent) then you’d send the same notification once every second while data > 500 and quickly hit the allowed limit for events.

Read this for more info on how to do notifications in Blynk IoT and how to use ‘flag’ variables to avoid unwanted repeat notifications…

Pete.

thank you very much for the reply , i will try to change the code for a bit .

i have corrected the code and it is able to compile but still cannot connect to blynk and the serial monitor is also blank . thank you


#include <SimpleTimer.h>
#include<WiFiClient.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#define BLYNK_DEVICE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "lRoRyr52ZZomiPLKEPaCoiha1MHDVpI6"



/* WiFi credentials */
char ssid[] = "anjing";
char pass[] = "bajingan";
char server[] = "blynk-cloud.com";
int port = 8080;
char auth[] = "lRoRyr52ZZomiPLKEPaCoiha1MHDVpI6";

SimpleTimer timer;
 
int mq135 = A0; // smoke sensor is connected with the analog pin A0 
int data = 0; 
void setup() 
{
  Serial.begin(115200);
  WiFi.begin(ssid, pass);
  Blynk.config(auth, server, port);


  timer.setInterval(1000L, getSendData); // new data will be updated every 1 sec 
}
 
void loop() 
{
  timer.run(); // Initiates SimpleTimer
  Blynk.run();
}
 
/***************************************************
 * Send Sensor data to Blynk
 **************************************************/
void getSendData()
{
data = analogRead(mq135); 
  Blynk.virtualWrite(V4, data); //
 

  
 
}

Triple backticks look like this ( ``` ).

BLYNK_TEMPLATE_ID and BLYNK_DEVICE_NAME must be on the top of your sketch, above any includes.

You are using the old blynk server, the new blynk server is blynk.cloud

I’d suggest using blynk timer instead of simple timer.

ok i am trying the new code . thank you for the reply

can i know the code for blynk timer ? or any library i should add . thank you

Check this article

this is the code that is updated t. it is able to connect with blynk but the problem is data is not be able to send to my template

#define BLYNK_DEVICE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "lRoRyr52ZZomiPLKEPaCoiha1MHDVpI6"


#include<WiFiClient.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space


/* WiFi credentials */
char ssid[] = "anjing";
char pass[] = "bajingan";
char server[] = "blynk.cloud";
int port = 8080;
int mq135 = 34; // smoke sensor is connected with the analog pin A0 
char auth[] = "lRoRyr52ZZomiPLKEPaCoiha1MHDVpI6";
int analog_data=analogRead(mq135);

BlynkTimer timer;
 

void sendSensor()
{



Blynk.virtualWrite(V4,analog_data);
delay(300);
}

void setup() 
{
  Serial.begin(9600);
  WiFi.begin(ssid, pass);
  Blynk.config(auth, server, port);


  timer.setInterval(1000L, sendSensor); // new data will be updated every 1 sec 
}
 
void loop() 
{
  timer.run(); // Initiates SimpleTimer
  Blynk.run();
  Serial.println(analog_data);
  delay(200);
}
 


 

I’d suggest that you add serial print function to make sure that everything is working properly.

You need to remove these delays. If you want the sendSensor function to be called less frequently then increase the BlynkTimer time.

You should also remove this from your void loop…

and place it in your sendSensor function.

You aren’t getting any values in Blynk because you are only reading the value of your mq135 once, at boot-up, with line of code…

rather than reading it in your sendSensor function.

Pete.

Your previous sketch was better.