BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Nodemcu + SKU:_SEN0257 water pressure sensor

#1

Hello!

I’m kind of stuck in my project and request from all you experienced programmers.

I am currently using a Nodemcu V3 and a SKU:SEN0257 water pressure sensor connected to A0.
It works perfectly to see the pressure value through the serial monitor, but i would like to send the value to Blynk. I have setup a value display (V2) and the project connects to the Blynk server, but still no data coming to the value display.
Please assist!


#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Blynk.h>

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxx";

char ssid[] = "xxxxxxxxxxxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxxxxxxxxxxx";

const float  OffSet = 0.788 ;

float V, P;

void setup()
{
  Serial.begin(9600);        
  Serial.println("/** Water pressure sensor demo **/");
 
}
void loop()
{
  //Connect sensor to Analog 0
  V = analogRead(0) * 5.00 / 1024;     //Sensor output voltage
  P = (V - OffSet) * 400;             //Calculate water pressure

  Serial.print("Voltage:");
  Serial.print(V, 3);
  Serial.println("V");

  Serial.print(" Pressure:");
  Serial.print(P, 1);
  Serial.println(" KPa");
  Serial.println();
  Blynk.virtualWrite(V2, P);
  delay(1000);

}

0 Likes

#2

You should read this:

Moving that stuff from your void loop into a function, getting rid of the delay() and using a timer to call the function will fix the problem.

More info in this guide too:

Pete.

0 Likes

#3

Thank you so much for the help Mr. Knight!

0 Likes

#4

If you get stuck then just come back with your updated code and an explanation of what isn’t working and we’ll help you out if we can.

Pete.

0 Likes

#5

Dear Mr. Knight!
I updated the code and compiled it and it seem to be working but i cannot connect to the blynk server for some mysterious reason.
The wifi doesn’t have a password and i am sure that i wrote the correct SSID.

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Blynk.h>

char auth[] = "xxxxxxxxxxxxxxxxx";
char ssid[] = "xxxxxxxxxxxxxxxxx";
char pass[] = "";

const float  OffSet = 0.788 ;

float V, P;

BlynkTimer timer; 

void setup()
{
  Serial.begin(9600);        
  Serial.println("/** Water pressure sensor **/");
  sensorDataSend();
  timer.setInterval(1000L, sensorDataSend);
}

void sensorDataSend() 
{

  V = analogRead(0) * 5.00 / 1024;     //Sensor output voltage
  P = (V - OffSet) * 400;             //Calculate water pressure

  Serial.print("Voltage:");
  Serial.print(V, 3);
  Serial.println("V");

  Serial.print(" Pressure:");
  Serial.print(P, 1);
  Serial.println(" KPa");
  Serial.println();
  Blynk.virtualWrite(V2, P);

}

void loop()
{
  Blynk.run();
  timer.run();        // run timer every second
}

The following can be seen in the serial monitor:
03:24:19.245 -> Voltage:0.752V
03:24:19.245 -> Pressure:-14.4 KPa
03:24:19.245 ->
03:24:19.292 -> Voltage:0.752V
03:24:19.292 -> Pressure:-14.4 KPa
03:24:19.292 ->
03:24:20.315 -> Voltage:0.752V
03:24:20.315 -> Pressure:-14.4 KPa
03:24:20.315 ->
03:24:21.244 -> [30006] Connecting to 0.0.0.0
03:24:24.262 -> Voltage:0.752V
03:24:24.262 -> Pressure:-14.4 KPa
03:24:24.262 ->
03:24:24.305 -> Voltage:0.752V
03:24:24.305 -> Pressure:-14.4 KPa
03:24:24.305 ->
03:24:25.319 -> Voltage:0.752V
03:24:25.319 -> Pressure:-14.4 KPa
03:24:25.319 ->
03:24:26.244 -> [35007] Connecting to 0.0.0.0

0 Likes

#6

Hi @David_Gronlund,
Where is your “Blynk.begin(auth, ssid, pass);” line in your void setup()??

1 Like

#7

Well spotted @psoro!

It seems it was missing from the first sketch too, despite @David_Gronlund saying

I guess that this was a different version of the code?
It can get messy when you’re trying 101 different th8 gs to get something working.

The other thing I noticed is this:

This isn’t normally needed, but if you had to add it in response to a compiler messaging that it couldn’t find Blynk.h then maybe there’s also problem with the way your Blynk library is installed?

BTW, I’d prefer ‘Pete’ rather than ‘Mr Knight’ :smiley:

Pete.

0 Likes

#8

Thank you for the help!

It works!

0 Likes