Hello i am newbie and want to connect my nodemcu v3 with arduino ide and blynk. I make smart water tank which use ultrasonic sensor and flow rate sensor. The problem is i ran my code and the serial monitor doesnt pop up anything and there is no wifi from the node mcu that i can connect with my blynk app. I hope that anyone can give me guidance. Here is my code
#define BLYNK_TEMPLATE_ID "TMPL4SEKQ9Nl"
#define BLYNK_DEVICE_NAME "NodemcuBlynk"
#define BLYNK_AUTH_TOKEN "2NFdoKGV8_o1W2QwdmU75ljTXUKYICu5"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define PULSE_PIN D2 //gpio2
#define LED_PIN D7 //gpio13
const int trigPin = D3;
const int echoPin = D4;
const int trigPin1 = D5;
const int echoPin1 = D6;
long duration;
int distance;
long duration1;
int distance1;
int valvepin = D1;
volatile long pulseCount=0;
float calibrationFactor = 4.5;
float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;
float totalLitres;
unsigned long oldTime;
void ICACHE_RAM_ATTR pulseCounter()
{
pulseCount++;
}
char auth[] ="2NFdoKGV8_o1W2QwdmU75ljTXUKYICu5";
char ssid[]="Unipie";
char pass[]="12332145";
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(valvepin, OUTPUT);
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
oldTime = 0;
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH); // We have an active-low LED attached
pinMode(PULSE_PIN, INPUT);
attachInterrupt(PULSE_PIN, pulseCounter, FALLING);
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop(){
Blynk.run();
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Blynk.virtualWrite(V5,distance);
if(distance>=22){
Blynk.notify("Please refill the coolant");
}
Serial.print("Distance Main Tank: ");
Serial.println(distance);
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration1 = pulseIn(echoPin1, HIGH);
distance1 = duration1 * 0.034 / 2;
Blynk.virtualWrite(V6,distance1);
Serial.print("Distance Machine Tank: ");
Serial.println(distance1);
if (distance1 >= 13)
{
digitalWrite(valvepin, HIGH);
delay(2000);
Serial.println("VALVE AND MOTOR OPEN");
}
else
{
digitalWrite(valvepin, LOW);
delay(2000);
Serial.println("VALVE AND MOTOR CLOSE");
}
if((millis() - oldTime) > 1000) // Only process counters once per second
{
detachInterrupt(PULSE_PIN);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime = millis();
flowMilliLitres = (flowRate / 60) * 1000;
totalMilliLitres += flowMilliLitres;
totalLitres = totalMilliLitres * 0.001;
unsigned int frac;
Serial.print("flowrate: ");
Serial.println(flowRate); // Print the integer part of the variable
Blynk.virtualWrite(V7,flowRate);
pulseCount = 0;
attachInterrupt(PULSE_PIN, pulseCounter, FALLING);
}
}
You don’t connect the Blynk app to the NodeMCU’s WiFi unless you are using dynamic provisioning - which you are not.
Using static provisioning, where you hard-code the Auth token and the WiFi credentials, the NodeMCU connects to your home WiFi so that it can communicate with the Blynk server.
Your mobile device also connects to the internet - using WiFi or mobile data from any location in the world, and it too talks to the same Blynk server. There is no direct mobile device to NodeMCU communication.
I’d suggest that you change the serial baud rate in your scent h to 74880 and change your serial monitor to the same baud rate.
Notifications also work differently in Blynk IoT, so Blynk.notify is no longer supported and you need to use events instead. Read this for more info…
When you’ve restructured your sketch to clean-up your void loop and changed or temporarily removed your notification code then re-post your revised sketch along with updated detailed of what is now appearing in your serial monitor and app/web dashboard.