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

LED and LCD widgets

Taking the examples that are built in to your Smartphone:

lcd.print(4, 0, “Hello”);
lcd.print(4, 1, “World”);

Line 0 Hello___
Line 1 World__

4 is the fifth character along the LCD display from left to right starting at position 0.

@Costas

Great, i understand…very simple :wink:

Most things in Blynk are quite simple compared with working with real components like LCD’s, LED and buttons etc.

Don’t forget that each widget has in built usage assistance with links to sample sketches. Just press the i for information icon.

@Costas

One question, do you know if each GPIO of the ESP8266 has an integrated pull up?

Yes they do except GPIO 16 which has an internal pull down resistor.

What are you planning to build?

Okay, so all GPIO´s of the ES8266 have integrated pull up resistor only 16 has pull down.

I want to use magnetic contact for my garage door. One on the top and one of the bottom If no one is closed the door is not open and not close.

@Costas

Hi, can you tell me why my NODEMCU is alway disconnecting and connection in a loop?

define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “********************”;

// Your WiFi credentials.
// Set password to “” for open networks.
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();

}

This is the reason for your disconnects. You are looping through the functions far too fast.
Look at the PushData example to see how we call functions at timed intervals with the essential SimpleTimer library.

@Costas

Do I need for each subroutine one timer?

Is it possible that you can help me here?

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().

@Costas

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

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

@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>

@GunnerTechTools

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

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

1 Like

@GunnerTechTools

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?

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

@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()
}

Not quite… more like this

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

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.