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

LED and LCD widgets


#30

The code for each subroutine can go in a single timer.

Just do what PushData does but with your code.

The 1s (1000ms) in PushData can be 100ms (or less if you need it) but you can’t run functions a thousand times a second in loop().


#31

@Costas

I think and sleep about this, perhaps I come back to you tomorrow. Thanks for your assistance!


#32

@Costas

Can you please show me as an example with my code on the top how to set an simple timer for one subroutine?
Is simple timer always with V5?

Further where do i get the ethernet.h?


#33

@Tom Just so you are aware, there are many resources available on all of your questions… @Costas, bless him, can be the epitome of helpful, just don’t wear him out :smile:

You can also find good examples of how to use SimpleTimer, LEDs and LCDs in the example pages:

http://examples.blynk.cc/

A good one for SimpleTimer would be GettingStarted/PushData. And the LED/LCD examples are clearly labeled as such.

And searching this forum can provide many answers and example code snippets.

That file is part of the default libraries that come with your Arduino IDE installation… you shouldn’t need to download anything, just include it in your sketch: #include <Ethernet.h>


#34

@Gunner

Sorry for all my questions, but i am realy new in blynk and programming, but i want learn.

My program, please find on the top is running, but alway disconnecting. Costas told me i should need an simple timer.

As i understand him rim, i need for each subroutne one timer, but i do not know how the code should look like.

char auth[] = “***************";
char ssid[] = "";
char pass[] = "
”;

WidgetLED led1(V2);//
WidgetLED led2(V3);//
WidgetLCD lcd(V4);

void setup()
{
Serial.begin(1152000);
Blynk.begin(auth, ssid, pass);

pinMode(13,OUTPUT); //
pinMode(4,INPUT_PULLUP);
}

BLYNK_WRITE(V1)
{
if (param.asInt() == 0)
{
digitalWrite(13, LOW); //GPIO13
}
else
{
digitalWrite(13, HIGH); // GPIO13
}
}

// Magnetic Sensor

void checkPin()
{
if (digitalRead(4)) // GPIO4
{
led1.off();
led2.off();

} else {
led1.on();
led2.on();
}
}

// Magnetic Sensor

void garageMagSensor ()
{
int garageSensorSW = digitalRead(4); // GPIO4
if (garageSensorSW == LOW)
{

lcd.print(1, 0, “GARAGE IS CLOSED”); // LCD print, column 1, row 0.

}
else
{
lcd.print(1, 0, “GARAGE IS OPEN”); // LCD print, column 1, row 0
}
}

void loop()

{
Blynk.run();
garageMagSensor();
checkPin();
}


#35

We all start off new to Blynk, and even programming (I have only been here just over 2 months)… but we all also had to familiarize ourselves with the >DOCs<, the search option and of course GOOGLE :wink:

We will help, but you are your own best teacher. Look at the examples I pointed out in order to understand Simple Timer… then you will better understand how to merge it with your own code. We can’t (or won’t) always write your code for you.

Here is another quick, but VERY important lesson… when posting ANY code, please format it properly as instructed in the >Welcome Post<. using the backquote key (3 times before and 3 times after your code):


#36

@Gunner

thanks for the hint regarding posting a code.

Please trust, i read a lot in google or the docs, and every evening i spent time for learning and testing.

Please see, do i need to prepare void Timer1, void Timer2 and void Timer 3? Each includes the code for my normal subroutine?


#37

Look how PushData works at https://github.com/blynkkk/blynk-library/blob/master/examples/GettingStarted/PushData/PushData.ino (it is also in the examples of your IDE against Blynk).

These 3 lines in the PushData sketch are only required if you are using Ethernet to connect to Blynk:

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

A few examples for an ESP connection can be found at Blynk for Beginners and help with your project


#38

@Costas

what do you think do i right?

#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>


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

WidgetLED led1(V2);//
WidgetLED led2(V3);//
WidgetLCD lcd(V4);



SimpleTimer MagneticSensorTIMER;
SimpleTimer checkPinTIMER;



void setup()
{
Serial.begin(1152000);
Blynk.begin(auth, ssid, pass);

pinMode(13,OUTPUT); //
pinMode(4,INPUT_PULLUP);

MagneticSensorTIMER.setInterval(1000L, magnetic);
checkPinTIMER.setInterval(1000L, checkPin);



}

BLYNK_WRITE(V1)
{
if (param.asInt() == 0)
{
digitalWrite(13, LOW); //GPIO13
}
else
{
digitalWrite(13, HIGH); // GPIO13
}
}

// Magnetic Sensor

void checkPin()
{
if (digitalRead(4)) // GPIO4
{
led1.off();
led2.off();

} else {
led1.on();
led2.on();
}
}

