Blynk timer no luck

First thanks for any help. I have looked at the examples but they do not really work for me. I have tried to set a timer but it appears not to have been set up properly.

  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  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
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

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

 *************************************************************

  Output any data on LCD widget!

  App project setup:
    LCD widget, switch to ADVANCED mode, select pin V1
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define TRIGGERPIN D1
#define ECHOPIN    D2
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "c48e77b790e64b05adf1ee77fb4dbb40";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

WidgetLCD lcd(V1);

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 3000); //was 1000
}

void setup()
{
  // Debug console
  Serial.begin(9600);
pinMode(TRIGGERPIN, OUTPUT);
  pinMode(ECHOPIN, INPUT);
  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);

  lcd.clear(); //Use it to clear the LCD Widget
  lcd.print(0, 0, "Distance in cm"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  // Please use timed events when LCD printintg in void loop to avoid sending too many commands
  // It will cause a FLOOD Error, and connection will be dropped

timer.setInterval(5000L, myTimerEvent);
}


void loop()
{
  void mytimerEvent()  ;{
  lcd.print(0, 0, "Sump depth in cm"); // use: (position X: 0-15, position Y: 0-1, "Message you want to print")
  long duration, distance;
  digitalWrite(TRIGGERPIN, LOW);  
  delayMicroseconds(6); 
  
  digitalWrite(TRIGGERPIN, HIGH);
  delayMicroseconds(14);
  
  digitalWrite(TRIGGERPIN, LOW);
  duration = pulseIn(ECHOPIN, HIGH);
  distance = 68-(duration/2) / 29.1;
  Serial.print(distance);
  Serial.println("Cm");
  lcd.print(7, 1, distance);
  Blynk.run();
  }
timer.run(); // Initiates BlynkTimer
  

}


1. Search forum for similar topics
2. Check http://docs.blynk.cc and http://help.blynk.cc/
3. Add details : 
• Hardware model + communication type. For example: Arduino UNO with Ethernet Shield
• Smartphone OS (iOS or Android) + version
• Blynk server or local server
• Blynk Library version 
• Add your sketch code. ☝**Code should be formatted as example below.**

Simply paste your code between ``` If you don't format your code, your topic can be deleted by moderators.

```cpp

void loop()

@sladecolin Am a newbie myself to both c and blynk.

You’ve declared mytimerEvent() in loop(). Why? Best to keep loop() simple. Just have blynk.run(); timer.run(); in loop(). Handle everything else outside either in setup or defined routines that are invoked by timer in the setup().

Move the set of statements that print to lcd as a call say write_sump_depth() {…} . Setup this routine to be called by the timer e.g timer.setInterval(1000L, write_sump_depth); in setup().

As @Costas and @Gunner keep saying, keep the loop simple and to the bare minimum.

1 Like

Thanks I am definitely missing something. Not yet ready to give up…, but…

Can someone post a sample script that is fully functioning so I can see how timer works. Just trying to get my head is the right space.

Am I the only one that is having issues with tutorials or samples that demonstrate a concept. ?

As stated in the Blynk Documentation, BlynkTimer is based on SimpleTimer which is also well documented here

https://playground.arduino.cc/Code/SimpleTimer#Functions

And in those same Blynk doc files there is a link to a simple example… (also found in the Sketch Builder under Push Data)

In you sketch, you assign/declare the timer…

BlynkTimer timer;

In your setup() you assign one or more timers…

timer.setInterval(1000L, myTimerEvent);

And each timer can call a function or “loop()” when the timer indicates…

void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
}

Thanks
So it I run this script what will happen? or does more needed to be added.

Gunner I appreciate the responses,

It displays the up-time in seconds on a Display Widget set for virtual pin 5

Only if you want to do more than watch the time fly by :stuck_out_tongue_winking_eye:

Thanks
for now quite happy to watch the time fly by. Added 2nd timer and it works, here is code for future users.

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  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
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  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 shows how value can be pushed from Arduino to
  the Blynk App.

  NOTE:
  BlynkTimer provides SimpleTimer functionality:
    http://playground.arduino.cc/Code/SimpleTimer

  App project setup:
    Value Display widget attached to Virtual Pin V5
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
}
void myTimerEvent2()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V6, millis() / 1000);
}

void setup()
{
  // Debug console
  Serial.begin(9600);

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

  // Setup a function to be called every second
  timer.setInterval(5000L, myTimerEvent);
   timer.setInterval(1000L, myTimerEvent2);
}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer
}
1 Like

At least change the 5 second display one to display something different :slight_smile: Try the RSSI signal strength…

void myTimerEvent()
{
  Blynk.virtualWrite(V5, WiFi.RSSI());
}

Nice my options are slowly growing!

1 Like

Soon, you could have one with a few more displays, etc :stuck_out_tongue:



Its not working for me

@Dharmendra_Vishwakar this is a two year old topic and @sladecolin hasn’t been seen on the forum since 28th February last year.

even if is was a current topic, simply saying

isn’t very helpful. I’s a bit like posting on an automotive forum and saying “my car won’t start”.

If you share information about exactly what hardware you are trying to use, what steps you’ve taken, what results you get when you compile and upload the code and what you see in the serial monitor then forum members may be able to assist.

Pete.