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

Water level indicator

#1

hello have a water level indicator works great with normal arduino but if I code to transfer to blynk the code does not work you can tell me why did not work did that as done in the video with normal arduino want to connect it now with blynk but it works not with blynk https://www.youtube.com/watch?v=yXjp6RVmP-k&t=103s

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Fishino.h>
#include <BlynkSimpleFishino.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "93bcb26e56384f7d53c4f";
BlynkTimer timer;
int level2=A2;
int level3=A3;
int level4=A4;
int level5=A5;
int b;
int c;
int d;
int e;
int r;
int z=111;
WidgetLED led1(V1);
void setup()
{
pinMode(level2,INPUT);
pinMode(level3,INPUT);
pinMode(level4,INPUT);
pinMode(level5,INPUT);
  Serial.begin(9600);
Blynk.begin(auth, "veh", "54923");

  timer.setInterval(82L, Messungbox);
}
void Messungbox(){
b=analogRead(level2);
c=analogRead(level3);
d=analogRead(level4);
e=analogRead(level5);  
if(e>z && d>z && c>z && b>z){
  led1.on();
}
else if(e<z && d>z && c>z && b>z){
  
}
else if(e<z && d<z && c>z && b>z){
 
}
else if(e<z && d<z && c<z && b>z){

}
else if(e<z && d<z && c<z && b<z){
 led1.off();
}
}
void loop()
{
  Blynk.run();
   timer.run();
}
0 Likes

#2

Hello Markop,

You should use following command for sending variables to your Blynk App:

Blynk.virtualWrite(V0, newValue);

0 Likes

#3

First of all, I’d stop trying to take readings every 82 milliseconds. I’m sure you don’t need to read the water level 12 times per eco s, and trying to write to the Blynk LED that quickly will cause server flooding problems.

Second, have verified that your board is actually connecting to Blynk and that you can toggle the virtual LED using simpler code?

Third, try adding-in some Serial.print statements to print the values of b, c, d, e and z, and print the LED status to the serial monitor as well. You may have different values that you expect, and that could be causing your ‘if’ statement to behave in a way that you’re not expecting. I assume that you plan to add more Blynk LEDs, or a Level widget once you have this working? If not, then you should simplify the if statements.

Pete.

0 Likes

#4

so this is not as easy as with a normal arduino the 82 were just for the test purposes

0 Likes

#5

Sorry, I’m not sure I understand the question.

Pete.

0 Likes

#6

blynk does not behave like a normal arduino

0 Likes

#7

An ‘Arduino’ is a type of microprocessor board, Blynk is an IoT software library. They are two totally different things.

When you’re writing C++ code to run on an Arduino or ESP8266 board then you can get away with a lot of bad practices, such as using blocking commands like delay() and putting all of your code in the void loop.
You can’t do this with IoT systems, as they need to be constantly communicating with the server (because they need to know if a button on the app has been pressed for example). You get around this by using timers (as you’ve done in your sketch) but you also need to be careful about what you do in those timed routines to ensure that you don’t stave Blynk of processor time, or that you don’t try to send data out to Blynk too often. An LCD display doesn’t really care if you write “Hello World” to it a thousand times per second. It’s obviously bad practice, because you only need to write the text once and it stays there, but some people insist on blasting the data at the device simply because they are too lazy to do it any other way.
Sending data to the Blynk server has overheads in terms of internet traffic, and server processing time, so the server limits how often data can be sent. If you exceed more than about 10 writes per second then some or all of those commands will be ignored.

Pete.

1 Like