Components and supplies
DHT11 Temperature & Humidity Sensor (4 pins)
Breadboard (generic)
Arduino UNO
Standard LCD - 16x2 White on Blue
Rotary potentiometer (generic)
Jumper wires (generic)
Button
Project description
Code
Clock without using RTC with temperature and humidity indicator
arduino
Clock without using RTC with temperature and humidity indicator
1// Ahmad Ordikhani Seyedlar 2 3#include <LiquidCrystal.h> 4#include <SimpleDHT.h> 5 6// initialize the library with the numbers of the interface pins 7LiquidCrystal lcd(7, 8, 9, 10, 11, 12); 8volatile int sec, minute = 0, hour = 0; 9int b_h = 5; 10int b_m = 6; 11int pinDHT11 = 2; 12int b_startstop = 3; 13bool startstop = false; 14 15SimpleDHT11 dht11; 16 17void setup() { 18 19 // set up the LCD's number of columns and rows: 20 lcd.begin(16, 2); 21 22 lcd.setCursor(0, 0); 23 lcd.print("Ahmad Ordikhani"); 24 lcd.setCursor(0, 1); 25 lcd.print("Clk without RTC"); 26 delay(3000); 27 lcd.clear(); 28 29 pinMode(b_h, INPUT_PULLUP); 30 pinMode(b_m, INPUT_PULLUP); 31 pinMode(b_startstop, INPUT_PULLUP); 32 33 attachInterrupt(digitalPinToInterrupt(3), buttons, FALLING); 34 35 36} 37 38void loop() { 39 40 //Setting the time will stop the clock to set the time 41 while (startstop == false) 42 { 43 lcd.setCursor(0, 1); 44 lcd.print("SET"); 45 delay(100); 46 lcd.setCursor(0, 0); 47 lcd.print("Time: "); 48 if(hour<10) 49 { 50 lcd.print("0"); 51 lcd.print(hour); 52 } 53 else 54 lcd.print(hour); 55 56 lcd.print(":"); 57 if(minute<10) 58 { 59 lcd.print("0"); 60 lcd.print(minute); 61 } 62 else 63 lcd.print(minute); 64 lcd.print(":"); 65 if(sec<10) 66 { 67 lcd.print("0"); 68 lcd.print(sec); 69 } 70 else 71 lcd.print(sec); 72 lcd.print(" "); 73 74 if (digitalRead(b_h) == LOW) 75 { 76 hour++; 77 if (hour > 23) 78 hour = 0; 79 } 80 81 if (digitalRead(b_m) == LOW) 82 { 83 minute++; 84 if (minute > 59) 85 minute = 0; 86 } 87 88 } 89 90 //Start the clock 91 while (startstop == true) 92 { 93 94 95 // noInterrupts(); 96 // read with raw sample data. 97 byte temperature = 0; 98 byte humidity = 0; 99 byte data[40] = {0}; 100 if (dht11.read(pinDHT11, &temperature, &humidity, data)) { 101 lcd.setCursor(0, 1); 102 lcd.print("Read DHT11 failed"); 103 return; 104 } 105 lcd.setCursor(0, 1); 106 lcd.print("Temp:"); 107 lcd.print((int)temperature); 108 //lcd.print("*C"); 109 lcd.print(" "); 110 lcd.print("Hum.:"); 111 lcd.print((int)humidity); 112 lcd.print("%"); 113 //Serial.print((int)temperature); Serial.print(" *C, "); 114 // Serial.print((int)humidity); Serial.println(" %"); 115 116 lcd.setCursor(0, 0); 117 //sec=millis()/1000; 118 delay(1000); 119 lcd.print("Time: "); 120 if (hour < 10) 121 { 122 lcd.print("0"); 123 lcd.print(hour); 124 } 125 else 126 { 127 lcd.print(hour); 128 } 129 lcd.print(":"); 130 if (minute < 10) 131 { 132 lcd.print("0"); 133 lcd.print(minute); 134 } 135 else 136 { 137 lcd.print(minute); 138 139 } lcd.print(":"); 140 if (sec < 10) 141 { 142 lcd.print("0"); 143 lcd.print(sec); 144 } 145 else 146 { 147 lcd.print(sec); 148 } 149 lcd.print(" "); 150 //lcd.print(startstop); 151 sec++; 152 if (sec > 59) 153 { 154 minute++; 155 sec = 0; 156 //lcd.clear(); 157 } 158 159 if (minute > 59) 160 { 161 hour++; 162 minute = 0; 163 //lcd.clear(); 164 } 165 if (hour > 23) 166 { 167 hour = 0; 168 //lcd.clear(); 169 170 } 171 } 172} 173 174//Start/Stop the clock 175void buttons() 176{ 177 lcd.clear(); 178 startstop = !startstop; 179 180 181} 182 183
Clock without using RTC with temperature and humidity indicator
arduino
Clock without using RTC with temperature and humidity indicator
1// Ahmad Ordikhani Seyedlar 2 3#include <LiquidCrystal.h> 4#include <SimpleDHT.h> 5 6// initialize the library with the numbers of the interface pins 7LiquidCrystal lcd(7, 8, 9, 10, 11, 12); 8volatile int sec, minute = 0, hour = 0; 9int b_h = 5; 10int b_m = 6; 11int pinDHT11 = 2; 12int b_startstop = 3; 13bool startstop = false; 14 15SimpleDHT11 dht11; 16 17void setup() { 18 19 // set up the LCD's number of columns and rows: 20 lcd.begin(16, 2); 21 22 lcd.setCursor(0, 0); 23 lcd.print("Ahmad Ordikhani"); 24 lcd.setCursor(0, 1); 25 lcd.print("Clk without RTC"); 26 delay(3000); 27 lcd.clear(); 28 29 pinMode(b_h, INPUT_PULLUP); 30 pinMode(b_m, INPUT_PULLUP); 31 pinMode(b_startstop, INPUT_PULLUP); 32 33 attachInterrupt(digitalPinToInterrupt(3), buttons, FALLING); 34 35 36} 37 38void loop() { 39 40 //Setting the time will stop the clock to set the time 41 while (startstop == false) 42 { 43 lcd.setCursor(0, 1); 44 lcd.print("SET"); 45 delay(100); 46 lcd.setCursor(0, 0); 47 lcd.print("Time: "); 48 if(hour<10) 49 { 50 lcd.print("0"); 51 lcd.print(hour); 52 } 53 else 54 lcd.print(hour); 55 56 lcd.print(":"); 57 if(minute<10) 58 { 59 lcd.print("0"); 60 lcd.print(minute); 61 } 62 else 63 lcd.print(minute); 64 lcd.print(":"); 65 if(sec<10) 66 { 67 lcd.print("0"); 68 lcd.print(sec); 69 } 70 else 71 lcd.print(sec); 72 lcd.print(" "); 73 74 if (digitalRead(b_h) == LOW) 75 { 76 hour++; 77 if (hour > 23) 78 hour = 0; 79 } 80 81 if (digitalRead(b_m) == LOW) 82 { 83 minute++; 84 if (minute > 59) 85 minute = 0; 86 } 87 88 } 89 90 //Start the clock 91 while (startstop == true) 92 { 93 94 95 // noInterrupts(); 96 // read with raw sample data. 97 byte temperature = 0; 98 byte humidity = 0; 99 byte data[40] = {0}; 100 if (dht11.read(pinDHT11, &temperature, &humidity, data)) { 101 lcd.setCursor(0, 1); 102 lcd.print("Read DHT11 failed"); 103 return; 104 } 105 lcd.setCursor(0, 1); 106 lcd.print("Temp:"); 107 lcd.print((int)temperature); 108 //lcd.print("*C"); 109 lcd.print(" "); 110 lcd.print("Hum.:"); 111 lcd.print((int)humidity); 112 lcd.print("%"); 113 //Serial.print((int)temperature); Serial.print(" *C, "); 114 // Serial.print((int)humidity); Serial.println(" %"); 115 116 lcd.setCursor(0, 0); 117 //sec=millis()/1000; 118 delay(1000); 119 lcd.print("Time: "); 120 if (hour < 10) 121 { 122 lcd.print("0"); 123 lcd.print(hour); 124 } 125 else 126 { 127 lcd.print(hour); 128 } 129 lcd.print(":"); 130 if (minute < 10) 131 { 132 lcd.print("0"); 133 lcd.print(minute); 134 } 135 else 136 { 137 lcd.print(minute); 138 139 } lcd.print(":"); 140 if (sec < 10) 141 { 142 lcd.print("0"); 143 lcd.print(sec); 144 } 145 else 146 { 147 lcd.print(sec); 148 } 149 lcd.print(" "); 150 //lcd.print(startstop); 151 sec++; 152 if (sec > 59) 153 { 154 minute++; 155 sec = 0; 156 //lcd.clear(); 157 } 158 159 if (minute > 59) 160 { 161 hour++; 162 minute = 0; 163 //lcd.clear(); 164 } 165 if (hour > 23) 166 { 167 hour = 0; 168 //lcd.clear(); 169 170 } 171 } 172} 173 174//Start/Stop the clock 175void buttons() 176{ 177 lcd.clear(); 178 startstop = !startstop; 179 180 181} 182 183
Downloadable files
Clock withou using RTC with Temperature und Humidity indicator
Clock withou using RTC with Temperature und Humidity indicator
Comments
Only logged in users can leave comments