Pulse Timer (for misting)

Why do you have the two ‘*’ symbolas before and after BLYNK_WRITE ?

Is this how it looks in your Arduino IDE, or is it something to do with the way you’ve posted your code?

It should look like this:

BLYNK_WRITE(V2) // Time interval for delay 5-120 seconds

Once you fix that error, you’ll also get errors saying that mistruntime and delaytime are not defined within this scope.
That’s because you haven declared these variables. As I said earlier, this declaration needs to happen near the top of your code, like this:

int mistruntime;
int delaytime;

You should insert these two lines just before the start of your void setup.

Pete.

Hi Gunner,

Am I alot closer with this

[code]
/*
 * Turns on a digital output for "RunTime" set by the slider widget 
 * on virtual pin 1, then it will turn off the digital output for 
 * "DelayTime" as set by the slider widget on virtual pin 2. Then repeats
 */


#define BLYNK_PRINT Serial

int RunTime;
int Active = 4;

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "Arduino.h"

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***";
char pass[] = "***";

void setup()
{
  // Debug console
  Serial.begin(9600);
  
  //initialize digital pin as output
  pinMode(Active, OUTPUT);
  
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);


}
BLYNK_WRITE (V1) // Time interval for misting 0.5-10 seconds, with 0.5 second increments

{

RunTime = param.asInt(); // assigning incoming value from pin V1 to the variable RunTime

serial.println(RunTime);

}

**BLYNK_WRITE** (V2) // Time interval for delay 5-120 seconds, with whole second increments

{

DelayTime = param.asInt(); // assigning incoming value from pin V2 to the variable DelayTime

serial.println(DelayTime);
{
void loop()
{
  digitalWrite(Active, HIGH);
  delay(1000*RunTime);
  digitalWrite(Active, LOW);
  delay(1000*DelayTime);
  Blynk.run();
}
[/code]

Thanks Pete, could you have a look at revision I have just pasted?
It’s done my head in, too much for a beginner, I might continue on tomorrow.

Thanks to both of you and more importantly for your patience. I WILL get there!

Your revision is MUCH worse!

That stuff in your void loop will kill the Blynk process, and you’ve got some random unneeded pinmode declaration in there for some reason.
Go back to the earlier version, sort out the ** characters, declare your variables then tell us what results you’re getting.

Pete.

oopsy, fresh start tomorrow.
I am thinking a bit like excel…

User to enter x and y values and tells it when to start, excel does the rest and calculates it.

ok I will revert, with a fresh head tomorrow :scream:

Ok I thought I would have one last crack for the evening…

This is what I pasted. At first I had an error saying mistruntime was not declared in this scope. So I though maybe I had to declare them as I did below
int mistruntime;
int delaytime;

But now with that I have a new error saying ‘serial’ was not declared in this scope
Now it’s time to recharge my batteries and have a good sleep, again thank you both for your patience.

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

int mistruntime;
int delaytime;


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***";
char pass[] = "***";

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}
BLYNK_WRITE (V1) // Time interval for misting 0.5-10 seconds

{

mistruntime = param.asInt(); // assigning incoming value from pin V1 to a variable

serial.println(mistruntime);

}

BLYNK_WRITE (V2) // Time interval for delay 5-120 seconds

{

delaytime = param.asInt(); // assigning incoming value from pin V2 to a variable

serial.println(delaytime);
void loop()
{
  Blynk.run();
}

OK… you must have an opening and closing bracket in a function… your one BLYNK_WRITE() function is missing it’s closing bracket and your compiler is basically confused :stuck_out_tongue:

Try to lay out things with self-determined spacing between functions and such, so you can look at things and get a feel for it at a glance… instead of lots of random extra lines and spacing

I tend to do it this way with single spacing between specific sections of code and triple spacing in between functions

int something;  // Declaring something as a global variable



BLYNK_WRITE(vPin)  {  // *** opening bracket
something = param.asInt();  // Get my value from my widget
// stuff that perhaps does things based on something
// then calls some other related function
function();
}  // *** closing bracket



void function()  {   // *** opening bracket
// stuff that takes something and does this
// and this
// and this

// then stuff that does that
// and that

// finally, stuff that does the other
}  // *** closing bracket

Also, serial and Serial are two tolally different things as far as C++ is concerned.

You’ve used the correct capitalised Serial in your Serial.begin statement, but an incorrect lower case version in your serial.println statement.

Pete.

1 Like

Thanks Guys,

I edited the sketch and uploaded. It is reading the values from the 2 sliders - although to not one decimal place - do I need to change int to float?

[code]
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

int mistruntime;
int delaytime;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***";
char pass[] = "***";

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}

BLYNK_WRITE (V1) // Time interval for misting 0.5-10 seconds
{
mistruntime = param.asInt(); // assigning incoming value from pin V1 to a variable

Serial.println(mistruntime);
}

BLYNK_WRITE (V2) // Time interval for delay 5-120 seconds
{
delaytime = param.asInt(); // assigning incoming value from pin V2 to a variable

Serial.println(delaytime);
}
void loop()
{
  Blynk.run();
}
[/code]

Since integers are Whole numbers, then yes, if you need Fractionals change to float mistruntime; etc. You can also set your slider settings accordingly for number of decimal places it will account for when sending.

Thanks Gunner

I changed them to float variables. Now the data is showing to 2 decimal places but it’s still rounded to a whole number essentially.

Do I need to change param.asInt() to param.asfloat()?

Sorry, yes, otherwise it is just converting the incoming float back to int :stuck_out_tongue:

Thanks. So now I have this code that seems to be interpreting the data correctly and storing that as a variable. (Only need run time as a float)

Any tips for the next step?

[code]
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

float mistruntime;
int delaytime;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "***";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "***";
char pass[] = "***";

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}

