Blynk doesn't connect with this code. If instead of timer I use a delay it works (Ik its wrong)

I want to make it work with timers. This doesn’t even connect to blynk.

  • Arduino Uno
  • Voltage Sensors (If voltage > 8 set V0 to 1) (Alarm system)
  • Relay module (BLYNK_WRITE functions)
  • ENC28J60 ethernet module
//#define BLYNK_DEBUG        // Optional, this enables more detailed prints
//#define BLYNK_PRINT Serial

#define BLYNK_TEMPLATE_ID "XXXXXXXXXXXXXXX"
#define BLYNK_DEVICE_NAME "XXXXXXXXXXXXXXXXXXX"
#define BLYNK_AUTH_TOKEN "XXXXXXXXXXXXXXXXXXXXXXxxxxx"

#include <UIPEthernet.h>
#include <BlynkSimpleUIPEthernet.h>

BlynkTimer timer;
char auth[] = BLYNK_AUTH_TOKEN;

double value = 0;
double voltage1 = 0;

BLYNK_WRITE(V3) {
  int value = param.asInt();
  if (value == 1) {
    digitalWrite(5, HIGH);
  } else {
    digitalWrite(5, LOW);
  }
}

BLYNK_WRITE(V5) {
  int value = param.asInt();
  if (value == 1) {
    digitalWrite(7, HIGH);
  } else {
    digitalWrite(7, LOW);
  }
}

void setup() {

  pinMode(5, OUTPUT);
  pinMode(7, OUTPUT);
  digitalWrite(5, HIGH);
  digitalWrite(7, HIGH);

  timer.setInterval(1000L, pushStatus);

  Serial.begin(115200);
  Blynk.begin(auth);

}

void pushStatus(){
  int voltage = (value * 5.0) / 1024.0;
  Blynk.virtualWrite(V0, voltage/0.2 > 8);
}

void loop() {
  value = analogRead(A0);
  Blynk.run();
  timer.run();
}

Blynk C++ Library version?

Pete.

Manuel.

I’d move this line to the top of your pushStatus() function so that you aren’t trying to unnecessarily read your analog pin thousands of times per second.

If you’re still having issues the share your serial output for this sketch, along with the sketch and serial output where you’ve successfully used a delay instead of BlynkTimer.

Pete.