Seeking suggestions for data transfer, plus added explanations

I am working to migrate my sketch into the Blynk environment as Blynk DOES make networking Arduino’s so much easier and reliable. My circuit is an Ethermega (Mega w/Ethernet), and 8 channel sainsmart relay, a DHT22 temp/humidity sensor and a Chronodot DS3231 real time clock. My project will one day control a greenhouse or indoor garden facility. The reason I do not wish to use Blynk’s RTC widget is because growing plants requires a schedule, and if for whatever reason the network were to fail, so too would the timing of events. With an RTC in the circuit, so long as there is power, the program will continue.

The current state of the sketch involves code for the DHT22, code to read the RTC, convert the time into 12 hour format, and code to output that format into a single pair of strings. One string handles the time, the other handles the date. I also have in the simple ethernet code for Blynk. The DHT22 data transmits flawlessly, and I can toggle the relays from Blynk easily as well.

My holdup now is my lack of understanding of how to use the Blynk functions, more particularly, I don’t really comprehend how to use either BLYNK_READ & Blynk.virtualWrite, or the other approach of WidgetLCD & lcd.clear();/lcd.print(); functions to produce the result that I seek. I hope someone can shed some added light as I have read, reread and rereread the language given on the DOCS page, and it is evident that I cannot wrap my brain around it.

So I guess my request is 2fold. Can someone adjust my code so that the RTC data will transmit to an LCD widget, and also can someone provide added insight and knowledge of how these 2 functions work and how they can be modified to fit into other people’s sketches?

      #include <SPI.h>
      #include <Ethernet.h>
      #include <BlynkSimpleEthernet.h>
      #include <Wire.h>                 
      #include "DHT.h"                
      #include <SimpleTimer.h>          
      #include "RTClib.h" // RealTimeClock Library for DS1307 and DS3231
      #define BLYNK_PRINT Serial
      #include <SPI.h>
//*******Sensor Model********************************    
      #define DHTTYPE DHT22
      #define DHTPIN 13 

      RTC_DS1307 RTC;
      float UTCOffset = -5.0;    // Your timezone relative to UTC (

      char auth[] = "authKey";

      byte h;  
      byte f;  
      SimpleTimer timer;
      //WidgetLCD lcdA(V2);
      //WidgetLCD lcdB(V3);

    void setup() 
      //Serial2.begin() // For other baud rates
      //Serial3.begin() // For other baud rates          
      pinMode(DHTPIN, OUTPUT);           

      RTC.adjust(DateTime(__DATE__, __TIME__)); 
      while (Blynk.connect() == false) {}

      timer.setInterval(5000L, climateCheck); // 5 seconds between sensor readings
      timer.setInterval(3000L, RTCdisplay); // 3 seconds between sensor readings
    void loop() 
    void climateCheck()
      h = dht.readHumidity();
      f = dht.readTemperature(true);

      Blynk.virtualWrite(V0, f);    //  Set Virtual Pin 0 frequency to PUSH in Blynk app
      Blynk.virtualWrite(V1, h);      //  Set Virtual Pin 1 frequency to PUSH in Blynk app
    void RTCdisplay()
      DateTime 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";      
      displayHour = now.hour();
      meridian = "AM"; 
      char timeStamp[11];
      char dateStamp[11];
      sprintf(timeStamp, "%02d:%02d:%02d-%02s", displayHour, MIN, SEC, meridian);
      sprintf(dateStamp, "%02d/%02d/%04d", now.month(),, now.year());
      Blynk.virtualWrite(V2, timeStamp);
      Blynk.virtualWrite(V3, dateStamp);
      //lcdA.print(4, 0, timeStamp);
      //lcdB.print(4, 0, dateStamp); 
Thank you in advance

Just a bump to hopefully generate a reply.


Widget LCD, ensure you have all the required components on your sketch as per the sample LCD sketch.

The LCD provided by Blynk is very similar to many physical LCD’s i.e 16 X 2 (16 characters on 2 rows).

The first row is zero and the second is row one. The first character on a row is zero and the sixteenth is position 15.

The LCD requires a string (check Arduino if you don’t know how to convert a float or int to a string).