BLYNK_WRITE (V1) // Time interval for misting 0.5-10 seconds
{
mistruntime = param.asFloat(); // assigning incoming value from pin V1 to a variable

Serial.println(mistruntime);
}

BLYNK_WRITE (V2) // Time interval for delay 5-120 seconds
{
delaytime = param.asInt(); // assigning incoming value from pin V2 to a variable

Serial.println(delaytime);
}
void loop()
{
  Blynk.run();
}
[/code]

Now set up a timed function (via BlynkTimer) that will check every x amount of minutes/hours and do something based on your input parameters.

could you provide an example sketch - I am truly lost when you say to setup a timed function to check every x period

Do I need to be doing if statement at this stage?

Ok, I will admit I have been to a couple of dozen sources and the more I read the more I am reading into something completely different to my end game, would really love the additional help to step me through this. I am willing to learn, but I best learn through correspondence and errors :tired_face:

I can relate… however, short of paying for someone on a site like fivver to make your code, or perhaps find a teacher, most fellow Blynk users here are running their own projects and lives, and can only provide basic ideas and suggestions.

I actually had to learn to program (still am) all by my lonesome as well… mainly by engaging others in this forum, and seeing their questions that intrigued me, I learned how to do it myself then answered the questions as best abled.

Over time, I have made a bunch of examples that I already provided the link for (a few posts above)… there is a section on the timers I was referring to in there.

So, instead of trying to make your particular full project from scratch, I recommend little projects that work on one or two concepts at a time… like a timer that flashes an LED every x period :smiley:

I actually wouldn’t have considered this project to be a full project.

I have done the LED timer that flashes every x period, but somehow that hasn’t helped. I thought it would simply be a variation of this and instead of fixed periods, I could substitute it with the variables from the sliders or steps. (you might notice I tried that above and I was way off the mark.)

What do you mean by setup a timed function to check every x period. In plain English it doesn’t make sense to me.

In plain English I would have thought

If D7 Input = 1 then start loop (Set D8 Output to HIGH for V1 duration of time, then set D8 Output to LOW for V2 duration of time. Repeat loop), if D7 Input = 0, set D8 to LOW.

Problem is you need to translate Plain English into Plain C++ code :stuck_out_tongue:

Looking at the Sketch Builder example for Push Data

AKA…

Do something every x period =

Every second, Send the elapsed time (since device boot), in seconds, to App =

A timer timer.setInterval(1000L, myTimerEvent); that calls a function named myTimerEvent() every second (1000 milliseconds), then that function runs the command Blynk.virtualWrite(V5, millis() / 1000); which sends the elapsed time in milliseconds, divided by 1000 (AKA how many elapsed seconds since the device started) to the Blynk App).

I can follow that in parrot fashion, but I am trying to understand why I need to know the elapsed time since boot?