Arduino Forum

Using Arduino => Programming Questions => Topic started by: MrEko on May 02, 2018, 10:39 pm

Title: Time, temperature and humidity (displaying separately)
Post by: MrEko on May 02, 2018, 10:39 pm
Hello everyone, i'm making a digital clock project on Arduino Uno. The thing i'm asked to do is making a digital clock that is being displayed on a LCD without using the RTC module. But i wanted to add some things such as a DHT11 temperature and humidity sensor as well. I wanted to display TIME:HH:MM:SS on the first line, and on the second line i wanted to display TEMP(*C):XX.YY, waiting for a moment, clearing the second line (i did it using blank space), then to display HUM(%):XX.YY. And on and on. I just wanted to delay the second line 2 seconds while changing from temperature to humidity to see temperature and humidity values clearly. But it delays the whole system and time value is disappering for the amount of delay time too. I just want the clock being displayed for the whole time and display temperature and humidity separately. This is my code below:
 #include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <dht.h>
#define dht_apin   2
LiquidCrystal_I2C lcd(0x27, 16, 2);
dht DHT; 
int h=14; //hour
int m=50; //minute
int s=20; //second
int flag;
int TIME;
const int hs=8;
const int ms=9;

void setup()
void loop()
lcd.print(' ');
Title: Re: Time, temperature and humidity (displaying separately)
Post by: PaulS on May 03, 2018, 12:56 am
we'll tell you the same thing we tell everybody that can't be bothered to do any research. See the damned blink without delay example, without delay.
Title: Re: Time, temperature and humidity (displaying separately)
Post by: Nick_Pyner on May 03, 2018, 01:45 am
If you want to do this clock stuff, you might as well jump in at the deep end and use an RTC module. The DS3231 is only a couple of dollars, and you get yourself what it says it is - a real clock. I don't think there is any point in using a blank space, all you need do is appropriately add charcter blanks to the temp or hum data. Similarly, if you need to print "TIME" at all, you only need to do it once - in Setup, and add the changing figures to the same line. For your current problem all you need is a 1-5 counter in the loop to set the condition to change the secondary display the data. I guess you will need another counter in that to select the different data. This means you go through a regular sequence over-writing the secondary display every few seconds.

A job like this is so trivial that the delay 1000 for the loop that you already have is entirely appropriate, and the clock, certainly with an RTC, will run fine for weeks - or until the time you want to move onto something else more exciting. Getting familiar with blink without delay is a good idea, but any idea that it is mandatory is just nonsense. I understand some people simply wait for a change in seconds from the RTC before going through the display cycle. Some, if not all, RTCs have a 1Hz square wave output that can be used to signal the loop as well.
Title: Re: Time, temperature and humidity (displaying separately)
Post by: odometer on May 03, 2018, 06:53 am
If you are going to post code, please use code tags.
What are code tags? Read item #7 at this link:,148850.0.html (,148850.0.html)

What is the variable called flag supposed to do? Does it actually do anything useful?

Also, how does your code handle the display of seconds? What actually happens after the seconds get to 59 ? Do they go back to zero?

About how long does a minute on your clock take in real time? Check it against a wristwatch or a stopwatch app.

I suggest that, for now, you remove the code for the temperature and humidity sensor, and just get the clock to work.

Here is a hint for you: Once you figure out how to correctly count seconds for your clock, you will be able to do something similar to count seconds for your temperature and humidity display.