Components and supplies
Alphanumeric LCD, 16 x 2
RTC DS1302
Rotary potentiometer (generic)
Resistor 10k ohm
Breadboard (generic)
Arduino Mega 2560
Resistor 220 ohm
DS18B20 HHC Temperature Sensor Module
Jumper wires (generic)
Project description
Code
Clock+RoomTemperature+Date
c_cpp
1#include <virtuabotixRTC.h> //Library for RTC DS1302 2#include <DallasTemperature.h> //Library for Temp Sensor 3#include <OneWire.h> 4#include <LiquidCrystal.h> //LCD library 5#define ONE_WIRE_BUS 7 // Data wire is connected to the Arduino digital pin 7 6 7virtuabotixRTC myRTC(A0, A1, A2); //Wiring configuration 8 9OneWire oneWire(ONE_WIRE_BUS);// Setup a oneWire instance to communicate with any OneWire devices 10DallasTemperature sensors(&oneWire);// Pass our oneWire reference to Dallas Temperature sensor 11LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //setup of LCD display 12 13//Creation of the ° symbol 14byte celsius[8] = 15{ 16 0b01110, 17 0b01010, 18 0b01110, 19 0b00000, 20 0b00000, 21 0b00000, 22 0b00000, 23 0b00000 24}; 25 26void setup() { 27 sensors.begin(); // Start up the library 28 lcd.createChar(0, celsius); 29 lcd.begin(16, 2); //initialize library 30 //myRTC.setDS1302Time(0, 18, 17, 5, 24, 6, 2021); //initialize date and time, used only once at the beginning 31 //second,minute,hour,dayOfTheWeek,day,month,year 32 //dayOfTheWeek means 1 for Sunday, 2 for Monday etc... if you want to display it, not used here 33 34} 35 36void loop() { 37 38 //-----Temperature----- 39 sensors.requestTemperatures(); //reads the temperature 40 lcd.setCursor(0, 0); 41 lcd.print(sensors.getTempCByIndex(0)); //shows temperature in Celsius with 2 decimals 42 lcd.setCursor(4, 0); //position of the 2nd decimal 43 lcd.write(byte(0)); //writes ° on the 2nd decimal that I don't want 44 lcd.print("C "); 45 46 //-----Clock----- 47 myRTC.updateTime(); 48 lcd.print(myRTC.hours); 49 lcd.print(":"); 50 lcd.print(myRTC.minutes); 51 lcd.print(":"); 52 lcd.print(myRTC.seconds); 53 lcd.setCursor(0, 1); 54 lcd.print(myRTC.dayofmonth); 55 lcd.print("/"); 56 lcd.print(myRTC.month); 57 lcd.print("/"); 58 lcd.print(myRTC.year); 59 delay(350); 60 61 if (myRTC.minutes == 59 && myRTC.seconds == 59) { //correction of the display errors at the end of a hour 62 lcd.setCursor(10, 0); 63 lcd.print(" "); 64 lcd.setCursor(13, 0); 65 lcd.print(" "); 66 lcd.print(" "); 67 } 68 if (myRTC.seconds == 59) { //correction of the display errors at the end of a minute 69 lcd.setCursor(14, 0); 70 lcd.print(" "); 71 } 72}
Clock+RoomTemperature+Date
c_cpp
1#include <virtuabotixRTC.h> //Library for RTC DS1302 2#include <DallasTemperature.h> 3 //Library for Temp Sensor 4#include <OneWire.h> 5#include <LiquidCrystal.h> 6 //LCD library 7#define ONE_WIRE_BUS 7 // Data wire is connected to the Arduino 8 digital pin 7 9 10virtuabotixRTC myRTC(A0, A1, A2); //Wiring configuration 11 12OneWire 13 oneWire(ONE_WIRE_BUS);// Setup a oneWire instance to communicate with any OneWire 14 devices 15DallasTemperature sensors(&oneWire);// Pass our oneWire reference to 16 Dallas Temperature sensor 17LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //setup of LCD 18 display 19 20//Creation of the ° symbol 21byte celsius[8] = 22{ 23 0b01110, 24 25 0b01010, 26 0b01110, 27 0b00000, 28 0b00000, 29 0b00000, 30 0b00000, 31 32 0b00000 33}; 34 35void setup() { 36 sensors.begin(); // Start up the library 37 38 lcd.createChar(0, celsius); 39 lcd.begin(16, 2); //initialize library 40 //myRTC.setDS1302Time(0, 41 18, 17, 5, 24, 6, 2021); //initialize date and time, used only once at the beginning 42 43 //second,minute,hour,dayOfTheWeek,day,month,year 44 45 //dayOfTheWeek means 1 for Sunday, 46 2 for Monday etc... if you want to display it, not used here 47 48} 49 50void 51 loop() { 52 53 //-----Temperature----- 54 sensors.requestTemperatures(); //reads 55 the temperature 56 lcd.setCursor(0, 0); 57 lcd.print(sensors.getTempCByIndex(0)); 58 //shows temperature in Celsius with 2 decimals 59 lcd.setCursor(4, 0); //position 60 of the 2nd decimal 61 lcd.write(byte(0)); //writes ° on the 2nd decimal that I 62 don't want 63 lcd.print("C "); 64 65 //-----Clock----- 66 myRTC.updateTime(); 67 68 lcd.print(myRTC.hours); 69 lcd.print(":"); 70 lcd.print(myRTC.minutes); 71 72 lcd.print(":"); 73 lcd.print(myRTC.seconds); 74 lcd.setCursor(0, 1); 75 76 lcd.print(myRTC.dayofmonth); 77 lcd.print("/"); 78 lcd.print(myRTC.month); 79 80 lcd.print("/"); 81 lcd.print(myRTC.year); 82 delay(350); 83 84 if (myRTC.minutes 85 == 59 && myRTC.seconds == 59) { //correction of the display errors at the end of 86 a hour 87 lcd.setCursor(10, 0); 88 lcd.print(" "); 89 lcd.setCursor(13, 90 0); 91 lcd.print(" "); 92 lcd.print(" "); 93 } 94 if (myRTC.seconds 95 == 59) { //correction of the display errors at the end of a minute 96 lcd.setCursor(14, 97 0); 98 lcd.print(" "); 99 } 100}
Downloadable files
Clock+RoomTemperature+Date
Clock+RoomTemperature+Date
Clock+RoomTemperature+Date
Clock+RoomTemperature+Date
Clock+RoomTemperature+Date_pic
Clock+RoomTemperature+Date_pic
Comments
Only logged in users can leave comments
akeylimepie
0 Followers
•0 Projects
0
0