Nodemcu + SKU:_SEN0257 water pressure sensor

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);

}

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.

Thank you so much for the help Mr. Knight!

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.

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

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

1 Like

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.

Thank you for the help!

It works!

Nice project David_Gronlundi have wemos D1 i insert the code , its connect with blynk its fine ,but on V2 i have continuous value 1682.84 .
Its not change . Here is the code .

#define BLYNK_PRINT Serial

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

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

const float  OffSet = 0.788 ;

float V, P;

BlynkTimer timer; 

void setup()
{
  Serial.begin(9600);        
  Serial.println("/** Water pressure sensor **/");
   Blynk.begin(auth, ssid, pass);
  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
}





Please let me know where is mistake and mi sensor is sku-sen0257 thanks

How have you connected the three wires on the sensor to your MCU?

Is your MCU a D1v1, D1v2, D1 Mini or D1 Mini Pro?

Pete.

WeMos D1 R2 ver 2.1 i connect +5 and A0 .
On the value display if I put the pin analogic A0 the value is oscillating or is changing room 140 .
When I blow the value is changed to 160 - + of course.

But if I change the pin on the blink app to V2 it’s freeze to 1,600 it’s not changing.

No GND connection?

The D1 R2 has an ADC that allows a maximum input voltage of 3.2v
The sku-sen0257 has an output voltage on the signal pin of between 0.5 and 4.5v

This means that if your sku-sen0257 is outputting anything over 3.2v then it will produce a reading of 1023 from the ADC.
It looks like you need a voltage divider on your analog input to make this sensor work correctly with your board.

Pete.

Yes of course he’s have gnd