Introduction: 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. !!!DOWNLOAD THE ORIGINAL SKETCH FROM HERE!!! 
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 a PREVIEW of 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 )-----*/

// 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 ) */


____________________________________________________________________________________________________

Comments

author
AaronW100 made it! (author)2016-06-23

I made it after editing the code somewhat and adding a little bit of extra code for more custom icons, but great work Timofte. Couldnt of done it with out this

P_20160623_202227.jpgP_20160623_202504.jpg
author
usmank13 made it! (author)usmank132017-07-04

Excellent job , can i have a code and schematic please ?

author
jhunmar100 made it! (author)2015-09-13

Modified and edit some codes that are not acceptable and it works!

Took me 3 hours to get it work

Im using RTClib library

IMG_9378.JPGIMG_9389.JPGIMG_9393.JPGIMG_9395.JPG
author
usmank13 made it! (author)usmank132017-07-02

hi bro, Can i use DS3231 Rtc Module with your code ,please send me schematics and reply on : uk070327@gmail.com

I hope you will reply me fast...Thnx

author
jhunmar100 made it! (author)jhunmar1002016-08-22

Ohh hey guys sorry i just replied today its been a year already since i opened my account so anyways i updated my code and i change it to 12hr format.. instead of 24hr format display and also i added some Pushbutton to light up the led display or the LCD and in 3 secs the lcd goes dark.. i just added it for light saving so if you want the code here it is....

https://codebender.cc/sketch:365345#RTC_DHT11_Disp...

Enjoy!

author
Lester JosephE made it! (author)Lester JosephE2016-10-12

can you send the schematic?

@ evalle420@gmail.com

salamat

author
Lester JosephE made it! (author)Lester JosephE2016-10-12

sir can i see the wiring connections? because its hard to understand on the picture..

thanks in advance

author
shadowfxd made it! (author)shadowfxd2016-08-23

how exactly did you hook up the button? There's no clue in the pics and I'm new to arduino.

author
jhunmar100 made it! (author)jhunmar1002016-09-05

This link might help you on doing it, and connect it to pin 4

https://www.instructables.com/id/How-to-use-a-push-...

author
TimothyL13 made it! (author)TimothyL132015-10-29

Hi jhunmar100

Experience the same thing. On the last part. Can Please have the Code you use with the RTClib too. Thanks

author
jhunmar100 made it! (author)jhunmar1002015-11-05

Yeah sure i will send it to you

author
MaCK1e made it! (author)MaCK1e2016-06-07

Can you send me the code?
Thanks!
zZMaCK1eZz@hotmail.com
Regards from Mexico !

author
MaCK1e made it! (author)MaCK1e2016-06-07

hi

author
descalle made it! (author)descalle2016-05-29

Hi, is it possible to send me the code please ? pascal@scalyvo.nl

thnx

author
CynthiaChong made it! (author)CynthiaChong2016-05-19

Can you send me the code?Thanks!! ccchong@ucdavis.edu

author
ALAKHMADHAV made it! (author)ALAKHMADHAV2016-04-04

can u send me code at alakh.madhav32@gmail.com please

author
ALAKHMADHAV made it! (author)ALAKHMADHAV2016-04-02

Can u send me code and diagram at alakh.madhav32@gmail.com

author
Harshvardhan Singh made it! (author)Harshvardhan Singh2016-03-27

Fast response appreciated

author
Harshvardhan Singh made it! (author)Harshvardhan Singh2016-03-27

Can you send me the code with all libraries? My email: singhharsh5000@gmail.com ; send through Google Drive.

author
HardikS12 made it! (author)HardikS122016-03-25

hieee hello

what about this error?

'negative' was not declared in this scope

can u mail me your code to me on solankihardik@hotmail.com

author
IsraelD3 made it! (author)IsraelD32015-11-06

a mi me sale como la de la imagen de arriba, ¿me puedes decir como lo hago para que me salga como el tuyo?

author
oschari made it! (author)2016-06-17

Yes, it works! i have changed the lcd i2c to paralel code, solved the weekday-problem, and i use a 16x4 display!

aditional i can set the rtc directlc with the flasching od the arduino!

20160617_150225[1].jpg
author
IZZATYZ made it! (author)IZZATYZ2017-04-27

can u teach me how to use lcd 16x4. i have trying so many time to connect it with arduino but it cant. please help me

author
AaronW100 made it! (author)AaronW1002016-06-23

can you advise how you got to set the RTC directly i was having an issue with this and had to use the settime example code first

author
omizyurko made it! (author)2017-01-18

Thanks! It was really helpful for me. To share some wiring there is a good tool - http://fritzing.org/home/

author
made it! (author)2016-09-01

Yes It's work ..

author
Brabolets made it! (author)2016-07-26

Where i plug RTC?????

author
Timofte Andrei made it! (author)2015-03-31

