Timers
How to use timers in code
sensorData = analogRead(A0); // this is an example of reading sensor data
Blynk.virtualWrite(V5, sensorData);Use Timers
// Declaring a global variabl for sensor data
int sensorVal;
// This function creates the timer object. It's part of Blynk library
BlynkTimer timer;
void myTimer()
{
// This function describes what will happen with each timer tick
// e.g. writing sensor value to datastream V5
Blynk.virtualWrite(V5, sensorVal);
}
void setup()
{
//Connecting to Blynk Cloud
Blynk.begin(auth, ssid, pass);
// Setting interval to send data to Blynk Cloud to 1000ms.
// It means that data will be sent every second
timer.setInterval(1000L, myTimer);
}
void loop()
{
// Reading sensor from hardware analog pin A0
sensorVal = analogRead(A0);
// Runs all Blynk stuff
Blynk.run();
// runs BlynkTimer
timer.run();
}Last updated
Was this helpful?

