I built an 8 head peristaltic dosing pump to be controlled with an Arduino over Ethernet through Blynk to my smartphone. The way the pumps work is I dial in a pump number and the amount of dosage in ml I want, then tick a button and the Arduino powers the respective pump on for a calculated amount of time and shuts off. Because of the way Blynk operates, I can forward all Serial.print commands in the form of terminal.print and the Blynk app displays that info on a monitor within the app on the smartphone.
All of that said, I am hoping there is an easy way to associate 8 different text strings with 8 different positions of the for loop. I have exhausted my ability to locate any similar projects on Google, plus I have exhausted my limited code skills when trying “different things” to make a scheme that will compile.
The below sketch runs perfectly if I can dial it back by deleting lines 21 and 22, and adjusting line 48 to simply print (x). What’s below is just my latest feeble attempt to make it compile. Research doesn’t suggest that I will find favorable “easy” results, but I am hoping someone with a fuller understanding can change that.
/*
*/
#include <SPI.h> //Used by Blynk
#include <Ethernet.h> //Used by Blynk
#include <BlynkSimpleEthernet.h> //Used by Blynk
#include <SimpleTimer.h>
char auth[] = "PasteAuthKeyBetweenQuotes"; //Paste code that app emailed you between "quotes"
SimpleTimer timer;
WidgetTerminal terminal(V3);
int pumpPin[8] = { 2, 3, 4, 5, 6, 7, 8, 9 }; //Digital pins used
uint32_t multiplier[8] = { 858, 827, 872, 865, 887, 895, 913, 843 }; //ms per ml
uint32_t startPump = 0;
uint32_t runCount;
float DOSEml; //V1 Step Widget (0.25 per step, send step/NO, loop values ON)
int button = 0; //V2 Button Widget set to Switch
bool pumpRunning = false;
int x;
const char y[8] = { "armorSi", "floraBlend", "caliMagic", "koolBloom",
"floraGro", "floraMicro", "floraBloom", "phDown" }
BLYNK_WRITE(V0) { // Choose Pump
x = param.asInt() - 1; // Edited *****
}
BLYNK_WRITE(V1) { // Adjust Dosage
DOSEml = param.asFloat();
}
BLYNK_WRITE(V2) { // Activate Chosen Pump
button = param.asInt();
}
void checkPump()
{
if (button == 1 && pumpRunning == false)
{
Blynk.virtualWrite(V0, 0);
Blynk.virtualWrite(V1, 0);
Blynk.virtualWrite(V2, 0);
pumpRunning = true;
digitalWrite(pumpPin[x], HIGH);
startPump = millis();
runCount = DOSEml * multiplier[x];
terminal.print("Dosing in: ");
terminal.print(DOSEml);
terminal.print(" milliliters of ");
terminal.println(y[x]);
terminal.flush();
}
if (millis() - startPump > runCount)
{
digitalWrite(pumpPin[x], LOW);
pumpRunning = false;
button = 0;
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth);
while (Blynk.connect() == false) {}
timer.setInterval(1500L, checkPump);
for (int p = 0; p <= 7; p++)
{
pinMode(pumpPin[p], OUTPUT);
}
Blynk.virtualWrite(V0, 0);
Blynk.virtualWrite(V1, 0);
Blynk.virtualWrite(V2, 0);
}
void loop()
{
Blynk.run();
timer.run();
}
I’d like to emphasize that I just wish to associate the text string to the current position of [ x ] so the correct string prints with the correct pump number. Otherwise I can deal with the value display of the step widget (1-8) and mentally make the association.
Edit - Here is a YouTube video depicting the pump motors and the app and how they relate to one another.