On Table Clock & Temp
Checking out time and room's temperature by one hand shake.
Components and supplies
1
Resistor 10k ohm
1
lcd 20*4
1
Resistor 47.5k ohm
1
tcrt 5000
1
Resistor 1k ohm
1
Arduino UNO
1
tiny rtc i2c module
1
lcm 1602
1
lm 35
Tools and machines
1
Soldering iron (generic)
Apps and platforms
1
Arduino IDE
1
Fritzing
1
DXP Altium Designer
Project description
Code
clk-temp-code
arduino
1// Date and time functions using a DS1307 RTC connected via I2C and Wire lib 2//rtc-lcm(sweach led ghat' beshe va 16 lcd be 6 va 15 lcd be 7 vasl beshe)-lm35(A0)-ir(57K ohm,1K ohm , be halat interrupt be paye 2 khroji mide)-lcd 3 4#include <Wire.h> 5#include<avr/sleep.h> 6#include "RTClib.h" 7#include <LiquidCrystal_I2C.h> 8 9// Set the LCD address to 0x3f or 0x27 (depends on your chip) for a 16 chars and 2 line display 10LiquidCrystal_I2C lcd(0x3f, 20, 4); 11RTC_DS1307 rtc; 12 13char daysOfTheWeek[7][12] = {" Sunday", " Monday", " Tuesday", "Wednesday", " Thursday", " Friday", " Saturday"}; 14 15void setup () { 16 lcd.begin(); 17 rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));// to set rtc init value by your pc time 18 pinMode(6,OUTPUT); 19 digitalWrite(6,0); 20 pinMode(7,OUTPUT); 21 digitalWrite(7,1); 22 delay(300); 23 attachInterrupt(0, wakeUpNow, LOW); 24 lcd.backlight(); 25} 26 27void loop () { 28 pinMode(7,OUTPUT); 29 digitalWrite(7,1); 30 pinMode(6,OUTPUT); 31 for(int i=255;i>0; i=i-4){ 32 analogWrite(6,i); 33 delay(20); 34 } 35 finFunc(); 36 pinMode(6,INPUT); //to put it to HiZ to low power using 37 digitalWrite(6,0); 38 pinMode(7,INPUT); //to put it to HiZ to low power using 39 digitalWrite(7,0); 40 lcd.clear(); 41 lcd.setCursor(0,1); 42 lcd.print(" stand by "); 43 lcd.setCursor(0,2); 44 lcd.print(" hover your hand! "); 45 sleepNow(); 46 lcd.clear(); 47} 48void finFunc(){ 49 for(int i=0; i<25; i++){ 50 mainFunc(); 51 delay(200); 52 } 53} 54void mainFunc(){ 55 int temp = (5.0 * analogRead(A0) * 100.0) / 1024; 56 DateTime now = rtc.now(); 57 lcd.setCursor(6,0); 58 if(now.hour()<10) 59 lcd.print("0"); 60 lcd.print(now.hour(), DEC); 61 Serial.print("time: "); 62 Serial.println(now.hour(), DEC); 63 lcd.print(':'); 64 if(now.minute()<10) 65 lcd.print("0"); 66 lcd.print(now.minute(), DEC); 67 lcd.print(':'); 68 if(now.second()<10) 69 lcd.print("0"); 70 lcd.print(now.second(), DEC); 71 lcd.print(" "); 72 lcd.setCursor(0,1); 73 lcd.print(now.year(), DEC); 74 lcd.print('/'); 75 if(now.month()<10) 76 lcd.print("0"); 77 lcd.print(now.month(), DEC); 78 lcd.print('/'); 79 if(now.day()<10) 80 lcd.print("0"); 81 lcd.print(now.day(), DEC); 82 lcd.setCursor(11,1); 83 lcd.print(daysOfTheWeek[now.dayOfTheWeek()]); 84 lcd.setCursor(8,2); 85 if(temp<10) 86 lcd.print("0"); 87 lcd.print(temp); 88 Serial.print("temp: "); 89 Serial.println(temp); 90 lcd.print((char)223); 91 lcd.print("C"); 92 lcd.setCursor(2,3); 93 if (temp>=43) 94 lcd.print("High Temp Alert!"); 95 else if(temp>=31) 96 lcd.print(" Too Hot! "); 97 else if(temp>=28) 98 lcd.print(" Hot! "); 99 else if(temp>=23) 100 lcd.print(" Norm "); 101 else if(temp>=19) 102 lcd.print(" Cold "); 103 else if(temp>=15) 104 lcd.print(" Too Cold "); 105 else 106 lcd.print(" Low Temp Alert "); 107 Serial.print("dipi: "); 108 Serial.println(digitalRead(2)); 109 Serial.print(""); 110 } 111 112 void sleepNow() 113{ 114 set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here 115 116 sleep_enable(); // enables the sleep bit in the mcucr register 117 // so sleep is possible. just a safety pin 118 attachInterrupt(0,wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function 119 // wakeUpNow when pin 2 gets LOW 120 sleep_mode(); // here the device is actually put to sleep!! 121 // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP 122 sleep_disable(); // first thing after waking from sleep: 123 // disable sleep... 124 detachInterrupt(0); // disables interrupt 0 on pin 2 so the 125 // wakeUpNow code will not be executed 126 // during normal running time. 127} 128 129void wakeUpNow(){} 130
clk-temp-code
arduino
1// Date and time functions using a DS1307 RTC connected via I2C and Wire 2 lib 3//rtc-lcm(sweach led ghat' beshe va 16 lcd be 6 va 15 lcd be 7 vasl beshe)-lm35(A0)-ir(57K 4 ohm,1K ohm , be halat interrupt be paye 2 khroji mide)-lcd 5 6#include <Wire.h> 7#include<avr/sleep.h> 8#include 9 "RTClib.h" 10#include <LiquidCrystal_I2C.h> 11 12// Set the 13 LCD address to 0x3f or 0x27 (depends on your chip) for a 16 chars and 2 line display 14LiquidCrystal_I2C 15 lcd(0x3f, 20, 4); 16RTC_DS1307 rtc; 17 18char daysOfTheWeek[7][12] = {" Sunday", 19 " Monday", " Tuesday", "Wednesday", " Thursday", " Friday", " Saturday"}; 20 21void 22 setup () { 23 lcd.begin(); 24 rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));// 25 to set rtc init value by your pc time 26 pinMode(6,OUTPUT); 27 digitalWrite(6,0); 28 29 pinMode(7,OUTPUT); 30 digitalWrite(7,1); 31 delay(300); 32 attachInterrupt(0, 33 wakeUpNow, LOW); 34 lcd.backlight(); 35} 36 37void loop () { 38 pinMode(7,OUTPUT); 39 40 digitalWrite(7,1); 41 pinMode(6,OUTPUT); 42 for(int i=255;i>0; i=i-4){ 43 44 analogWrite(6,i); 45 delay(20); 46 } 47 finFunc(); 48 pinMode(6,INPUT); 49 //to put it to HiZ to low power using 50 digitalWrite(6,0); 51 pinMode(7,INPUT); 52 //to put it to HiZ to low power using 53 digitalWrite(7,0); 54 lcd.clear(); 55 56 lcd.setCursor(0,1); 57 lcd.print(" stand by "); 58 lcd.setCursor(0,2); 59 60 lcd.print(" hover your hand! "); 61 sleepNow(); 62 lcd.clear(); 63} 64void 65 finFunc(){ 66 for(int i=0; i<25; i++){ 67 mainFunc(); 68 delay(200); 69 70 } 71} 72void mainFunc(){ 73 int temp = (5.0 * analogRead(A0) * 100.0) / 74 1024; 75 DateTime now = rtc.now(); 76 lcd.setCursor(6,0); 77 if(now.hour()<10) 78 79 lcd.print("0"); 80 lcd.print(now.hour(), DEC); 81 Serial.print("time: 82 "); 83 Serial.println(now.hour(), DEC); 84 lcd.print(':'); 85 86 if(now.minute()<10) 87 lcd.print("0"); 88 lcd.print(now.minute(), 89 DEC); 90 lcd.print(':'); 91 if(now.second()<10) 92 lcd.print("0"); 93 94 lcd.print(now.second(), DEC); 95 lcd.print(" "); 96 lcd.setCursor(0,1); 97 98 lcd.print(now.year(), DEC); 99 lcd.print('/'); 100 if(now.month()<10) 101 102 lcd.print("0"); 103 lcd.print(now.month(), DEC); 104 lcd.print('/'); 105 106 if(now.day()<10) 107 lcd.print("0"); 108 lcd.print(now.day(), DEC); 109 110 lcd.setCursor(11,1); 111 lcd.print(daysOfTheWeek[now.dayOfTheWeek()]); 112 113 lcd.setCursor(8,2); 114 if(temp<10) 115 lcd.print("0"); 116 lcd.print(temp); 117 118 Serial.print("temp: "); 119 Serial.println(temp); 120 121 lcd.print((char)223); 122 lcd.print("C"); 123 lcd.setCursor(2,3); 124 125 if (temp>=43) 126 lcd.print("High Temp Alert!"); 127 else if(temp>=31) 128 129 lcd.print(" Too Hot! "); 130 else if(temp>=28) 131 lcd.print(" 132 Hot! "); 133 else if(temp>=23) 134 lcd.print(" Norm 135 "); 136 else if(temp>=19) 137 lcd.print(" Cold "); 138 139 else if(temp>=15) 140 lcd.print(" Too Cold "); 141 else 142 143 lcd.print(" Low Temp Alert "); 144 Serial.print("dipi: "); 145 146 Serial.println(digitalRead(2)); 147 Serial.print(""); 148 } 149 150 151 void sleepNow() 152{ 153 set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep 154 mode is set here 155 156 sleep_enable(); // enables the sleep bit in 157 the mcucr register 158 // so sleep is possible. just 159 a safety pin 160 attachInterrupt(0,wakeUpNow, LOW); // use interrupt 0 (pin 161 2) and run function 162 // wakeUpNow when 163 pin 2 gets LOW 164 sleep_mode(); // here the device is actually put 165 to sleep!! 166 // THE PROGRAM CONTINUES FROM HERE AFTER 167 WAKING UP 168 sleep_disable(); // first thing after waking from sleep: 169 170 // disable sleep... 171 detachInterrupt(0); // 172 disables interrupt 0 on pin 2 so the 173 // wakeUpNow 174 code will not be executed 175 // during normal running 176 time. 177} 178 179void wakeUpNow(){} 180
Downloadable files
clk&temp_schematic
clk&temp_schematic

clk&temp_schematic
clk&temp_schematic

Documentation
final_pcb
final_pcb

clk-temp-shield
PCB pic, Altium Designer
clk-temp-shield

clk-temp-shield
PCB pic, Altium Designer
clk-temp-shield

final_pcb
final_pcb

clk-temp-pcb
clk-temp-pcb

Comments
Only logged in users can leave comments