Lcd Clock With Humidity and Temperature Using DS3231 With Alarm

About: THE KING check my new youtube channel : vblogskk ̿ ̿ ̿̿'̿'\̵͇̿̿\з=(•̪●)=ε/̵͇̿̿/ ̿̿'̿''̿'̿̿̿ ̿ (='.'=)>>>>(")_(")....... .just believe on it (●̮̮̃•̃) ʚϊɞ.... ♪♫•*¨*•.¸¸❤ .|̲̅̅●̲̅̅|̲̅̅=̲̅̅|̲̅̅●̲̅̅|

Dht humidity and Temperature in F and C

Use LiquidCrystal_I2C and DHT libraries to display temperature in Fahrenheit and Celsius on your Arduino or Uno R3 microcontroller! and setup time using buttons . with alarm !!!!!!!!!!!!!!

Step 1: Lego Frame

make a lego frame using Lego - Technic - 9398

Step 2: Componants

arduino Uno

DS3231

LCD 1602 x 4 Lines 20x4

Buzzer

4 Push Button

Jumper

Humidity Sensor LCD I2C Arduino

Step 3: Connection

DS3231 _________________________________

Vcc 5 V

GND GND

SDA A4

SCL A5

LCD 1602 _______________________________

Vcc 5V

GND GND

SDA A4

SCL A5

Buzzer ________________________________

+ To 13

- To GND

Step 4: Buttons Connection

Button 1 To D2

Button 2 To D3

Button 3 To D4

Button 4 To D5

Step 5: Code

#include //Memanggil RTC3231 Library

#include // i2C Conection Library #include

//Memanggil i2C LCD Library #include //Memanggil library Push Button

//float tempF; //feh //tempF = dht.readTemperature(True);

#include "dht.h" #define dht_apin A0 // Analog Pin sensor is connected to dht DHT;

//Setup Tombol Setting #define DN_PIN 2 //Decrease Button #define UP_PIN 3 //Increase Button #define SET_PIN 4 //Setup Button #define ALR_PIN 5 //Setup Button #define PULLUP true //Mengaktifkan internal Pull Up #define INVERT true #define DEBOUNCE_MS 20 #define REPEAT_FIRST 500 #define REPEAT_INCR 100

//Declare push buttons Button btnUP(UP_PIN, PULLUP, INVERT, DEBOUNCE_MS); Button btnDN(DN_PIN, PULLUP, INVERT, DEBOUNCE_MS); Button btnSET(SET_PIN, PULLUP, INVERT, DEBOUNCE_MS); Button btnALR(ALR_PIN, PULLUP, INVERT, DEBOUNCE_MS); enum {WAIT, INCR, DECR}; uint8_t STATE; int count; int lastCount = -1; unsigned long rpt = REPEAT_FIRST;

// LiquidCrystal_I2C lcd(0x3F, 16, 2); //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity

//custom degrees char uint8_t dgrsChar[8] = {0x4,0xa,0x4,0x0,0x0,0x0,0x0,0x0};

// Init DS3231 DS3231 rtc(SDA, SCL);

// Init a Time-data structure Time t; //pencacah string time()

uint32_t targetTime = 0; uint8_t conv2d(const char* p) { uint8_t v = 0; if ('0' <= *p && *p <= '9') v = *p - '0'; return 10 * v + *++p - '0';}

//Mengambil waktu jam dari waktu Compile/Upload di system Windows uint8_t hh = 0, mm = 0, ss = 0, dd = 0, bb = 0; int yy = 0; String Day = " "; uint8_t alarmHH = 9, alarmMM = 30; int alarmLONG = 0; uint8_t setMode = 0, setAlarm = 0, alarmMode=0;

void setup() { // Setup Serial connection //Serial.begin(115200); pinMode (13, OUTPUT); //digitalWrite (13, LOW); // jika menggunakan relay sebagai beban alarm // lcd.begin(); // memulai koneksi i2c dengan LCD rtc.begin(); // memulai koneksi i2c dengan RTC lcd.begin(16,4); //++++++++++++++++++++++++++++++++ lcd.backlight(); //++++++++++++++++++++++++++++++++ lcd.createChar(0, dgrsChar); //Membuat custom char derajat lcd.setCursor (0,0); lcd.print(F(" King Clock ")); lcd.setCursor (0,1); lcd.print(F("By Feras Fares")); lcd.setCursor(12, 3); //12th column, second row lcd.print("Ver 1.0"); lcd.blink(); //start blinking cursor delay (1000);

lcd.clear(); // clear display, set cursor position to zero lcd.setBacklight(HIGH); // Backlight on lcd.setCursor (0,0); //col 0 of line 1 lcd.print("Boot sequence"); lcd.setCursor (0,1); // go col 0 of line 2 lcd.print("starting."); delay(1000); lcd.setCursor (0,2); //col 0 of line 1 lcd.print(" Be Ready"); lcd.setCursor (0,3); // go col 0 of line 2 lcd.print(" starting."); lcd.noBlink(); //stop blinking cursor delay(1000); //delay 1 second //start blinking cursor delay (1000); // clear display, set cursor position to zero { for (int y = 0; y < 4; y++) { for (int x = 0; x < 20; x++) { lcd.setCursor (x,y); lcd.print(" "); delay(10);

} } }