Format is lcd.print(characterposition, rownumber, string);
So to send “Happy Easter to all Blynkers” it would be something like this:

lcd.print(0, 0, "Happy Easter to ");
lcd.print(0, 1, "   all Blynkers  ");

You don’t have to pad out the string to 16 characters but sometimes it saves sending a lcd.clear();

I was able to pass my strings in Advanced Mode, but I was only able to pass one, OR the other with lcd.print. However, I wish to pass both strings with every iteration of void RTCdisplay(); which leads me to believe the Simple Mode side of the widget is required as there are 2 fields to attach the virtual pins to.

The sample sketch has the following blocks in the setup;

    Blynk.virtualWrite(V0, millis() / 1000);

    Blynk.virtualWrite(V1, millis());

but when I exchange the millis verbiage for my function name, the sketch does not compile, no matter where in the sketch that function is located. Trial and error has lead me to remove the curly braces and used semi colons to get the sketch to compile and upload. Still, in doing that, no values are outputted to the app which leads me to believe my syntax is incorrect, and my limited coding skills hinder my ability to make the needed corrections.

  1. Does the simple method require that the BLYNK_READ() text be in the setup, or am I free to put them in one of my functions?
  2. Is WIDGETLCD lcd(V0); strictly to be used with advanced mode (lcd.print), or can it also be used for simple mode (BLYNK_READ)?

You can pass whatever strings you like to the LCD widget in advanced mode and we do it with most of our projects.

If a string is 8 or less characters in length you can have 4 strings on the LCD at any one time.

String1 String2
String3 String4

Each of my strings is 10 characters long plus the added null character making them [11] characters.

      char timeStamp[11];
      char dateStamp[11];
      sprintf(timeStamp, "%02d:%02d:%02d-%02s", displayHour, MIN, SEC, meridian);
      sprintf(dateStamp, "%02d/%02d/%04d", now.month(),, now.year());
      Blynk.virtualWrite(V2, timeStamp);
      Blynk.virtualWrite(V3, dateStamp);

So they will fit nicely on the advanced LCD.

String 1 is lcd.print(0, 0, timestamp);
String 2 is lcd.print(0, 1, datestamp);

But this will only work if timestamp and datestamp are Strings not character arrays.

Snippet from one of our projects with a float:

  float temp = 21.45;
  char buff[8];  // next few lines convers float to string for LCD
  dtostrf(temp, 4, 1, buff);  // width of 4 is to cover from -99.9 to 99.9 
  lcdtemp = buff;
  String lcdtemperature = lcdtemp + " C";
  lcd.print(0, 0, lcdtemperature);

Your use of Blynk_Read is way off course.


Unfortunately I have char arrays ATM, but I am looking into converting those arrays to Strings. Also, the language used in the DOCS page I find to be most basic, which should suffice for intermediate level coders, but being such a novice myself, I find that there isn’t enough for me to build upon, hence this thread. I am very grateful for what you’ve shared thus far, so please don’t interpret this as unappreciative, I just need more info to build upon.

Side note, earlier, when my sketch used the advanced mode, my char array did pass through the server and onto my app in the LCD widget, so the statement that char arrays won’t pass is not entirely accurate.

Have you looked through the 3 LCD examples (1 advanced and 2 simple)?

1 Like

Ok, I’m almost there now.

      char timeStamp[11];
      char dateStamp[11];
      sprintf(timeStamp, "%02d:%02d:%02d-%02s", displayHour, MIN, SEC, meridian);
      sprintf(dateStamp, "%02d/%02d/%04d", now.month(),, now.year());
      String ts;
      String ds;
      ts = timeStamp;
      ds = dateStamp;
      lcdA.clear();                   //Advanced Mode
      lcdA.print(0, 0, ts + ds);    //Advanced Mode

The above snippet sends the 2 Strings to the same LCD in Advanced mode, but the date starts immediately after the meridian (PM). Is there something I can use to force “ds” to print on the following line of the LCD?

As says

lcd.print(x, y, "Your Message");

So your code should look like this:

lcdA.print(0, 0, ts);    
lcdA.print(0, 1, ds);

Thank you Pavel, works like a charm! Extra thank yous to Costas for walking me through it all and helping me understand this better.

1 Like