// Magnetic Sensor

void magnetic ()
{
int garageSensorSW = digitalRead(4); // GPIO4
if (garageSensorSW == LOW)
{

lcd.print(1, 0, "GARAGE IS CLOSED"); // LCD print, column 1, row 0.

}
else
{
lcd.print(1, 0, "GARAGE IS OPEN"); // LCD print, column 1, row 0
}
}

void loop()
{
Blynk.run();
MagneticSensorTIMEr.run();
checkPinTIMER.run()
}

#39

Not quite… more like this

But instead of posting your code, again, please just EDIT your last posts.


#40

Few points:

  1. I think you are using ESP, not Ethernet, so your libraries are all wrong.
  2. Most people just use timer but for you I would use a single instance called GarageTimer.
  3. So not 2 (MagneticSensorTimer and checkPinTimer) but just one GarageTimer.
  4. Create the function GarageTimer and put all the MagneticSensor and checkPin code in there.

Make the mods and post your revised code.


#41

And check your spelling, no little r in TIMER :wink:

Also, while you don’t appear to be using the serial monitor… you have an extra 0 in the BAUD rate :slight_smile: should be only 115200


#42

@Tom for reference with each instance of SimpleTimer i.e. GarageTimer you can have up to 10 functions / subroutines. In your case I think you only need one function / subroutine but has you develop your projects you will need more functions / subroutines but not normally more than one instance of SimpleTimer unless it is a very complex project.

So an example of the lines required for general use of SimpleTimer, with all the Blynk stuff excluded would be:

// Blynk libraries for your specific connection method go here

#include <SimpleTimer.h>

SimpleTimer GarageTimer

void setup() {
  // put your Blynk connection code here
  
  GarageTimer.setInterval(1000L, function1); // do something at 1s intervals
  GarageTimer.setInterval(5000L, function2); // do something at 5s intervals
  // more functions / subroutines if required
  GarageTimer.setInterval(30000L, function10); // do something at 30s intervals
}

void function1(){
  // some code here
}

void function2(){
  // some code here
}

void function10(){
  // some code here
}


void loop() {
  // normally just Blynk.run() here
  GarageTimer.run()
}

You wouldn’t use names like function1, function2 though, obviously something meaningful based on what the function does.


#43

@Costas

And now?

Regarding V5, what i have to set to V5 in Blynk App?
LCD Display i have to set for PUSH, but only LCD?

#include <SimpleTimer.h>


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

WidgetLED led1(V2);//
WidgetLED led2(V3);//
WidgetLCD lcd(V4);



SimpleTimer GarageTIMER;

/////////////////////////setup////////////////////////////////////////////

void setup()
{

Serial.begin(1152000);
Blynk.begin(auth, ssid, pass);

pinMode(13,OUTPUT); //
pinMode(4,INPUT_PULLUP);

GarageTIMER.setInterval(1000L, sensorcheck);

}

BLYNK_WRITE(V1)
{
if (param.asInt() == 0)
{
digitalWrite(13, LOW); //GPIO13
}
else
{
digitalWrite(13, HIGH); // GPIO13
}
}

/////////////////////////sensorcheck////////////////////////////////////////////

void sensorcheck()
{
if (digitalRead(4)) // GPIO4
{
led1.off();
led2.off();

} else {
led1.on();
led2.on();
}


{
int garageSensorSW = digitalRead(4); // GPIO4
if (garageSensorSW == LOW)
{

lcd.print(1, 0, "GARAGE IS CLOSED"); // LCD print, column 1, row 0.

}
else
{
lcd.print(1, 0, "GARAGE IS OPEN"); // LCD print, column 1, row 0
}

blynk.virtualWrite(V5, millis() / 1000); //do i need this line, and what is V5 in Blynk App?

}


/////////////////////////loop////////////////////////////////////////////

void loop()

{
Blynk.run();
GarageTIMER.run()
}

#44

You don’t need the V5 it is just an example. In the example sketch you would have a value display widget on V5 and it would update (like a clock) every second. Comment it out.

Your sketch looks much better but you are missing all your Blynk libraries.


#45

@Costas

okay i will add the libaries and then i hope it runs.

Regarding V5, so i can remove the following line?

blynk.virtualWrite(V5, millis() / 1000);


#46

Yes that line can be removed. For reference everything is case sensitive so Blynk.virtualWrite not blynk.virtualWrite.


#47

Thank you Costas. I will try i will report in the evening.


#48

@Tom as pointed out by @Gunner don’t forget to change the baud from 1152000 to 115200.


#49

@Costas

Can you tell me what is my problem?

Garage_1:116: error: expected ‘}’ at end of input
}
^
exit status 1
invalid conversion from ‘void (*)()’ to ‘int’ [-fpermissive]