Multi timer

hello
i am new to blynk and have not programmed in over 20 years
i would like to set up a light timer that will come on at the same time then shut off for a few hours then turn back on then off for the night adb i would like to be able to manuel turn the light on or off if needed just unsure where to start.
i am not asking for the program to be written for me just asking for help with getting started and what i should read throu

thanks

1 Like

You can program for timed events, but also you can manually turn lights on and off with a Blynk widget at your convenience. Did you already build the circuits and connected it/them to your microcontroller? Which microcontroller are you using?

in the process of building it started with arduino mini was was think of switching to a NodeMCU LUA WiFi Internet ESP8266 still working on the code the basic code i have will turn them on and off at the times of day but id power goes out when it comes back on it like everything started all over again so have to work out if then else statements but i have never worked with blynk and when i have tried to nothing really happened with it so i just gave up LOL

I found an old thread that hashed out a lot of what you’ll likely want to do. It uses the ESP and Blynk RTC widget to test the time against preset values.

http://community.blynk.cc/t/turning-light-using-rtc-widget/5450/16

no but i will give it a try and i am using a rtc module with it i think it is the ds1307. i have use it in anothe project with no problem but that is juts a dosing system

I use that library with my ds3231, so here’s a Blynk sketch that uses that library. Be mindful, that I use an Ethernet connection and an Arduino Mega, so you’ll likely need to augment the sketch to suit your MCU. You’ll also need to eject the DHT lines if they don’t apply.


      #include <SPI.h>
      #include <Ethernet.h>
      #include <BlynkSimpleEthernet.h>
      #include <Wire.h>                 
      #include "DHT.h"                    // DHT data wire connected to D13 with a 10k pullup resistor               
      #include <SimpleTimer.h>          
      #include "RTClib.h"                 // RealTimeClock Library for DS1307 and DS3231
    
//*******Sensor Model********************************    
      #define DHTTYPE DHT22
      #define DHTPIN A0 

      RTC_DS1307 RTC;
      float UTCOffset = -5.0;    // Your timezone relative to UTC (http://en.wikipedia.org/wiki/UTC_offset)

      char auth[] = "PasteAuthKeyBetweenQuotes";

      DHT dht(DHTPIN, DHTTYPE);
      byte h;  
      byte f;  
                
      SimpleTimer timer;
    
      WidgetLCD lcdA(V2);  //Set LCD widget to Advanced
      WidgetTerminal terminal(V8);

    void setup() 
    {
      Serial.begin(9600);  
      //Serial2.begin() // For other baud rates
      //Serial3.begin() // For other baud rates          
      Blynk.begin(auth);
      pinMode(DHTPIN, OUTPUT);           
      dht.begin();

  //RTC.adjust(DateTime(__DATE__, __TIME__));
  //Uncomment "RTC.adjust" the first time this sketch is uploaded to program the RTC.
  //Once done, re-comment that line out, and upload this sketch again.
      RTC.begin();   
     
      while (Blynk.connect() == false) {}

      timer.setInterval(5000L, climateCheck); // 5 second intervals between DHT readings
      timer.setInterval(3000L, RTCdisplay); // 3 second intervals between RTC readings
    }
      
    void loop() 
    {
      Blynk.run();
      timer.run();
    }
    
    void climateCheck()
    {
      h = dht.readHumidity();
      f = dht.readTemperature(true);

      Blynk.virtualWrite(V0, f);    //  Set Virtual Pin 0 frequency to PUSH in Blynk app (display widget)
      Blynk.virtualWrite(V1, h);      //  Set Virtual Pin 1 frequency to PUSH in Blynk app (display widget)
      //Serial.print(f);
      //Serial.print(h);
    }
    
    void RTCdisplay()  
    { 
      DateTime now = RTC.now();  // reads time at beginning of loop
  
      byte twelveHour = now.hour() - 12; // Variable used to display 13+ hours in 12 hour format
      byte zeroHour = 12;                // Variable use to convert "0" zero hour to display it as 12:00+
      byte displayHour;
      byte MIN = now.minute();
      byte SEC = now.second();
      char* meridian;
  
      if (now.hour() == 0)  // First we test if the hour reads "0"
    { 
      displayHour = zeroHour;
      meridian = "AM";         
    }
      else if (now.hour() >= 13)  // if no, Second we test if the hour reads "13 or more"
    { 
      displayHour = twelveHour;
      meridian = "PM";      
    }
      else 
    { 
      displayHour = now.hour();
      meridian = "AM"; 
    }
     
      char timeStamp[16];
      char dateStamp[16];
      sprintf(timeStamp, "%02d:%02d:%02d-%02s", displayHour, MIN, SEC, meridian);
      sprintf(dateStamp, "%02d/%02d/%04d", now.month(), now.day(), now.year());
      String ts;
      String ds;
      ts = timeStamp;
      ds = dateStamp;
       
      lcdA.clear();            //Advanced Mode
      lcdA.print(3, 0, ts);    //Advanced Mode
      lcdA.print(3, 1, ds);    //Advanced Mode
    
    }

Also, here is a snippet from my master sketch that tests the on time and off time, for 5 instances per day but of course that’s scalable both ways.

  boolean pumpAstate = false;
  if (pumpAon == 1) pumpAstate = true;
  if (now.hour() == 6 && now.minute() >= 0 && now.minute() < 5) pumpAstate = true;    //6:00 am - 5 mins
  if (now.hour() == 8 && now.minute() >= 30 && now.minute() < 35) pumpAstate = true;  //8:30 am - 5 mins
  if (now.hour() == 11 && now.minute() >= 0 && now.minute() < 5) pumpAstate = true;  //11:00 am - 5 mins
  if (now.hour() == 13 && now.minute() >= 30 && now.minute() < 35) pumpAstate = true;  //1:30 pm - 5 mins
  if (now.hour() == 16 && now.minute() >= 0 && now.minute() < 10) pumpAstate = true;  //4:00 pm - 10 mins
  if (pumpAstate == true)
  {
    digitalWrite(pumpA, TURN_ON);
    terminal.println("Pump A On");  //  Text printed to terminal monitor
    terminal.flush();
  }
  else
  {
    pumpAon = 0;
    digitalWrite(pumpA, TURN_OFF);
  }

“pumpAon” is an int connected to a Blynk virtual pin and a button widget. This allows me to prioritize the Blynk command over the programmed off time that would otherwise hold the relay in the off position.

Ditch this mate… check out the RTC widget and provided examples. Far more accurate and a few lines of code to configure. You can also set up timezones via the widget options.