Blynk with Spark Photon - Dual output control with single botton

First of all I would like to thank the team Blynk for the wonderful application and the community members for the knowledge sharing.
I am one among the newbies to both Spark Photon as well as Blynk so if I ask silly question please pardon. So here is the background of my requirment:

I have a submersible pump which turns on by two switch I mean by one switch (Push switch) I have to charge the capacitor and then the main pump switch to turn on the motor. For charging I have to press the push switch for say 1-2 sec then have to release after motor start. And to turn off the motor I just have to turn off the second switch.

So my idea is to control the pump remotely with easy possible way and at the same time cost effectively. For that I choose Spark Photon to control the relays and the Blynk for the application based mobile control.

Present Understanding:
So far I can set two GPIO with two botton one set as push mode and one as switch mode to control the pump as I do manually. Push botton will charge the capacitor and switch will turn on my motor.

I want to control the pump with one botton. I mean if I press one botton (switch mode) that will execute background events like charge the capacitor say for 2 sec — turn on the motor — turn off the capacitor charging — turn off the motor after a predefined time. Here is the graphical presentation.

So my request is how I can do it? Please suggest code and necessary modification inside blynk.

@shubhranshu for Arduino users we would use SimpleTimer but I believe the Photon has it’s own version called SparkIntervalTimer.

It is available at

As the name suggests it is a timer. So perhaps something like this:

Blynk virtual button.
It sets a flag that your capacitor needs to be on
Timer for capacitor is running in 2 second intervals
If flag was set by Blynk button turn on the capacitor.
In timer loop if already on turn off the capacitor on the next loop.
Second timer loop checking every 500 ms.
In this loop if capacitor flag was set as on turn on the motor.

Thanks for the quick replay. Can you please bit elaborate may be with some example. Being a newbie sometimes its difficult to understand the hints y myself. Once again thank you.

@shubhranshu before I can help further I need to know you can connect to Blynk with your Photon.
Once you are connected look at the github for how to use SparkIntervalTimer and then provide your sketch (formatted with the </> icon).

I can then provide sketch extracts for what you want to do. Do you have any coding experience?

Hello Costas
Yes I am able to connect Blynk with Photon and able to control digital and analog pin which basically straight forward and doesn’t need any code even. Right now I am testing everything by connecting two LED to my digital GPIO. One LED represents my capacitor switch and other motor. I can set push mode for one and switch mode for another which allowing me to control the system manually.
For SparkIntervalTimer I have flashed the firmware once and able to get the output stated on their demo but was not successful in integrating with Blynk.
And regarding my coding experience, I am basically not a coding person but I am able to use some by looking examples, demos and trial and error. But unfortunately I am not getting any similar example for Blynk-Photon-SparkIntervalTimer from where I can learn something. So may be be you can help me on this.

@shubhranshu take a look at the partial sketch below. I’m not a Photon user so some of it is guesswork.
The bits marked //** are for you to enter the required code. Not sure how critical the timings are but you could reduce the 500ms to say 250ms and change the MotorStarted == X if statements accordingly.

//** all your Blynk stuff here

#include "SparkIntervalTimer/SparkIntervalTimer.h"

// Create an IntervalTimer object
IntervalTimer CapTimer;

void setup(void) {

  // more Blynk stuff here

  CapTimer.begin(TurnOnCap, 500, hmSec);  // 500ms intervals, may need slight adjustment
  volatile int CapStarted = 0; // use volatile for variables shared with ISR
  volatile int MotorStarted = 0;
// functions called by IntervalTimer should be short, run as quickly as
// possible, and should avoid calling other functions if possible.

void TurnOnCap(void) {  // Callback for Timer 1
  if(CapStarted == 1){
    MotorStarted++;  // Cap has started sometime in the last 500ms
    if(MotorStarted == 2){  // second pass so capacitor has been on for at least 500ms
      //** Photon code here to turn the motor on
    if(MotorStarted == 5){ // cap has been on for at least 2 seconds so it can be turned off
      //** Photon code here to turn the capacitor off
      CapStarted = 0; // reset Cap flag      

BLYNK_WRITE(V0)   // this Blynk function tied to a button in SWITCH mode on virtual pin 0 starts the CapTimer
  int CapOn = param.asInt();
  if (CapOn == 1) {
    CapStarted = 1;
    //** then Photon code to switch on the Capacitor
  else{  // button was pressed for off
    //** Photon code here for turning motor off
    MotorStarted = 0;  // reset MotorStarted flag

void loop(void) {;
  // with Arduino you need to keep calling the timers but it doesn't look like you do for Photons