//rtc.setTime (10, 15, 00); //rtc.setDate(23, 8, 2016);

void loop()
{ DHT.read11(dht_apin); t = rtc.getTime(); Day = rtc.getDOWStr(1);

if (setMode == 0){ hh = t.hour,DEC; mm = t.min,DEC; ss = t.sec,DEC; dd = t.date,DEC; bb = t.mon,DEC; yy = t.year,DEC; }

if (setAlarm <2){ lcd.setCursor(1,0); if(setMode==0)lcd.print(Day); else {lcd.print(F("SET"));} lcd.print(F(" ")); lcd.print(dd); lcd.print(F("-")); lcd.print(bb); lcd.print(F("-")); lcd.print(yy); lcd.print(F(" "));

lcd.setCursor(0,1); if (hh<10){ lcd.print(F("0"));} lcd.print(hh); lcd.print(F(":")); if (mm<10){ lcd.print(F("0"));} lcd.print(mm); lcd.print(F(":")); if (ss<10){ lcd.print(F("0"));} lcd.print(ss); lcd.print(F(" ")); lcd.print(rtc.getTemp()); lcd.print((char)0); lcd.print(F("C")); lcd.print(F(" ")); }

lcd.setCursor(0,3); lcd.print(F(" S.Temp=")); lcd.print(DHT.temperature); lcd.print((char)0); lcd.print(F("C ")); lcd.print((int)round(1.8*rtc.getTemp()+32)); lcd.print((char)0); lcd.print(F("F"));

lcd.setCursor(0,2); lcd.print(F(" Humidity=")); lcd.print(DHT.humidity);

//lcd.println(Fahrenheit(DHT11.temperature), 2);

//lcd.print(tempF); // lcd.print(dht.readTemperature(true)); //F //Serial.print("Current humidity = "); //lcd.print(DHT.humidity); // Serial.print("% "); // Serial.print("temperature = "); //Serial.print(DHT.temperature); //Serial.println("C "); setupClock(); Alarm (alarmHH, alarmMM, alarmLONG);

if (setAlarm <2 && setMode != 0) {delay (100);} if (setAlarm <2 && setMode == 1){lcd.setCursor(5,0); lcd.print(F(" ")); delay(100);} if (setAlarm <2 && setMode == 2 && bb>9){lcd.setCursor(8,0); lcd.print(F(" ")); delay(100);} if (setAlarm <2 && setMode == 2 && bb<=9){lcd.setCursor(8,0); lcd.print(F(" ")); delay(100);} if (setAlarm <2 && setMode == 3 && bb>9){lcd.setCursor(11,0); lcd.print(F(" ")); delay(100);} if (setAlarm <2 && setMode == 3 && bb<=9){lcd.setCursor(10,0); lcd.print(F(" ")); delay(100);} if (setAlarm <2 && setMode == 4){lcd.setCursor(0,1); lcd.print(F(" ")); delay(100);} if (setAlarm <2 && setMode == 5){lcd.setCursor(3,1); lcd.print(F(" ")); delay(100);} if (setAlarm <2 && setMode == 6){lcd.setCursor(6,1); lcd.print(F(" ")); delay(100);}

if (setMode == 0 && setAlarm != 0 && setAlarm != 1) {delay (100);} //if (setMode == 0 && setAlarm == 1){lcd.clear(); lcd.setCursor(3,0); lcd.print(F("Alarm OFF")); delay(100);} if (setMode == 0 && setAlarm == 2){lcd.setCursor(0,1); lcd.print(F(" ")); delay(100);} if (setMode == 0 && setAlarm == 3){lcd.setCursor(3,1); lcd.print(F(" ")); delay(100);} if (setMode == 0 && setAlarm == 4 && alarmLONG >9){lcd.setCursor(12,1); lcd.print(F(" ")); delay(100);} if (setMode == 0 && setAlarm == 4 && alarmLONG <10){lcd.setCursor(12,1); lcd.print(F(" ")); delay(100);}

Serial.print (setMode); Serial.print (" "); Serial.println (setAlarm); } /////////////////////////////////////////////// // Coding ini dibuat Oleh Dani Rajacell /////// // Untuk www.belajarduino.com ///////////////// // Support by www.tokopedia.com/rajacell ////// // Copyright 24/8/2016 Rev.0.0 //////////////// /////////////////////////////////////////////// void setupClock (void) { btnUP.read(); //read the buttons btnDN.read(); btnSET.read(); btnALR.read(); if (setMode == 7){ lcd.setCursor (0,0); lcd.print (F("Set Date Finish ")); lcd.setCursor (0,1); lcd.print (F("Set Time Finish "));delay (1000); rtc.setTime (hh, mm, ss); rtc.setDate (dd, bb, yy); lcd.clear(); setMode = 0;}

