Timer Help

I have a small project where I have 2 leds controlled with buttons for on and off and a slider for each controlling their brightness with PWM. The leds are blue and white.

I want to add a simple schedule where the blue leds come on at a set time, and off again at a set time. The same for the white leds.

I have the buttons and sliders working but adding the timer is confusing as I cant select a digital pin on the widget only a virtual one. So I added this code:

BLYNK_WRITE(V1){
  if (V1 == 1){
  digitalWrite(2, 1);
  } else {
    digitalWrite(2, 0);
  }
}

The gpio pin is 2. The time input widget points to V1.

What did I miss? It compiles and the buttons and sliders continue to work fine.

Change to:
if(param.asInt()){

Then spend some time studying the docs and the examples.

I get no difference with that line in the logic.

I cant really find the correct Documentation section.

I cant even set the Timer widget to the actual D2 pin and have it work…

Huge resource of docs including https://examples.blynk.cc/?board=ESP8266&shield=ESP8266%20WiFi&example=Widgets%2FTimer

Thanks

Yeah I have seen that and the only thing that isnt in the getting started code is

BLYNK_WRITE(V5)
{
  // You'll get HIGH/1 at startTime and LOW/0 at stopTime.
  // this method will be triggered every day
  // until you remove widget or stop project or
  // clean stop/start fields of widget
  Serial.print("Got a value: ");
  Serial.println(param.asStr());
}

I have tried this code. Something isnt right still, I presume with my app on my phone. I have a timer, the start time is 8:00 and the end is 22:00 Pin is V5… Sorry I feel I am being dense.

Which MCU are you using?

Its a NodeMCU esp8266.

The thing is the button works great. I just want the app to press the button essentially… I even tried deleting the button, so no conflict there. Tried just pointing the timer at the digital pin and even that doesnt work. Do I need to get the time into the sketch itself?

D2 is not the pin you are using in your sketch, you are using GPIO 2.
D2 is GPIO 4.
The D references printed on ESP boards are not like Arduino’s where they match the GPIO’s.

My button (on the app) is set to D2. It turns the leds off and on as intended.

I made a timer (after changing the button to something different) to D2. It doesnt turn the leds on, the start time was 0800 end was 2200…

That’s probably because you need to change the 2 you have in the digitalWrite() calls to 4 (GPIO) or D2 ESP label.

Sorry I dont follow. I am not using the V5 at the moment, just trying to get the timer widget to turn the pin on using D2. If it was V5 I would get what your saying through!

Suggest changing these so we don’t have to wait until tomorrow morning.

Ensure your phone has the correct time (most are updated by the internet but some are not). If it’s wrong by a minute or two it will give you false readings.

Then set timer widget for on in 2 minutes time and off in 3 minutes time.

If it fails post your sketch.

Ok so I misunderstood that the timer would not activate unless is was exactly the start time! Setting the time to a few mins in the future worked if I set the timer to D2. However my V5 still doesnt work.

this is my sketch

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

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

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

BLYNK_WRITE(V5)
{
  if (param.asInt()) {
    digitalWrite (4, HIGH);
    Blynk.notify("Blues are ON");
  } else {
    digitalWrite (4,LOW);
    Blynk.notify("Blues are OFF");

  }
  Serial.print("Got a value: ");
  Serial.println(param.asStr());
}
BLYNK_WRITE(V6)
{
  if(param.asInt()) {
    digitalWrite (16, HIGH);
    Blynk.notify("Whites are ON");
  } else {
    digitalWrite (16,LOW);
    Blynk.notify("Whites are OFF");

  }
  Serial.print("Got a value: ");
  Serial.println(param.asStr());
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();
}

Timer is set to V5.

Connected to Pins D0 and D2 on the nodeMcu which should be GPIO 4 and 16.

Then it will not control the code in V6 unless you add it into the codeof V5.

But the code you have in V5 is correct. You are mixing pins or you don’t have the correct time settings for the timer.

Yeah I have a standard timer for both V5 and V6. They work but the TimerInputs dont work at all. Adding a notification to each they both read as on as soon as i “play” the app way before the timer is due to go off. :confused: standard timers will have to do i suppose!

Thanks ! :slight_smile:

If you mean the Time Input widget it works just fine. Just find the relevant sketch.

Yeah the Time Input is a lot more complicated that this Timer widget. I am on IOS so no Eventor :frowning:

but much more powerful.

Which board do you use?