Gday Blynk’ers
Excuse me for everything after this. I am excited to find Blynk and need to learn how to use it for a project I need to complete. I am not thick or dumb, but due to an accident I find things I could previously do quite easily like programming which I started in the 90’s, so I am going have to ask for some kind people to be patient with me.
I have been learning Arduino for the past two years and still find it hard. I have got a working sketch for a simple project using a Wemos D1 Mini Pro. I needed to create an autofiller for my Anycubic resin printer. They don’t make one for my model, so I bought the one they have and hacked it but now want to use Blynk to send a push notification to my mobile to notify me when resin runs out with my printer in my back shed. I also want to be able to turn on or off the buzzer in the auto filler.
So I need to learn how to send the notification when the input turns low for the resin bottle and to use a virtual input that will turn on and off the buzzer function.
Can anyone point me in the direction of a project that is similar as find it easier to understand someone when it is close to what I need. I have looked at the tutorials and some code I found but just can’t get my head around it.
See my Arduino sketch below (I was given help with this and don’t understand the spam part of it and some of the logic but will keep working on it. I have also edited it so the spam function(debug) isn’t functioning):
[Blynk code would be- IF NOT bottlecapacity send push notification “Resin Bottle Empty” which will repeat at an interval set in the Blynk app and, IF switch for buzzer is on(in Blynk app) turn buzzer function on, ELSE turn off buzzer function.
# define bottlecapacity_pin 0
# define fullvatswitch_pin 1
# define ps_pin 2
# define resinemptyled_pin 3
# define buzzer_pin 16
unsigned long previousMillis1 = 0UL;
//unsigned long previousMillis2 = 0UL;
unsigned long previousMillis3 = 0UL;
unsigned long previousMillis4 = 0UL;
unsigned long kkInterval1 = 1500UL; // beep blink duty cycle
//unsigned long kkInterval2 = 3000UL; //spare
unsigned long kkInterval3 = 5000UL; //after vat is full delay pump off
unsigned long kkInterval4 = 60000UL; //pump delay on
void setup()
{
pinMode(bottlecapacity_pin, INPUT); //bottlecapapcityswitch_pin
pinMode(fullvatswitch_pin, INPUT); //fullvatswitch_pin
pinMode(ps_pin, OUTPUT); //soleniods and pump on
pinMode(buzzer_pin, OUTPUT); //resin bottle empty buzzer
pinMode(resinemptyled_pin, OUTPUT); //resin bottle empty led
}
unsigned long now;
# define PRESSED HIGH // argh! pulled down switches
void loop()
{
if (millis() > 30000) //30sec delay before code starts operating
{
now = millis();
byte bottlecapacity = digitalRead(bottlecapacity_pin);
byte vatFull = digitalRead(fullvatswitch_pin);
**/***
** blink led and buzzer if green bottle switch not pressed(open)**
** if green bottle button pressed(closed) then blink led and buzzer stop instantaneously**
** if vat red button pressed(closed - vat if full) and stays pressed for 5 seconds then ps_pin off(LOW)**
** if vat red button not pressed(open - vat not full) and the resin bottle(full - green button pressed(on) and both cases are met for 60 seconds then ps_pin on(HIGH)**
** */**
**// timer for how long has green button has not been pressed**
static unsigned long bottlecapacityTimer;
if (bottlecapacity != PRESSED) {
if (!bottlecapacityTimer) bottlecapacityTimer = now;
}
else bottlecapacityTimer = 0; // 0 -> timer not running
**// timer for how long has red button been pressed**
static unsigned long vatFullTimer;
if (vatFull == PRESSED) {
if (!vatFullTimer) vatFullTimer = now;
}
else vatFullTimer = 0; // 0 -> timer not running
**// timer for how long has red button been unpressed AND green button has been pressed**
bool bothConditions = (vatFull != PRESSED) && (bottlecapacity == PRESSED);
static unsigned long bothConditionsTimer;
if (bothConditions) {
if (!bothConditionsTimer) bothConditionsTimer = now;
}
else bothConditionsTimer = 0; // 0 -> timer not running
**/* informational spam**
** xprintf("vatFull %s ", vatFull == PRESSED ? "pressed " : "not pressed ");**
** xprintf("botlcap %s\n", bottlecapacity == PRESSED ? "pressed " : "not pressed ");**
if (vatFullTimer)
xprintf("vatfull pressed for %lu ms ", now - vatFullTimer);
if (bothConditionsTimer)
xprintf(" vatfull unpressed && bottlecapacity pressed for %lu ms ", now - bothConditionsTimer);
*/
// informational spam
//xprintf("RED %lu ms /RED & GREEN %lu ms\n",
// vatFullTimer ? now - vatFullTimer : 0,
// bothConditionsTimer ? now - bothConditionsTimer : 0
//);
**// if the bottlecapacity button isn't pressed, we should beep and blink**
static unsigned char toggle;
if (bottlecapacity != PRESSED) {
if (now - previousMillis1 >= kkInterval1) {
if (toggle) {
digitalWrite(resinemptyled_pin, LOW);
digitalWrite(buzzer_pin, HIGH);
}
else {
digitalWrite(resinemptyled_pin, HIGH);
noTone(buzzer_pin);
}
toggle = !toggle;
previousMillis1 = now;
}
}
else {
digitalWrite(resinemptyled_pin, LOW);
// noTone(buzzer_pin);
}
**// if the bottlecapacity condition has been false for enough time**
if (bottlecapacity != PRESSED) {
if (now - bottlecapacityTimer > kkInterval3) { //turn pump off by kkinterval3
if (1) {
digitalWrite(ps_pin, LOW);
bottlecapacityTimer = 0;
}
}
}
**// if the vatFull condition has been true for enough time**
if (vatFullTimer) {
if (now - vatFullTimer > kkInterval3) { //turn pump off by kkinterval3
if (1) {
digitalWrite(ps_pin, LOW);
vatFullTimer = 0;
}
}
}
// if the vatFull/bottlecap condition has been true for enough time
if (bothConditionsTimer) {
if (now - bothConditionsTimer > kkInterval4) { //turn pump on by kkinterval4
if (1) {
digitalWrite(ps_pin, HIGH);
bothConditionsTimer = 0;
}
}
}
}
}