if (setAlarm == 5){ lcd.setCursor (0,0); lcd.print (F("Set Alarm Finish")); lcd.setCursor (0,1); lcd.print (F("Alarm at : ")); lcd.print (alarmHH); lcd.print (F(":")); lcd.print (alarmMM); delay (1000); lcd.clear(); setAlarm=0; alarmMode=1;} if (setAlarm >0){ alarmMode=0;} switch (STATE) { case WAIT: if (btnSET.wasPressed()) { setMode = setMode+1;} if (btnALR.wasPressed()) { setAlarm = setAlarm+1;} if (btnUP.wasPressed()) STATE = INCR; else if (btnDN.wasPressed()) STATE = DECR; else if (btnUP.wasReleased()) rpt = REPEAT_FIRST; else if (btnDN.wasReleased()) rpt = REPEAT_FIRST; else if (btnUP.pressedFor(rpt)) { rpt += REPEAT_INCR; STATE = INCR; } else if (btnDN.pressedFor(rpt)) { rpt += REPEAT_INCR; STATE = DECR; } break;

case INCR: if (setAlarm<2 && setMode==1 && dd<31)dd=dd+1; if (setAlarm<2 && setMode==2 && bb<12)bb=bb+1; if (setAlarm<2 && setMode==3 && yy<2050)yy=yy+1; if (setAlarm<2 && setMode==4 && hh<23)hh=hh+1; if (setAlarm<2 && setMode==5 && mm<59)mm=mm+1; if (setAlarm<2 && setMode==6 && ss<59)ss=ss+1; if (setMode==0 && setAlarm==2 && alarmHH<23)alarmHH=alarmHH+1; if (setMode==0 && setAlarm==3 && alarmMM<59)alarmMM=alarmMM+1; if (setMode==0 && setAlarm==4 && alarmLONG<59)alarmLONG=alarmLONG+1; STATE = WAIT; break;

case DECR: if (setAlarm<2 && setMode==1 && dd>0)dd=dd-1; if (setAlarm<2 && setMode==2 && bb>0)bb=bb-1; if (setAlarm<2 && setMode==3 && yy>2000)yy=yy-1; if (setAlarm<2 && setMode==4 && hh>0)hh=hh-1; if (setAlarm<2 && setMode==5 && mm>0)mm=mm-1; if (setAlarm<2 && setMode==6 && ss>0)ss=ss-1; if (setMode==0 && setAlarm==2 && alarmHH>0)alarmHH=alarmHH-1; if (setMode==0 && setAlarm==3 && alarmMM>0)alarmMM=alarmMM-1; if (setMode==0 && setAlarm==4 && alarmLONG>0)alarmLONG=alarmLONG-1; STATE = WAIT; break; } } /void Alarm (uint8_t alarmHH, uint8_t alarmMM,int alarmLONG) {

if (alarmMode==1 && hh == alarmHH && (mm - alarmMM >= 0 ) && (mm - alarmMM <= alarmLONG )) { tone (13, 1200); if(ss%2==0){lcd.noBacklight();} else {lcd.backlight ();} btnALR.read(); if (btnALR.wasPressed()) { alarmMode = 0; lcd.backlight();}} else {noTone (13); lcd.backlight();}

if (setMode == 0 && setAlarm !=0 && setAlarm !=1){ lcd.setCursor (1,0); lcd.print(F(" Set Alarm ")); lcd.setCursor (0,1); if(alarmHH<10){lcd.print(F("0"));} lcd.print (alarmHH); lcd.print(F(":")); if(alarmMM<10){lcd.print(F("0"));} lcd.print (alarmMM); lcd.print(F(" Long:")); lcd.print (alarmLONG); lcd.print(F("mnt ")); } }

Sensors Contest

This is an entry in the
Sensors Contest

Share

    Recommendations

    • Planter Challenge

      Planter Challenge
    • Beauty Tips Contest

      Beauty Tips Contest
    • DIY Summer Camp Contest

      DIY Summer Camp Contest

    Discussions