Hello everyone this is my first time with blink,so i am beginner.
I saw this sketch which has been created by dutchman and i don;t understand some things.
I went to blynk app and i don’t know how to set the buttons.
what is the WidgetLED led1(10); //virtual led .How can i create it?
Also is necessary to create the relayVButton1 = 0; at the app or is just for nodemcu side?
//#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h> // here is the SimpleTimer library
char auth[] = "xxx"; //insert here your token generated by Blynk
SimpleTimer timer; // allocate a name (timer) to the timer
int relay1 = 7;
int relay2 = 8;
int relay3 = 9;
int button1 = 2;
int button2 = 3;
int button3 = 5;
int relayVButton1 = 0;
int relayVButton2 = 0;
int relayVButton3 = 0;
boolean relayState1 = 1;
boolean relayState2 = 1;
boolean relayState3 = 1;
boolean buttonState1 = 1;
boolean buttonState2 = 1;
boolean buttonState3 = 1;
WidgetLED led1(10); //virtual led
WidgetLED led2(11); //virtual led
WidgetLED led3(12); //virtual led
void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth); //insert here your SSID and password
timer.setInterval(600L, somefunction);
pinMode(relay1, OUTPUT);
pinMode(button1,INPUT_PULLUP);
pinMode(relay2, OUTPUT);
pinMode(button2,INPUT_PULLUP);
pinMode(relay3, OUTPUT);
pinMode(button3,INPUT_PULLUP);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
}
void somefunction()
{
buttonState1 = digitalRead (button1);
if (buttonState1 < 1 || relayVButton1 > 0)
{
relayState1 = !relayState1;
}
digitalWrite(relay1, relayState1);
buttonState2 = digitalRead (button2);
if (buttonState2 < 1 || relayVButton2 > 0)
{
relayState2 = !relayState2;
}
digitalWrite(relay2, relayState2);
buttonState3 = digitalRead (button3);
if (buttonState3 < 1 || relayVButton3 > 0)
{
relayState3 = !relayState3;
}
digitalWrite(relay3, relayState3);
if (digitalRead(relay1) == LOW) //virtual led1
{
led1.on();
}
else
led1.off();
if (digitalRead(relay2) == LOW) //virtual led2
{
led2.on();
}
else
led2.off();
if (digitalRead(relay3) == LOW) //virtual led3
{
led3.on();
}
else
led3.off();
}
BLYNK_WRITE(V4)
{
relayVButton1 = param.asInt(); // Get the state of the VButton
}
BLYNK_WRITE(V5)
{
relayVButton2 = param.asInt(); // Get the state of the VButton
}
BLYNK_WRITE(V6)
{
relayVButton3 = param.asInt(); // Get the state of the VButton
}
void loop()
{
Blynk.run();
timer.run(); // call the simple timer routine
}
Thanks Costas(your name sounds Greek name).
So.I went to: button>pin>select pin>Virtual>V4
button>pin>select pin>Virtual>V5! button>pin>select pin>Virtual>V4
and now i have 3 buttons!
The next step:I went to led>input>V10. led>input>V11. , led>input>V12.
I am correct about the buttons and the leds?
I have already downloaded the blynk library into the arduino ide and i am going to make the connection with buttons.Thanks.
I live in Athens and i know a lot of costas or Kostas ,or konstantinos.
So i saw the example and i see that nodemcu or esp8266(in reality it is the same)
have different libraries in contrast with bluetooth for example .
As i said i have already downloaded the blynk for the arduino ide.Now if just copy and paste the above sketch into the ide in order to upload it to the nodemcu,will i have problems?
Thanks for help.I will complete the project tomorrow after looking some examples!
If i have problems i will ask for help.
Have a beautiful day!!
Sir Wanek i am sorry!
Sir Costas you explained all the things very well and at first sight i understood the most you described.I will read and and post the complete sketch tomorrow.
Hello costas.Below is the code and a plan.When i tried to compile the sketch i had problems because the ide required the SimpleTimer.So i finally installed it and then i uploaded the sketch into the nodemcu, When i push the buttons nothing happens.Is like the nodemcu is dead.Also i tried to push the buttons that i created from blynk but just says light is offline.I don’t know what to do. I tried to use the blink example from libraries in order to see if the nodemcu lua works and i saw that the led is blinking.Then i uploaded the sketch which we made but after the upload nothing happens.
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h> // here is the SimpleTimer library
char auth[] = "a42623932a49458f805d465f4108f655"; //insert here your token generated by Blynk
char ssid[] = "connex-x114450";
char pass[] = "xxxxxxxx"; //insert here your SSID and password
SimpleTimer timer; // allocate a name (timer) to the timer
int relay1 = 12; //D6 from nodemcu lua refers to pin 12
int relay2 = 13; //D7 from nodemcu lua refers to pin 13
int relay3 = 14; //D5 from nodemcu lua refers to pin 14
int button1 = 2; //D4 from nodemcu lua refers to pin 2
int button2 = 4; //D2 from nodemcu lua refers to pin 4
int button3 = 5; //D1 from nodemcu lua refers to pin 5
int relayVButton1 = 0;
int relayVButton2 = 0;
int relayVButton3 = 0;
boolean relayState1 = 1;
boolean relayState2 = 1;
boolean relayState3 = 1;
boolean buttonState1 = 1;
boolean buttonState2 = 1;
boolean buttonState3 = 1;
WidgetLED led1(10); //virtual led
WidgetLED led2(11); //virtual led
WidgetLED led3(12); //virtual led
void setup()
{
Serial.begin(115200); // See the connection status in Serial Monitor
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
pinMode(relay1, OUTPUT);
pinMode(button1,INPUT_PULLUP);
pinMode(relay2, OUTPUT);
pinMode(button2,INPUT_PULLUP);
pinMode(relay3, OUTPUT);
pinMode(button3,INPUT_PULLUP);
digitalWrite(relay1, 1);
digitalWrite(relay2, 1);
digitalWrite(relay3, 1);
timer.setInterval(600L, somefunction);
}
void somefunction()
{
buttonState1 = digitalRead (button1);
if (buttonState1 < 1 || relayVButton1 > 0)
{
relayState1 = !relayState1;
}
digitalWrite(relay1, relayState1);
buttonState2 = digitalRead (button2);
if (buttonState2 < 1 || relayVButton2 > 0)
{
relayState2 = !relayState2;
}
digitalWrite(relay2, relayState2);
buttonState3 = digitalRead (button3);
if (buttonState3 < 1 || relayVButton3 > 0)
{
relayState3 = !relayState3;
}
digitalWrite(relay3, relayState3);
if (digitalRead(relay1) == LOW) //virtual led1
{
led1.on();
}
else
led1.off();
if (digitalRead(relay2) == LOW) //virtual led2
{
led2.on();
}
else
led2.off();
if (digitalRead(relay3) == LOW) //virtual led3
{
led3.on();
}
else
led3.off();
}
BLYNK_WRITE(V4)
{
relayVButton1 = param.asInt(); // Get the state of the VButton
}
BLYNK_WRITE(V5)
{
relayVButton2 = param.asInt(); // Get the state of the VButton
}
BLYNK_WRITE(V6)
{
relayVButton3 = param.asInt(); // Get the state of the VButton
}
void loop()
{
Blynk.run();
timer.run(); // call the simple timer routine
}
If you looked at recent sketches, like those on Blynk’s GitHub pages, Sketch Builder and already “in your phone” within the guidance notes for each widget in the Blynk app you will see this is now:
BlynkTimer timer;
The timer function is so fundamental to Blynking that’s it now hardcoded in the main Blynk library. SimpleTimer is not required.
Which Blynk library version are you using?
If you are using the 15 month old, bug ridden Arduino ESP8266 2.3.0 core move up to 2.4.0-rc2.
Report back and we will run the sketch here if required.