akeylimepie
Published © GPL3+

LCD Clock

Get clock, date and room temperature (and later smartphone notifications on the same screen in a 3D printed casing when I'm done).

IntermediateWork in progress1,502
LCD Clock

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
NDS1602A
×1
Sunfounder RTC DS1302
×1
Sunfounder DS18B20 HHC Temperature Sensor Module
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 220 ohm
Resistor 220 ohm
×1

Story

Read more

Schematics

Clock+RoomTemperature+Date

Clock+RoomTemperature+Date_pic

Code

Clock+RoomTemperature+Date

C/C++
#include <virtuabotixRTC.h> //Library for RTC DS1302
#include <DallasTemperature.h> //Library for Temp Sensor
#include <OneWire.h>
#include <LiquidCrystal.h>  //LCD library
#define ONE_WIRE_BUS 7 // Data wire is connected to the Arduino digital pin 7

virtuabotixRTC myRTC(A0, A1, A2); //Wiring configuration

OneWire oneWire(ONE_WIRE_BUS);// Setup a oneWire instance to communicate with any OneWire devices
DallasTemperature sensors(&oneWire);// Pass our oneWire reference to Dallas Temperature sensor
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //setup of LCD display

//Creation of the ° symbol
byte celsius[8] =
{
  0b01110,
  0b01010,
  0b01110,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

void setup() {
  sensors.begin();  // Start up the library
  lcd.createChar(0, celsius);
  lcd.begin(16, 2); //initialize library
  //myRTC.setDS1302Time(0, 18, 17, 5, 24, 6, 2021); //initialize date and time, used only once at the beginning
                                                    //second,minute,hour,dayOfTheWeek,day,month,year
                                                    //dayOfTheWeek means 1 for Sunday, 2 for Monday etc... if you want to display it, not used here
                                                   
}

void loop() {

  //-----Temperature-----
  sensors.requestTemperatures(); //reads the temperature
  lcd.setCursor(0, 0);
  lcd.print(sensors.getTempCByIndex(0)); //shows temperature in Celsius with 2 decimals
  lcd.setCursor(4, 0); //position of the 2nd decimal
  lcd.write(byte(0)); //writes ° on the 2nd decimal that I don't want
  lcd.print("C ");

  //-----Clock-----
  myRTC.updateTime();
  lcd.print(myRTC.hours);
  lcd.print(":");
  lcd.print(myRTC.minutes);
  lcd.print(":");
  lcd.print(myRTC.seconds);
  lcd.setCursor(0, 1);
  lcd.print(myRTC.dayofmonth);
  lcd.print("/");
  lcd.print(myRTC.month);
  lcd.print("/");
  lcd.print(myRTC.year);
  delay(350);

  if (myRTC.minutes == 59 && myRTC.seconds == 59) { //correction of the display errors at the end of a hour
    lcd.setCursor(10, 0);
    lcd.print(" ");
    lcd.setCursor(13, 0);
    lcd.print(" ");
    lcd.print(" ");
  }
  if (myRTC.seconds == 59) {  //correction of the display errors at the end of a minute
    lcd.setCursor(14, 0);
    lcd.print(" ");
  }
}

Credits

akeylimepie
0 projects • 0 followers

Comments