Easter has been quite productive for me, this is project 3 out of 4 is rechargeable battery powered arduino clock with temp and humidity function. Nothing fancy, but highly practical and accurate. The code is a mess, but i have shared it down below, i know someone out there can clean it up and make it more efficient, but for now, its working and doing what it needs so, show the temp and the time.
Hardware is kind of inefficient for this task, arduino mega and 3.2″lcd are both overkill and power hungry. There is an RTC and temp humidity sensor, 18650 battery, boost and charge controller. As usual i did a really crap job at cutting the hole out, I really should have done this in the CNC, I might even make a how to video on how i do that later today.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
//Includes #include <TFT_HX8357.h> #include <DS3231.h> #include <Wire.h> #include "DHT.h" //Defines #define DHTPIN A0 #define DHTTYPE DHT22 //Instances TFT_HX8357 tft = TFT_HX8357(); DHT dht(DHTPIN, DHTTYPE); DS3231 Clock; //Global Variables const long interval = 60000; unsigned long previousMillis = 0; float temp; float humid; bool h12; bool PM; bool Century = false; int DAW; String DayOfWeek; int L_Date; int L_Month; int L_Year; int L_Hour; int L_Minute; String AmPm; void setup() { dht.begin(); Wire.begin(); tft.init(); tft.setRotation(1); tft.fillScreen(TFT_BLACK); } void loop() { unsigned long currentMillis = millis(); //Do stuff here every 60 seconds if (currentMillis - previousMillis >= interval) { previousMillis = currentMillis; tft.fillScreen(TFT_BLACK); tft.setCursor(10, 10, 1); tft.setTextColor(TFT_WHITE); tft.setTextFont(4); tft.setTextSize(1); GetDay(); tft.print(DayOfWeek); tft.print("-: "); GetDate(); if (L_Date < 10) tft.print("0"); tft.print(L_Date); tft.print("-"); if (L_Month < 10) tft.print("0"); tft.print(L_Month); tft.print("-"); tft.println(L_Year); GetTime(); tft.setCursor(30, 100, 7); tft.setTextSize(2); if (L_Hour < 10) tft.print("0"); tft.print(L_Hour); tft.print(":"); if (L_Minute < 10) tft.print("0"); tft.print(L_Minute); tft.setTextFont(6); tft.setTextSize(2); tft.println(AmPm); GetTempHumid(); tft.setCursor(20, 280, 4); tft.setTextSize(1); tft.print("Temp: "); tft.print(temp); tft.print("Deg C"); tft.setCursor(260, 280, 4); tft.print("Humidity: "); tft.print(humid); tft.print("%"); } } void GetTempHumid() { humid = dht.readHumidity(); temp = dht.readTemperature(); return; } void GetTime() { L_Hour = Clock.getHour(h12, PM); L_Minute = Clock.getMinute(); if (h12) { if (PM) { AmPm = "pm"; } else { AmPm = "am"; } } return; } void GetDate() { L_Date = Clock.getDate(); L_Month = Clock.getMonth(Century); L_Year = Clock.getYear(); L_Year += 2000; return; } void GetDay() { DAW = Clock.getDoW(); switch (DAW) { case 0: DayOfWeek = "Sunday"; break; case 1: DayOfWeek = "Monday"; break; case 2: DayOfWeek = "Tuesday"; break; case 3: DayOfWeek = "Wednesday"; break; case 4: DayOfWeek = "Thursday"; break; case 5: DayOfWeek = "Friday"; break; case 6: DayOfWeek = "Saturday"; break; default: DayOfWeek = "ERROR"; break; } return; } |




