BLYNK

# How to manipulate input numbers

#1

Hi there, I would like to manipulate the input from a generic pressure sensor so that it shows me the percentage/Metres of water left in a tank. i think you will need to Divide the input voltage by 25, and then minus 20 to convert from the input volts to how many metres it is below the surface.
Thankyou,
Simeon

#2

I hate math… so almost afraid to ask But… what is your Blynk related question then??

#3

So, At the moment when I setup the app to the photon and put a guage on the pin I have connected to the pressure sensor (A4), it goes to a number between 0-4095 but I want to try and divide that number by 25 and minus 20 so that the number becomes how many metres of water are above the sensor. After I do that I can calibrate it to tell me when a tank is getting low
I hope that makes sense,
Simeon

#4

``````float pressureSensor;  // could be int if you wanted
float waterLevel;

waterLevel = (pressureSensor / 25.0) - 20.0;
Blynk.virtualWrite(Vx, waterLevel);
``````

Is this what you were asking?

#5

Thank you so Much,
is This something like what it should look like

``````int pressuresensor = A4;
float pressureSensor;  // could be int if you wanted
float waterLevel;

#define BLYNK_PRINT Serial

#include <blynk.h>
char auth[] = "Auth Code";
void setup()
{
Serial.begin(9600);
delay(5000);

Blynk.begin(auth);
}
BLYNK_WRITE(V1) {

waterLevel = (pressureSensor / 25.0) - 20.0;
Blynk.virtualWrite(Vx, waterLevel);
}
}

void loop()
{
Blynk.run();
}
``````

Thanks once again,
Simeon

#6

Not like that.

1. Vx should be V2 or V3 or V4 etc i.e. the virtual pin number of the widget that you want to see the water level in.

2. You need to use BlynkTimer (aka in Arduino world as SimpleTimer and not related to any Blynk timer widgets) as shown in PUSH_DATA example to call a function at say 3s intervals. This function will include what you have inside BLYNK_WRITE(V1).

3. Costmetic but I don’t like your choice of variable names, I would use pressuresensorPin for A4.

Which MCU are you using?

Try a quick re-write of what you learn from PUSH_DATA and provide feedback.

#7

does this look OK

``````int pressuresensorPin = A4;
float pressureSensorPin;  // could be int if you wanted
float waterLevel;

#define BLYNK_PRINT Serial

#include <blynk.h>
char auth[] = "Auth Code";
void setup()
{
Serial.begin(9600);
delay(5000);

Blynk.begin(auth);
}
BLYNK_WRITE(V1) {

waterLevel = (pressureSensorPin / 25.0) - 20.0;
Blynk.virtualWrite(V1, waterLevel);
}

void loop()
{
Blynk.run();
delay(300);
}
``````

#8

Worse than before.

Never use delay() in loop().

You need several parts of PUSH_DATA in your sketch like `timer.run()` in loop().

#9

@AussieNinja and use this method to format posted code here… not [ ]

#10

Hi, I am using the Particle Photon and the particle web IDE,
Is this any better
Simeon

``````int pressuresensorPin = A4;
float pressureSensorPin;
float waterLevel;

#define BLYNK_PRINT Serial

#include <blynk.h>
char auth[] = "Auth Code";

BlynkTimer timer;

void myTimerEvent()
{
Blynk.virtualWrite(V1, millis() / 1000);
}

void setup()
{
Serial.begin(9600);

Blynk.begin(auth);

timer.setInterval(1000L, myTimerEvent);
}
BLYNK_WRITE(V1) {

waterLevel = (pressureSensorPin / 25.0) - 20.0;
Blynk.virtualWrite(V1, waterLevel);
}

void loop()
{
Blynk.run();
timer.run();
}
``````

Blynk for Beginners and help with your project
#11

Thanks Gunner

#12

You should have mentioned that in your first post as the assumption is everyone is using the mighty WeMos D1 Mini, unless stated otherwise

Now if you were using my recommended MCU your code would be about perfect, but you are not, so the code will not work.

I should have twigged you were none standard with this line `#include <blynk.h>`

I believe the Photon has it’s own version of Arduino’s SimpleTimer (BlynkTimer in your sketch).

Let me use the site’s search facility for something like “photon sparkpolltimer or some similar timer name”.

#13

@AussieNinja ok the name for your time is SparkCorePolledTimer

See this sketch for it’s use Particle Photon + DS18B20 with Blynk

#14

I just popped that <SparkCorePolledTimer.h> in there and it came up with the “No such file or directory”
should i use a timer from the particle libaries ( https://build.particle.io/libs/blynk/0.5.0/tab/BlynkTimer.cpp )
Thanks

``````int pressuresensorPin = A4;
float pressureSensorPin;  // could be int if you wanted
float waterLevel;

#define BLYNK_PRINT Serial

#include <blynk.h>

#include <SparkCorePolledTimer.h>

char auth[] = "Auth Code";

BlynkTimer timer;

void myTimerEvent()
{
Blynk.virtualWrite(V1, millis() / 1000);
}

void setup()
{
Serial.begin(9600);
delay(5000);

Blynk.begin(auth);
timer.setInterval(1000L, myTimerEvent);
}
BLYNK_WRITE(V1) {

waterLevel = (pressureSensorPin / 25.0) - 20.0;
Blynk.virtualWrite(V1, waterLevel);
}

void loop()
{
Blynk.run();
timer.run();
}
``````

#15

You need to locate the library from Photon GitHub.

#16

Is This the one???
if so ,how would i put that into my code
Thanks
Simeon

#17

You don’t put the library IN your code, you load the library into your IDE… and add the `#include` reference to that library in your code.

As to how to load libraries in Particle Web IDE… that is a question for the Particle site or forum.

https://docs.particle.io/guide/getting-started/intro/