Nodemcu v1 using blynk

What does your serial monitor say?

Update it to my example above.

Whoops!! You’re missing the important bit…

timer.run(); // run the timers! 

Thanks for the tip i will try it and let you know

Thank you guys for the great support @Jamin @Gunner the code is working like charm
i will post it here in case somebody need it

/**************************************************************
   Blynk is a platform with iOS and Android apps to control
   Arduino, Raspberry Pi and the likes over the Internet.
   You can easily build graphic interfaces for all your
   projects by simply dragging and dropping widgets.

     Downloads, docs, tutorials: http://www.blynk.cc
     Blynk community:            http://community.blynk.cc
     Social networks:            http://www.fb.com/blynkapp
                                 http://twitter.com/blynk_app

   Blynk library is licensed under MIT license
   This example code is in public domain.

 **************************************************************
   This example runs directly on ESP8266 chip.

   You need to install this for ESP8266 development:
     https://github.com/esp8266/Arduino

   Please be sure to select the right ESP8266 module
   in the Tools -> Board menu!

   Change WiFi ssid, pass, and Blynk auth token to run :)

 **************************************************************/

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

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SSD1306_LCDHEIGHT 64

#define OLED_RESET LED_BUILTIN  //4
Adafruit_SSD1306 display(OLED_RESET);

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

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

void setup()
{
  display.clearDisplay();
  pinMode(13, OUTPUT);
  Serial.begin(115200);
  Blynk.begin(auth, "ssid name", "pass");
}
void actionRelays()
{
  relay1_ON(); // turn on relay1
  timer.setTimeout(1000, relay2_ON); // delay 2sec then turn on relay2
  sendOLED();
  timer.setTimeout(5000, relays_OFF); 
  timer.setTimeout(5000, relays_OFF);// delay 15sec from first action and turn off both relays

  timer.setTimeout(5000, sendOLED);
  timer.setTimeout(5000, screen_clear);
}

void screen_clear()
{
   display.clearDisplay();
  display.display();
  }

void relay1_ON()
{
  digitalWrite(13, LOW); // turn on relay1
  Blynk.virtualWrite(V10, 255); // turn on an LED widget (optional)
}

void relay2_ON()
{
  digitalWrite(13, HIGH); // turn on relay2
  Blynk.virtualWrite(V20, 255); // turn on an LED widget (optional)
}
void relays_OFF()
{
  digitalWrite(13, LOW); // turn off relay2
  Blynk.virtualWrite(V20, 0); // turn off an LED widget (optional)
}


void sendOLED()
{

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.display();

  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println("Hello from:");
  display.print("Door is Open ");
  display.display();
  display.startscrollright(0x00, 0x0F);
 

}

BLYNK_WRITE(V7)
{
  if (param.asInt() == 1 )
  {
    actionRelays();
    // oled();
    // sendOLED();
  }
}



void loop()
{
  Blynk.run();
  timer.run();
  display.clearDisplay();
}

1 Like

Thanks for sharing, I’m using the same and would like to know if its possible to add variable for the delay?

timer.setTimeout(5000, relays_OFF);// delay 15sec from first action and turn off both relays

I’d like to use the slider widget attached to V0 to take a time input in minutes converted to seconds for user by the timer

BLYNK_WRITE(V0){   // add a slider on V0 range 0 to 30 (minutes)
  Countdown = param.asInt();  // set variable as Slider value
  Serial.print("V0 Slider value is: ");
  Serial.println(Countdown);
  CountdownValue=(Countdown*60000);
  Serial.print("CountdownValue will be: ");
  Serial.println(CountdownValue);

You almost had it right. Try this instead.

BLYNK_WRITE(V0){   // add a slider on V0 range 0 to 30 (minutes)
  long CountdownValue = param.asInt() * 60000;  // take slider input and times by 60k to get millisecs
  Serial.print("V0 Slider value in mins: ");
  Serial.println(param.asInt());
  Serial.print("V0 Slider value in seconds: ");
  Serial.println(CountdownValue / 1000);
  Serial.print("Timer value in millisecs will be: ");
  Serial.println(CountdownValue);
  yourCustomTimer = timer.setTimout(CountdownValue, yourFunctionHere); // do you normal simpleTimer setup here using the same ID = yourCustomTimer 

Thanks @Jamin. Thats done it.

1 Like