Need help with this project...pretty please?

So thanks to @bko I have been able to create the initial code for the project I’m working on. The second part that I would like to attempt (I know virtually nothing about this type of programming - TOTAL NEWBIE!!) is to be able to adjust the parameters of the program either via a webpage or via a LCD keypad such as this.

A few notes about the project. What I’m controlling is a relay shield that turns on one of two peristaltic dosing pumps. The pumps need to be able to run for very specific amounts of time, but may need to be adjusted over time. So it would be nice to be able to adjust the programming via a much more simple method than going into the spark builder every time.

Ideally the parameters to adjust would be as follows:

On time - day of week, hour, minute, second
run time - minutes, seconds
Manual On/Off Override

On a side note, it would be great to know if there was a way to measure the amount of liquid dispensed, but I’m not sure how you would go about that. The pump is supposed to dispense .6ml/min but the pumps are not always 100% accurate. This is definitely an after thought. I know there are flow meters, but I’m not sure I know of any flow meter that measures such small amounts

Here is the code, again, HUGE thanks to @bko for his help with this. And here is a link to his RTC Clock Library.

// This #include statement was automatically added by the Spark IDE.
#include "SparkTime.h"


UDP UDPClient;
SparkTime rtc;

int RELAY1 = D0;
int RELAY2 = D1;
int RELAY3 = D2;
int RELAY4 = D3;

void setup()
{
   //Initilize the relay control pins as output
   pinMode(RELAY1, OUTPUT);
   pinMode(RELAY2, OUTPUT);
   pinMode(RELAY3, OUTPUT);
   pinMode(RELAY4, OUTPUT);
   // Initialize all relays to an OFF state
   digitalWrite(RELAY1, LOW);
   digitalWrite(RELAY2, LOW);
   digitalWrite(RELAY3, LOW);
   digitalWrite(RELAY4, LOW);

rtc.begin(&UDPClient, "pool.ntp.org");
rtc.setTimeZone(-5); // gmt offset
rtc.setUseDST(true);

}

void loop() {

unsigned long currentTime = rtc.now();
static unsigned long stopTime = 0;

if (rtc.hour(currentTime)==0 && rtc.minute(currentTime)==17 && rtc.second(currentTime)==00) {
    digitalWrite(RELAY1,HIGH);
    stopTime = currentTime + (2);  //one minute and ten seconds
}

if (currentTime >= stopTime) {
    digitalWrite(RELAY1,LOW);
}
if (rtc.hour(currentTime)==0 && rtc.minute(currentTime)==17 && rtc.second(currentTime)==03) {
    digitalWrite(RELAY2,HIGH);
    stopTime = currentTime + (2);  //one minute and ten seconds
}

if (currentTime >= stopTime) {
    digitalWrite(RELAY2,LOW);
}

delay(100);

}
2 Likes

Looks great!

Just one quick point–if for any reason you want the pumps to overlap (turn on pump1 … turn on pump2 … turn off pump1 … turn off pump2) you will need two stop time variable since the second one will overwrite the first one’s time.

You might also want to update the comments “one minute and ten seconds” should be 2 seconds, right?

For the control, you could have a set of Spark functions that set the times and provides manual control for the web.

Glad you got the first part working!

Hey @bko the timing is off right now, I was just using that as a test for each channel. Thank you for your help. Any thoughts on where I could do some investigation or reading to try and learn myself?

I’m really hoping someone will help me out, but I’m willing to try myself as well.