Blynk Controller Doser Pump

I have an old aquarium dosing pump that I have converted to use a NodeMCU and 3 relays. I have a simple sketch and Blynk app that has 3 buttons. Pressing them runs the pumps until you turn them off.

The next step is 2 fold. I need to set the buttons to be pressed once a day and a specific time (all three cannot run at once) and the second step is to set how long the button is pressed for. I suspect this is all done in the app itself but have no idea where to start.

IRC you can use the eventor widget for that. Else you can code this with a timer. See documentation for that.

1 Like

The RTC widget can be used to reference in code to begin timed events at a desired time, the duration can be measured with millis and stop pumping when the preset duration elapses. In my larger project, I have a function to select between 8 peristaltic pumps, dial up a dose between 0.25ml-80.00ml which is also measured using millis. @Fettkeewl, helped me work everything out about a year ago. I’ll share the function and related language. Use whatever you can.

//V36 - Menu (Dosing Pump Select)
//V37 - Step V (Dosing Pump Volume)(DOSEml)
//V38 - Button (Dosing Pump Start)
//V39 - Step V (calibration 0-1000) 

//-Digital Pins - Peristaltic Pump Variables - 00 Series Pins
const int pumpPin[8] = { 2, 4, 5, 12, 13, 14, 15, 16 };
int dosingLEDs[8]  = { V40, V41, V42, V43, V44, V45, V46, V47 };
uint32_t multiplier[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; //ms per ml
uint32_t startPump = 0;
uint32_t runCount;
bool pumpRunning;
const char *nuteType[8] = { "NutrientA", "NutrientB", "NutrientC", "NutrientD",
                            "NutrientE", "NutrientF", "NutrientG", "NutrientH"
                          }; //Text Printed to Terminal Widget^^

float DOSEml;      //Step Widget (0.25 per step, send step/NO, loop values ON)
int button = 0;   //Button Widget set to Switch
int x;           //Correlates Array Positions with Pump Motor Pins
int calibration;

BLYNK_WRITE(V36) {    //X = Pump Select
  x = param.asInt() - 1;
}
BLYNK_WRITE(V37) {
  DOSEml = param.asFloat();
}
BLYNK_WRITE(V38) {    //Pump Start
  button = param.asInt();
}
BLYNK_WRITE(V39) {
  calibration = param.asInt();
}

//--------Setup------------
  //timer.setInterval(2007L, dosingPumps);         // 0.2 second interval to maintain accuracy (+/- .25)
//--------------------------------
void dosingPumps()
{
  if (button == 1 && pumpRunning == false)
  {
    multiplier[x] = calibration;                      // Gets the value in [x] position from Blynk
    Blynk.virtualWrite(V36, 0);
    Blynk.virtualWrite(V37, 0);
    Blynk.virtualWrite(V38, 0);                        // Keeps button ON until fully executed
    pumpRunning = true;
    digitalWrite(pumpPin[x], HIGH);
    Blynk.virtualWrite(dosingLEDs[x], 255);           // [x] position Blynk indicator LED
    startPump = millis();
    runCount = DOSEml * multiplier[x];
    terminal.print("Dosing in: ");
    terminal.print(DOSEml);
    terminal.print(" milliliters of ");
    terminal.println(nuteType[x]);
  }
  if (millis() - startPump > runCount)
  {
    digitalWrite(pumpPin[x], LOW);
    Blynk.virtualWrite(dosingLEDs[x], 0);
    pumpRunning = false;
    button = 0;
  }
  terminal.flush();
}
1 Like