Water tank water level measurment

HERE IS CODE

// defines pins numbers
const int trigPin = 12;
const int echoPin = 15;
// defines variables
long duration;
int distance;
float h;


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


char auth[] = "xxx";


void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
Blynk.begin(auth, "xxx", "xxx");

}


int data()
{
 // Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
delay(10);



Blynk.virtualWrite(1, distance);


return(distance);



}







void loop()
{
    Blynk.run();
   data();
      Blynk.virtualWrite(1, distance);


}
1 Like

You don’t want to post your blynk ID and your wifi password in a public forum :wink:

@Dmitriy &co - maybe there should be a drive to put these sensitive constants into a separate .h file so they don’t get posted so much?

Hi there, This script would be excellent for my project. Im new to Blynk and coding and was trying this sketch on my esp8266-12e module with NodeMCU installed. I dont seem te get a connection with the internet with esp. Blynk app says: “your nodemcu is not in network”. I checked ssid and password and auth, and they are correct. when I put sketch from http://www.instructables.com/id/ESP8266-ESP-12Standalone-Blynk-101/ it works fine. I can toggle a relais with it. Anny suggestions on why this script is not working on my nodemcu?

Thanks already!

below my script im using:

// defines pins numbers
const int trigPin = 5;
const int echoPin = 6;
// defines variables
long duration;
int distance;
float h;


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>


char auth[] = "xxx";


void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600); // Starts the serial communication
  Blynk.begin(auth, "xxx", "xxx");

}


int data()
{
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);
  delay(10);



  Blynk.virtualWrite(1, distance);


  return (distance);



}


void loop()
{
  Blynk.run();
  data();
  Blynk.virtualWrite(1, distance);


}

Hi guys, I got script working. Rookie mistake, power supply didn’t suply enough current. Used a lolin base board and its working fine now.