For everyone of you who's going to use this project for himself: please learn basic electronics before crying out loud around because it's not my fault you don't have any idea of pull-up resistors, anti-parallel diodes and so on. The schematic is described in words just to see the amount of people which are understanding electronics or not. I know I have some issues with terms in english, but you have to start getting informations from elsewhere to understand a project. I know I'm rude in this comment, but if you don't start to understand what are you doing, you just waste your time and time is expensive, but you don't know that yet!

author
RalphV10 made it! (author)RalphV102016-07-16

why on earth would you make an instructable with deliberate mistakes in it? whinging about people needing help, make the instructable correct and people wont ask questions, you dead set wanker.

author
unn made it! (author)unn2016-01-30

I have one comment :

//months of the week also in romanian

basic nowledge ? ;D

author
Bruno.Castro.Fmc made it! (author)2016-07-10

Can i use DSI 1502 with the same code ?

author
IsraelD3 made it! (author)2015-11-06

lo hice pero vi un problema en el código y lo arregle, el (1) el que viene ya puesto no me iba a si que use el (2) de otro proyecto I2C y me funciono a la primera.

1 (MALO) LiquidCrystal_I2C lcd(0x20, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE);

2 (BUENO) LiquidCrystal_I2C lcd( 0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE );

gracias.

IMG_20151107_050135.jpg
author
MaCK1e made it! (author)MaCK1e2016-06-07

Me lo puedes mandar a mi correo:
zZMaCK1eZz@hotmail.com

author
MaCK1e made it! (author)MaCK1e2016-06-07

Hola me podroas pasar tu codigo porfavor ?

author
greg.nordstrom made it! (author)2016-05-17

Timofte, thanks for posting this project. Very helpful!

author
fitfat123 made it! (author)2016-04-12

Hey, can i change the lcd with bluetooth module for controlling by android? Please for the respon

author
ALAKHMADHAV made it! (author)2016-04-02

Hey i want complete code and diagram of this project because when i tried i got error please some one send me code and diagram at alakh.madhav32@gmail.com

author
delokaver made it! (author)2016-02-19

I think will be nice if the " : " able to blink for each second, have any one already try and willing to share the sketch ?

author
kantona80 made it! (author)2015-01-30

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...

YwRobotLCD-CU-450.jpg
author
Ingenerare made it! (author)Ingenerare2015-09-13

does not work:

RTC_LCD_DHT11.ino:66:32: error: invalid conversion from 'int' to 't_backlighPol' [-fpermissive]

In file included from RTC_LCD_DHT11.ino:23:0:

C:\Users\vincent\Documents\Arduino\libraries\LiquidCrystal/LiquidCrystal_I2C.h:53:4: error: initializing argument 3 of 'LiquidCrystal_I2C::LiquidCrystal_I2C(uint8_t, uint8_t, t_backlighPol)' [-fpermissive]

LiquidCrystal_I2C (uint8_t lcd_Addr, uint8_t backlighPin, t_backlighPol pol);

^

Error compiling

author
JustinS15 made it! (author)JustinS152015-10-07

I also have this error...

invalid conversation from 'int' to 't_backlightPol' [-fpermissive]

Anyone figure out a fix?

author
RenatoL1 made it! (author)2015-06-15

There is a trick to make this kind of I2C module to work with WINSTAR LCD ... Note that the PIN1 from LCD is marked after pins 16 and 15 ... I had to jump it from the last pins of I2C to the first pins of LCD ....

2015-06-15 19.53.28.jpg2015-06-15 19.53.35.jpg2015-06-15 19.55.09.jpg2015-06-12 13.24.52.jpg2015-06-15 20.09.25.jpg
author
jhunmar100 made it! (author)jhunmar1002015-09-13

Can you give us your code sir?? Please??

author
Ploopy made it! (author)2015-05-23

Cool!

author
adam.miernik made it! (author)2015-02-23

It is not works!!! I trying do this for six hours and I did nothing. Error and error and error. I regret that I bought parts, in Poland I spent 150 zloty`s its a lot of money in Poland.

author
Timofte Andrei made it! (author)Timofte Andrei2015-03-31

https://www.dropbox.com/s/ycgh1sa88tqq8r8/termometru_dht11_cu_ceas.ino THIS IS THE CODE

author
Timofte Andrei made it! (author)Timofte Andrei2015-03-31

Here's the schematic. It is described in the project text, but it's hard to read. I'm usualy not providing schematics just to see how people are handling this...
You really have to learn how electronic systems are working, otherwise you only waste your time.
Read the code to see what pins are used by each sensor/device. If it uses i2c bus, in arduino uno there are only 2 pins used: A4(SDA) and A5(SCL), with the coresponding 4.7K pull-up resistors. In my case the pull-up resistors are integrated in the RTC module. Do no copy-paste the code from the page because it's not going to work because of html issues of the page.

temp_780911878.jpg
author
adam.miernik made it! (author)adam.miernik2015-02-26

can you give me electronic plan of this project?

author
ChứcN made it! (author)2014-08-23

How to adjust correct time. Thanks

author
ChứcN made it! (author)ChứcN2015-03-26

please help!