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.