# How to manipulate input numbers

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

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

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

In your sketch itâ€™s simply:

``````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?

1 Like

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

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.

1 Like

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

Worse than before.

Never use delay() in loop().

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

@AussieNinja and use this method to format posted code hereâ€¦ not [ ]

1 Like

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();
}
``````

Thanks Gunner

1 Like

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â€ť.

@AussieNinja ok the name for your time is SparkCorePolledTimer

See this sketch for itâ€™s use Particle Photon + DS18B20 with Blynk

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();
}
``````

You need to locate the library from Photon GitHub.

1 Like

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

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/

1 Like