Sei sulla pagina 1di 8

Food

Living

Outside

Play

Technology

Workshop

Clock with thermometer using Arduino, i2c 16x2 lcd, DS1307 RTC and DHT11
sensor.
by Timofte Andrei on January 16, 2014

Table of Contents
Clock with thermometer using Arduino, i2c 16x2 lcd, DS1307 RTC and DHT11 sensor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Intro: Clock with thermometer using Arduino, i2c 16x2 lcd, DS1307 RTC and DHT11 sensor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

http://www.instructables.com/id/Clock-with-termometer-using-Arduino-i2c-16x2-lcd-D/

Intro: Clock with thermometer using Arduino, i2c 16x2 lcd, DS1307 RTC and DHT11 sensor.
Hello! It's been a while I've didn't posted anything on Instructables, but now I made a simple project that I've seen on internet in various forms. I managed to build a code
using other codes I've found on internet and I got to say it's working good.
For this project you need:
- Arduino Uno
- 16x2 LCD with i2c module
- DS1307 RTC
- DHT11 temperature and humidity sensor
- a bread board
- some wires for connections.
As you can see the RTC is homemade because I had a DS1307 chip and a battery extracted from an old german electronic cash registering device.
So the connections are very simple:
The RTC and the i2c LCD are connected to A4 pin (SDA) and A5(SCL) and DHT11 sensor is connected to D2 pin. DHT11 has 4 pins, but only 3 are actually used. First
pin is Vcc, the second is for data and the forth pin is for ground. As I said, connect data pin of the sensor to D2 on Arduino.
Now, the hardest part: the code. https://www.dropbox.com/s/ycgh1sa88tqq8r8/termometru_dht11_cu_ceas.ino
I've tried some sketches I've found on internet, but there were alot of errors caused by incompatible libraries and so on. I managed to build a code made from parts of
other codes and it's working like a charm now. There is a single problem though. You can find in the sketch a bit of code for displaying first 3 letters of the week day, but
for some reason it doesn't work. Instead of those letters it shows some unknown characters and it's pretty ugly. I suspect that is a problem caused by i2c communication
because in standard connection (4bits) it works without problems.
My inspiration came from this page http://arduino-info.wikispaces.com/PROJECT-Temp-Humidity-Display , and this page http://www.ucontrolit.tv/184/
This is the library used for this project http://arduino-info.wikispaces.com/file/view/DHT11.zip/390039522/DHT11.zip and don't forget to use the new LCD library that can
be found right here https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads (when you add this new library in the folder, delete the old LiquidCrystal folder!)
And this is the code:
________________________________________________________________________________________________
/* YourDuino.com Example Software Sketch
DHT11 Humidity and Temperature Sensor test
Displayed on I2C LCD Display
Credits: Rob Tillaart
http://arduino-info.wikispaces.com/PROJECT-Temp-Humidity-Display
terry@yourduino.com
Combined with:
Mark Johnson's code
http://uControlIt.tv
December 2012
License: GNU General Public License
Modiffied by Timofte Andrei ( http://timofteandreidiy.wordpress.com )
January 2014
*/
/*-----( Import needed libraries )-----*/
#include
#include
#include
#include
#include
//const char* zile[] =
// { "Lun", "Mar", "Mie", "Joi", "Vin", "Sam", "Dum"}; //days of the week in romanian (not used)
const char* luni[] =
{"Dec", "Ian", "Feb", "Mar", "Apr", "Mai", "Iun", "Iul", "Aug", "Sep", "Oct", "Noi" }; //months of the week also in romanian
byte termometru[8] = //icon for termometer
{
B00100,
B01010,
B01010,
B01110,
B01110,
B11111,
B11111,
B01110
};
byte picatura[8] = //icon for water droplet
{
B00100,
B00100,
B01010,
B01010,
B10001,
B10001,
B10001,
B01110,
};
/*-----( Declare objects )-----*/

http://www.instructables.com/id/Clock-with-termometer-using-Arduino-i2c-16x2-lcd-D/

