Project tutorial
Clock without using RTC in Arduino with Temperature and humi

Clock without using RTC in Arduino with Temperature and humi

Clock without using RTC in Arduino with Temperature and humidity indicator

  • 34,363 views
  • 34 comments
  • 69 respects

Components and supplies

About this project

Clock without using RTC with temperature and humidity indicator (Arduino)

This small code will work as clock and also it will show the temperature and humidity using the DHT11 temperature and humidity Module. I used 3 buttons to be able to set the clock.

You will need these pieces for this project:

  • Arduino Uno Board
  • Button x3
  • Potentiometer
  • LCD 1602 Module (With pi header)
  • DHT11 Temperature and Humidity Module
  • Breadboard
  • Some jumper wires

Code

Clock without using RTC with temperature and humidity indicatorArduino
Clock without using RTC with temperature and humidity indicator
// Ahmad Ordikhani Seyedlar

#include <LiquidCrystal.h>
#include <SimpleDHT.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
volatile int sec, minute = 0, hour = 0;
int b_h = 5;
int b_m = 6;
int pinDHT11 = 2;
int b_startstop = 3;
bool startstop = false;

SimpleDHT11 dht11;

void setup() {

  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);

  lcd.setCursor(0, 0);
  lcd.print("Ahmad Ordikhani");
  lcd.setCursor(0, 1);
  lcd.print("Clk without RTC");
  delay(3000);
  lcd.clear();

  pinMode(b_h, INPUT_PULLUP);
  pinMode(b_m, INPUT_PULLUP);
  pinMode(b_startstop, INPUT_PULLUP);

  attachInterrupt(digitalPinToInterrupt(3), buttons, FALLING);


}

void loop() {

  //Setting the time will stop the clock to set the time
  while (startstop == false)
  {
    lcd.setCursor(0, 1);
    lcd.print("SET");
    delay(100);
    lcd.setCursor(0, 0);
    lcd.print("Time: ");
    if(hour<10)
    {
    lcd.print("0");
    lcd.print(hour);
    }
    else
    lcd.print(hour);
    
    lcd.print(":");
    if(minute<10)
    {
      lcd.print("0");
    lcd.print(minute);
    }
    else
    lcd.print(minute);
    lcd.print(":");
    if(sec<10)
    {
    lcd.print("0");  
    lcd.print(sec);
    }
    else
    lcd.print(sec);
    lcd.print(" ");

    if (digitalRead(b_h) == LOW)
    {
      hour++;
      if (hour > 23)
        hour = 0;
    }

    if (digitalRead(b_m) == LOW)
    {
      minute++;
      if (minute > 59)
        minute = 0;
    }

  }

  //Start the clock
  while (startstop == true)
  {


    // noInterrupts();
    // read with raw sample data.
    byte temperature = 0;
    byte humidity = 0;
    byte data[40] = {0};
    if (dht11.read(pinDHT11, &temperature, &humidity, data)) {
      lcd.setCursor(0, 1);
      lcd.print("Read DHT11 failed");
      return;
    }
    lcd.setCursor(0, 1);
    lcd.print("Temp:");
    lcd.print((int)temperature);
    //lcd.print("*C");
    lcd.print(" ");
    lcd.print("Hum.:");
    lcd.print((int)humidity);
    lcd.print("%");
    //Serial.print((int)temperature); Serial.print(" *C, ");
    // Serial.print((int)humidity); Serial.println(" %");

    lcd.setCursor(0, 0);
    //sec=millis()/1000;
    delay(1000);
    lcd.print("Time: ");
    if (hour < 10)
    {
      lcd.print("0");
      lcd.print(hour);
    }
    else
    {
      lcd.print(hour);
    }
    lcd.print(":");
    if (minute < 10)
    {
      lcd.print("0");
      lcd.print(minute);
    }
    else
    {
      lcd.print(minute);

    } lcd.print(":");
    if (sec < 10)
    {
      lcd.print("0");
      lcd.print(sec);
    }
    else
    {
      lcd.print(sec);
    }
    lcd.print(" ");
    //lcd.print(startstop);
    sec++;
    if (sec > 59)
    {
      minute++;
      sec = 0;
      //lcd.clear();
    }

    if (minute > 59)
    {
      hour++;
      minute = 0;
      //lcd.clear();
    }
    if (hour > 23)
    {
      hour = 0;
      //lcd.clear();

    }
  }
}

//Start/Stop the clock
void buttons()
{
  lcd.clear();
  startstop = !startstop;


}

Schematics

Clock withou using RTC with Temperature und Humidity indicator
Clock steckplatine kvghjvtq0n

Comments

Similar projects you might like

Date, Time, Temperature and Humidity Display

Project tutorial by Chamath Vithanawasam

  • 38,836 views
  • 13 comments
  • 58 respects

Simple Arduino Digital Clock Without RTC

Project in progress by Annlee Fores

  • 165,045 views
  • 40 comments
  • 155 respects

Arduino Temperature - Humidity - Rain Sensor

Project showcase by Mako

  • 24,426 views
  • 7 comments
  • 25 respects

Simplest UNO Digital Clock Ever

Project tutorial by plouc68000

  • 98,350 views
  • 53 comments
  • 118 respects

Clock Set Date Time

Project tutorial by Tittiamo

  • 97,029 views
  • 58 comments
  • 115 respects

Arduino OLED Temperature Display with Real Time Clock

Project tutorial by Keval Doshi

  • 21,957 views
  • 9 comments
  • 39 respects
Add projectSign up / Login