Go Down

Topic: Time, temperature and humidity (displaying separately) (Read 141 times) previous topic - next topic

MrEko

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()
{
lcd.begin();
lcd.backlight();
}
 
void loop()
{
delay(1000);
lcd.setCursor(0,0);
s=s+1; 
lcd.print("TIME:");
lcd.print(h);
lcd.print(":");
lcd.print(m);
lcd.print(":");
lcd.print(s);     
delay(400);
if(flag==24)flag=0;
delay(1000);
lcd.clear();
if(s==60){
 s=0;
 m=m+1;
}
if(m==60)
{
 m=0;
 h=h+1;
 flag=flag+1;
}       
DHT.read11(dht_apin);
lcd.setCursor(0,1);
lcd.print("TEMP(*C):"); 
lcd.print(DHT.temperature);
delay(2000);
lcd.setCursor(0,1);
lcd.print(' ');
lcd.setCursor(0,1);
lcd.print("HUM(%):");
lcd.print(DHT.humidity);
delay(1000);
}

PaulS

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.
The art of getting good answers lies in asking good questions.

Nick_Pyner

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.

odometer

If you are going to post code, please use code tags.
What are code tags? Read item #7 at this link: http://forum.arduino.cc/index.php/topic,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.

Go Up