// Set the pins on the I2C chip used for LCD connections:
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x20, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE); // Set the LCD I2C address
dht11 DHT11;
/*-----( Declare Constants, Pin Numbers )-----*/
#define DHT11PIN 2 //dht11 signal pin connected to D2
void setup() /*----( SETUP: RUNS ONCE )----*/
{
Wire.begin();
lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight
lcd.backlight();
lcd.clear();
lcd.createChar(1,termometru);
lcd.createChar(2,picatura);
// part code from http://tronixstuff.wordpress.com/
Wire.beginTransmission(0x68);
Wire.write(0x07); // move pointer to SQW address
Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission();
// end part code from http://tronixstuff.wordpress.com/
setSyncProvider(RTC.get);
}/*--(end setup )---*/
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
afisare_temperatura(); //displaying temperature
data_si_ora(); //displaying date and time
}
void afisare_temperatura()
{
int chk = DHT11.read(DHT11PIN);
lcd.setCursor(1, 1);
lcd.write(1);
lcd.setCursor(3, 1);
lcd.print((float)DHT11.temperature, 0);
lcd.setCursor(5, 1);
lcd.print((char)223); //degree sign
lcd.print("C");
lcd.setCursor(9, 1);
lcd.write(2);
lcd.setCursor(11, 1);
lcd.print((float)DHT11.humidity, 0);
lcd.print("%");
delay(2000);
}
void data_si_ora()
{
tmElements_t tm;
(RTC.read(tm));
lcd.setCursor(0, 0);
afisare2cifre(tm.Hour);
lcd.print(":");
afisare2cifre(tm.Minute);
lcd.setCursor(7,0);
afisare2cifre(tm.Day);
lcd.print(" ");
lcd.print(tm.Month[luni]);
lcd.print(" ");
lcd.print(tmYearToCalendar(tm.Year)-2000);
// lcd.setCursor(12,1); // this code is used for displaying day of the week
// lcd.print(tm.Wday[zile-2]); //it's disabled because for some reason it doesn't work on i2c display
}
void afisare2cifre(int numar) { //this adds a 0 before single digit numbers
if (numar >= 0 & numar < 10) {
lcd.write('0');
}
lcd.print(numar);
}
/* ( THE END ) */
____________________________________________________________________________________________________

http://www.instructables.com/id/Clock-with-termometer-using-Arduino-i2c-16x2-lcd-D/

Image Notes
1. RTC DS1307
2. i2c convertion module for lcd
3. DHT11
4. colorful spaghetti on breadboard

http://www.instructables.com/id/Clock-with-termometer-using-Arduino-i2c-16x2-lcd-D/

Image Notes
1. 3V even after 12 years. awesome, huh?

Related Instructables

Weekend
project clock
date
thermometer
and humidity
with Arduino
mega by arick

Mostrar
Temperatura en
Display con
Sensor DHT11 y
Arduino by
ElectroCrea

Arduino for
Greenhouse,
Garden or
Growbox by
diy_bloke

I2C LCD
Controller Part II Arduino
Portable
by verdelj
Weather
Monitor,
altimeter,
temperature,
humidity, using
DHT11 and
BMP85 with
LCD using only
3 pins by
animes25

Arduino Real
Time Clock
(DS1307) by
Naren_Murali

Advertisements

Comments
34 comments Add Comment

AdrianF2 says:

Jan 4, 2015. 5:19 AM REPLY


Foarte fain, mai ales partea cu caracterele speciale! Is this possible to have the humidity trend over an hour? Also, as a suggestion, maybe the LCD can be
connected also on I2C. Best regards, Adrian

Timofte Andrei says:

Feb 1, 2015. 4:43 AM REPLY


salut! scuze pentru intarziere...uita-te la mine la proiecte sa vezi ca am facut niste modificari si am adaugat card SD pentru logging al temperaturii si
umiditatii :D Cum a zis si pvalyk, ecranul si ceasul sunt conectate pe i2c, deci ceilalti pini raman liberi pentru alte chestii :) Mersi pt comentariu! Bafta

