Blynk app or 'if' statements being ignored

I am trying to control a 4chan relay with an Adafruit ESP8266 Feather Huzzah, and am trying to use old code that I once ran on an Arduino Mega. My old code is on my Git HERE and HERE, the latter being more abbreviated, but the former actually having the function I am trying to now use. The function that is troubling me is supposed to be initiated by the Blynk app and receive an int in the range of 0-16 and use that int to multiply a preset length of milliseconds and hold a digital pin HIGH for that duration. The problems are that the ‘if’ statements are being ignored and the executable lines inside the curly braces are just being executed. Through all of the edits I’ve made, I’ve had varying degrees of the same problem and I can’t get past this block. I also don’t know if this is a question for Blynk, Arduino or maybe even Adafruit/ESP, but I’m trying Blynk first.

Some instances, the project waits for the first commands from blynk app before beginning the never ending loop while other times it just gets right into that loop. I don’t know why this code performed flawlessly on another Arduino board using Blynk 1.0, but now it’s not. I’m doing my best to articulate my problem without being over or under informative, so please forgive any lack of clarity.

Ideally, the project will receive the int when the button on another Vpin becomes true and perform the time based math operation and exit and stay idle until another set of commands is received from the Blynk app. Now, for the most part, the Blynk app isn’t instigating that process which is what I’m hoping to achieve.

TYIA for your time!

#define BLYNK_TEMPLATE_ID           "TMPLWzp-edHg"
#define BLYNK_DEVICE_NAME           "Test"
#define BLYNK_AUTH_TOKEN            "XXXXyyyyZZZZ"
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Mike-N";
char pass[] = "password";

WidgetTerminal terminal(V10);
BlynkTimer timer;

#define TURN_ON HIGH // TURN_ON and TURN_OFF are defined to account for Active LOW relays
#define TURN_OFF LOW  // Used to switch relay states for on/off of 120VAC~ devices 
#define feedRelay 4           //Digitial Pin
#define ROrelay 5             //Digitial Pin
#define RelayPin3 2           //Digitial Pin
#define RelayPin4 16          //Digitial Pin

boolean runningRO = false;
int msPerQuart = 5454; //ms per Quart
int ROstart;            //Start of count
int countQuarts;        //Total Quarts from Blynk times msPerQuart

int button = 0;       //V0
int ROpumpOn = 0;     //V1
int totalQuarts = 0;  //V2
int feedPumps = 0;    //V3

BLYNK_WRITE(V0) { //Test red LED on ESP8266
  button = param.asInt();  
BLYNK_WRITE(V1) { //triggers the RO countdown
  ROpumpOn = param.asInt();  // ROpump remote
BLYNK_WRITE(V2) { //number of quarts ordered from app
  totalQuarts = param.asInt();  // ROpump remote
BLYNK_WRITE(V3) { //button to activate all feed pumps
  feedPumps = param.asInt();

void ROcheck()  //RO Pump = 34 seconds on time per gallon
  if (V1 == 1 && runningRO == false)  // Activates when Blynk button is toggled
    Serial.println("First IF statement");
    digitalWrite(ROrelay, TURN_ON);
    runningRO = true;
    ROstart = millis();
    countQuarts = msPerQuart * totalQuarts;  // Calculates length of runtime 
    terminal.println(" Quarts of RO");
  if (millis() - ROstart > countQuarts && runningRO == true)  // Ends Runtime
    runningRO = false;
    countQuarts = 0;
    ROstart = 0;
    digitalWrite(ROrelay, TURN_OFF);
    Blynk.virtualWrite(V1, 0);    //ROpumpOn
    Blynk.virtualWrite(V2, 0);    //totalQuarts
    Serial.println("Second IF Statement");
    terminal.print("Finished Pumping:");
    terminal.println(" Quarts of RO");
void setup()
  Blynk.begin(auth, ssid, pass);
  pinMode(feedRelay, OUTPUT);
  pinMode(ROrelay, OUTPUT);
  pinMode(RelayPin3, OUTPUT);
  pinMode(RelayPin4, OUTPUT);
  digitalWrite(ROrelay, TURN_OFF);
  Blynk.virtualWrite(V0, 0);      //button
  Blynk.virtualWrite(V1, 0);      //ROpump
  Blynk.virtualWrite(V2, 0);      //Number of Quarts
  timer.setInterval(1000L, ROcheck);

void loop()

3 posts were merged into an existing topic: Is there error in my logic?