pvalyk says:

Jan 28, 2015. 5:23 AM REPLY


Both the LCD and RTC are connected to I2C (Sda and Scl). For temperature trend you need EEPROM memory or do you mean get the temperature
once in 1h? In that case modify the delay by defining delays as 1h.

kantona80 says:
Here is a ZIP archive with all libraries and the right sketch that works with LCD I2C
YwRobot LCM1602 IIC (mine works on 0x27 address)
https://drive.google.com/file/d/0B0rVZYzj6RpOYm9vU...

http://www.instructables.com/id/Clock-with-termometer-using-Arduino-i2c-16x2-lcd-D/

Jan 30, 2015. 6:47 AM REPLY

kantona80 says:

Jan 30, 2015. 6:07 AM REPLY

Hi timofte, great job for the project:


Very detailed and simple to follow instructables but the tricky part is
by collecting all the needed libraries!!!
You could have put the
libraries that you have used in a zip archive all together, in order to
simplify things. I also have a compilation error after adding all the
libraries:
'NEGATIVE' was not declared in this scope
Kf5qgf, can you upload your code on the cloud somewhere?
Thanks

kantona80 says:

Jan 30, 2015. 6:23 AM REPLY

I think that the NEGATIVE issue shown by Arduino IDE could be related to a different LiquidCrystal_I2C library version...

airfoil233 says:

Jun 27, 2014. 3:36 AM REPLY

Helps a lot! thanks for the tutorial.

Ch?cN says:

Oct 6, 2014. 12:57 AM REPLY

I have error 'class DS1307RTC' has no member named 'get' and error with setSyncProvider(RTC.get);
help me please

refill71 says:

Oct 19, 2014. 2:26 PM REPLY

If you have a error in class DS1307RTC, please add the Time library.
http://www.pjrc.com/teensy/td_libs_Time.html

Ch?cN says:

Oct 19, 2014. 6:51 PM REPLY

thanks very much! It work fine

airfoil233 says:
HI ChucN:
Maybe this will help!
http://forums.adafruit.com/viewtopic.php?f=31&t=36...

http://www.instructables.com/id/Clock-with-termometer-using-Arduino-i2c-16x2-lcd-D/

Oct 6, 2014. 1:20 AM REPLY

Ch?cN says:

Oct 9, 2014. 9:04 AM REPLY

thanks so much! But i can not see this page.

Ch?cN says:

Sep 29, 2014. 12:51 AM REPLY

I have error 'class DS1307RTC' has no member named 'get' and error with setSyncProvider(RTC.get);
help me please

diy_bloke says:

Aug 20, 2014. 11:59 AM REPLY

looks real neat.


A word of warning though. For another project (
http://www.instructables.com/id/Arduino-for-Greenh... )
I have something comparable: a clear plastic box with the electronics and a DHT11 sensor on top. Seemed real compact. I couldnt understand why my
project always gave a temperature that was 2-5 degrees higher than the real temperature.... until I checked. The electronics in the box, especially the
LCD, were heating up the box... and the DHT11 sensor on top :-).
I attached it with a wire and the 'problem' was gone

Timofte Andrei says:

Jun 30, 2014. 7:18 PM REPLY


well that is awesome, my friend! :) don't forget to say a word to the world about me :P thanks for your feedback and good luck! :D

Lectric Wizard says:

Jan 16, 2014. 12:59 PM REPLY

Well done ,but needs an H in the title so we can find it with search engine. "termometer"

Timofte Andrei says:

Jan 16, 2014. 9:25 PM REPLY


sorry for that! i'm romanian and i don't write english texts very often so i'm really sorry for spelling mistakes. thanks for your reply!

kf5qgf says:

Jan 20, 2014. 11:00 PM REPLY


I've modified the code for an English version if you'd like I can e-mail it to you. It's an excellent piece of code you wrote here. Fit exactly what I
wanted. Just made a few mods, changed the LCD library and the pin initialization to fit my LCD shield and viola. 73's.

mukundans says:

Oct 18, 2014. 6:56 PM REPLY

Hi kf5qgf ,
greetings, iam a noob just getting to play with Arduino mini pro.Would appreciate if you email me your sketch (vu3smz@gmail.com) in english so
that i can try and build a clock.
thanks
muks

Timofte Andrei says:

Jan 22, 2014. 5:53 AM REPLY


Thanks for your reply! I'm glad that code is useful for you! Have a good time using it and show us your project and your improvements! Cheers!

Lectric Wizard says:

Jan 21, 2014. 6:02 AM REPLY

Thanks for sharing ! I won't be using this at this time but did keep the link for future reference. CHEERS!!!!

teaMJPx says:

Oct 7, 2014. 9:51 AM REPLY

This is awesome! I was making this on my own but... With your instructable... WOW! Thanks for this!

cts_casemod says:

Apr 19, 2014. 1:45 PM REPLY


I loaded all the libraries, but no success compiling. I Think they might be different. Any chance of including a zip file with dht11, Time and DS1307RTC
libraries as you used?
Regards

http://www.instructables.com/id/Clock-with-termometer-using-Arduino-i2c-16x2-lcd-D/

Timofte Andrei says:

Apr 25, 2014. 1:22 PM REPLY

what error you got?

Ch?cN says:

Sep 28, 2014. 10:34 PM REPLY

I have error 'class DS1307RTC' has no member named 'get' and error with setSyncProvider(RTC.get);
help me please

Timofte Andrei says:

Apr 25, 2014. 1:25 PM REPLY


oh and try to use an older arduino IDE. newer IDEs are just too buggy. i'm considering to use other kind of IDE instead of original one provided by
arduino team. there are too many annoying problems that are killing me inside....

Ch?cN says:

Aug 23, 2014. 1:16 AM REPLY

How to adjust correct time. Thanks

jmsl100 says:

May 25, 2014. 11:32 AM REPLY


It seems really simple, but it does not. I like to congratulate you, very simple explanation of an arduino project. So the tricky part is by collecting all the
needed libraries, there are some of them in many flavors. My only concern was with the compilation of the sketch. After I have all the hardware and software,
the arduino IDE remarks : NEGATIVE was not declared, so I decided to ask you, what is NEGATIVE do?, and by the way, please indicate the correct sketch
line. Regards.

Timofte Andrei says:

May 27, 2014. 11:59 AM REPLY


For some reason Instructables doesn't let me upload the code on the site, so here's a dropbox link to the code... i hope it works ok because on my ide it's
compiling without a problem! cheers!
https://www.dropbox.com/s/ycgh1sa88tqq8r8/termometru_dht11_cu_ceas.ino

samumar82 says:

May 3, 2014. 2:36 AM REPLY


Hey kf could you please mail me the code you modified? I'm getting tons or errors with this author's one and can't figure it out why.
thanks a lot! samuele.marchetti [at] fastwebnet.it

Timofte Andrei says:

Apr 30, 2014. 2:11 AM REPLY


use 1.2.0 library and don't forget about DS1307RTC Library! oh, and try to use Arduino IDE below 1.0.3 or something like that! I've seen that the original
Arduino IDE sucks more and more.

quinto says:

Apr 26, 2014. 4:17 AM REPLY

which version of LiquidCrystal library are you using?


I use newest 1.2.1 and I get 12 errors in your code.
1."NEGATIVE" and "RTC" was not declared in this scope for example

guitarans says:

Mar 9, 2014. 4:54 AM REPLY

i would realy like a schematic,

Timofte Andrei says:

Mar 12, 2014. 11:58 AM REPLY


SDA(A4), SCL(A5), 5v, gnd for i2c rtc and LCD, and DHT11 is connected to D2 pin (read the code). there is no schematic needed for this kind of simple
project.

http://www.instructables.com/id/Clock-with-termometer-using-Arduino-i2c-16x2-lcd-D/

Potrebbero piacerti anche