Components and supplies
Arduino pro Mini 3v
0.91" I2C OLED 128x32
USB Cable, USB Type C Plug
Battery Lipo 500 mAh
Female Header Pins
TP4056 Micro USB 5V 1A Li - Ion Battery Charger Module (AZDelivery)
Tactile button
Adafruit RTC DS3231 Real time clock
Tools and machines
Digital Multimeter
Soldering kit
Apps and platforms
Arduino IDE 2.0 (beta)
SOLIDWORKS
Project description
Code
arduino_watch_3.o
c
code
1#include <RTClib.h> 2#include <Wire.h> 3#include <Adafruit_GFX.h> 4#include <Adafruit_SSD1306.h> 5#include "TomThumb.h" 6#define SCREEN_WIDTH 128 7#define SCREEN_HEIGHT 32 8#define SCREEN_ADDRESS 0x3C 9 10Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); 11RTC_DS3231 rtc; 12char t[10]; 13char t2[10]; 14char d[10]; 15const char* daysOfTheWeek[] = {"SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"}; 16const char* monthname[] = {"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "OCTOBER", "OCTOBER", "NOVEMBER", "DECEMBER"}; 17int year = 2024; 18int month = 02; 19int day = 25; 20int hour = 8; 21int minute = 46; 22int second = 00; 23char pmam[3]; 24const int buttonPin1 = 8; 25int buttonState1 = HIGH; 26int lastButtonState1 = HIGH; 27int pressCount1 = 0; 28const int buttonPin2 = 7; 29int buttonState2 = HIGH; 30int lastButtonState2 = HIGH; 31int pressCount2 = 0; 32const int buttonPin3 = 9; 33int buttonState3 = HIGH; 34int lastButtonState3 = HIGH; 35int timeb, dateb, battb = 0; 36const int buttonPins = 6; 37#define voltmeter A0 38double offset = 0.09; 39 40const uint8_t sign [] PROGMEM = { 41 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 42 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 43 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 44 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 45 0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 46 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 47 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 48 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 49 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 50 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 51 0x00, 0x00, 0x00, 0x05, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 52 0x00, 0x00, 0x00, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 53 0x00, 0x00, 0x00, 0x28, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 54 0x00, 0x00, 0x00, 0x48, 0x80, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 55 0x00, 0x00, 0x00, 0xC8, 0x40, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 56 0x00, 0x00, 0x00, 0x38, 0x78, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 57 0x00, 0x00, 0x00, 0x0F, 0xA7, 0x80, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 58 0x00, 0x00, 0x00, 0x08, 0x11, 0x00, 0x02, 0x00, 0x03, 0x81, 0xBF, 0x80, 0x00, 0x00, 0x00, 0x00, 59 0x00, 0x00, 0x00, 0x10, 0x12, 0x00, 0x02, 0x00, 0x03, 0x82, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 60 0x00, 0x00, 0x00, 0x10, 0x0C, 0x00, 0x02, 0x03, 0x80, 0xE6, 0x40, 0x60, 0x00, 0x00, 0x00, 0x00, 61 0x00, 0x00, 0x00, 0x10, 0x08, 0x00, 0x02, 0x07, 0x01, 0xBC, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 62 0x00, 0x00, 0x01, 0xD0, 0x14, 0x00, 0x02, 0x66, 0x63, 0x08, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 63 0x00, 0x00, 0x00, 0x3F, 0xE4, 0x00, 0x06, 0xFE, 0x7E, 0x18, 0x00, 0x1C, 0x32, 0x00, 0x00, 0x00, 64 0x00, 0x00, 0x00, 0x10, 0x02, 0x01, 0x87, 0x82, 0xD8, 0x00, 0x00, 0x06, 0x02, 0x00, 0x00, 0x00, 65 0x00, 0x00, 0x00, 0x10, 0x02, 0x03, 0x4D, 0x03, 0x80, 0x00, 0x00, 0x06, 0x3F, 0x00, 0x00, 0x00, 66 0x00, 0x00, 0x00, 0x20, 0x01, 0x02, 0xF9, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x01, 0x00, 0x00, 0x00, 67 0x00, 0x00, 0x00, 0x20, 0x01, 0x02, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x81, 0x00, 0x00, 0x00, 68 0x00, 0x00, 0x00, 0x20, 0x00, 0x83, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 69 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 70 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 71 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 72 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 73}; 74 75 76void setup() 77{ 78 Serial.begin(9600); 79 display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS); 80 display.clearDisplay(); 81 Wire.begin(); 82 pinMode(buttonPin1, INPUT_PULLUP); 83 pinMode(buttonPin2, INPUT_PULLUP); 84 pinMode(buttonPins, INPUT_PULLUP); 85 //pinMode(press, INPUT_PULLUP); 86 //pinMode(lpb, INPUT_PULLUP); 87 //pinMode(rpb, INPUT_PULLUP); 88 rtc.begin(); 89 //rtc.adjust(DateTime(F(__DATE__),F(__TIME__))); 90 rtc.adjust(DateTime(year, month, day, hour, minute, second)); 91 pinMode(voltmeter, INPUT); 92} 93void loop() 94{ 95 96 DateTime now = rtc.now(); 97 98 sprintf(t2, "%02d:%02d:%02d", now.hour(), now.minute(), now.second()); 99 100 //sprintf(t, "%02d:%02d:%02d %02d/%02d/%02d", now.hour(), now.minute(), now.second(), now.day(), now.month(), now.year()); 101 if (now.hour() >= 13) { 102 sprintf(t, "%02d:%02d:%02d", now.hour() - 12, now.minute(), now.second()); 103 sprintf(pmam, "%c%c", 'P', 'M'); 104 } 105 else if (now.hour() == 00) { 106 sprintf(t, "%02d:%02d:%02d", now.hour() + 12, now.minute(), now.second()); 107 sprintf(pmam, "%c%c", 'P', 'M'); 108 } 109 else { 110 sprintf(t, "%02d:%02d:%02d", now.hour(), now.minute(), now.second()); 111 sprintf(pmam, "%c%c", 'A', 'M'); 112 } 113 sprintf(d, "%02d/%02d", now.day(), now.month()); 114 115 buttonState1 = digitalRead(buttonPin1); 116 117 if (buttonState1 == LOW && lastButtonState1 == HIGH) { 118 delay(90); 119 120 if (buttonState1 == LOW) { 121 pressCount1++; 122 Serial.println(pressCount1); 123 if (pressCount1 == 2) { 124 pressCount1 = 0; 125 } 126 } 127 } 128 lastButtonState1 = buttonState1; 129 130 buttonState2 = digitalRead(buttonPin2); 131 132 if (buttonState2 == LOW && lastButtonState2 == HIGH) { 133 delay(90); 134 135 if (buttonState2 == LOW) { 136 pressCount2++; 137 Serial.println(pressCount2); 138 if (pressCount2 == 3 ) { 139 pressCount2 = 0; 140 } 141 } 142 } 143 lastButtonState2 = buttonState2; 144 145 146 if (pressCount1 == 0) { 147 buttonState3 = digitalRead(buttonPin3); 148 display.ssd1306_command(SSD1306_DISPLAYOFF); 149 } 150 151 else { 152 display.ssd1306_command(SSD1306_DISPLAYON); 153 if (digitalRead(buttonPins) == 0) { 154 //display.ssd1306_command(SSD1306_DISPLAYON); 155 display.clearDisplay(); 156 display.setTextColor(WHITE); 157 display.setTextSize(1); 158 display.setFont(NULL); 159 display.drawBitmap(0, 0, sign, 128, 32, 1); 160 display.display(); 161 } 162 else if (pressCount2 == 0) { 163 164 buttonState3 = digitalRead(buttonPin3); 165 166 if (buttonState3 == LOW && lastButtonState3 == HIGH) { 167 delay(90); 168 169 if (buttonState3 == LOW) { 170 timeb++; 171 Serial.println(timeb); 172 if (timeb == 2 ) 173 timeb = 0; 174 } 175 } 176 lastButtonState3 = buttonState3; 177 if (timeb == 0) { 178 display.clearDisplay(); 179 display.setTextColor(WHITE); 180 display.setTextSize(2); 181 display.setFont(&TomThumb); 182 display.setCursor(0, 10); 183 display.println("TIME: (24F)"); 184 display.setTextSize(3); 185 display.setCursor(27, 27); 186 display.print(t2); 187 display.display(); 188 } 189 else { 190 display.clearDisplay(); 191 display.setTextColor(WHITE); 192 display.setTextSize(2); 193 display.setFont(&TomThumb); 194 display.setCursor(0, 10); 195 display.println("TIME:"); 196 display.setTextSize(3); 197 display.setCursor(27, 27); 198 display.print(t); 199 display.setTextSize(1); 200 display.print(pmam); 201 display.display(); 202 } 203 } 204 205 else if (pressCount2 == 1) { 206 buttonState3 = digitalRead(buttonPin3); 207 208 if (buttonState3 == LOW && lastButtonState3 == HIGH) { 209 delay(90); 210 211 if (buttonState3 == LOW) { 212 dateb++; 213 Serial.println(dateb); 214 if (dateb == 3 ) 215 dateb = 0; 216 } 217 } 218 lastButtonState3 = buttonState3; 219 220 if (dateb == 1) { 221 display.clearDisplay(); 222 display.setTextColor(WHITE); 223 display.setTextSize(2); 224 display.setFont(&TomThumb); 225 display.setCursor(0, 10); 226 display.println("DAY:"); 227 display.setTextSize(3); 228 display.setCursor(8, 27); 229 display.print(daysOfTheWeek[now.dayOfTheWeek()]); 230 display.display(); 231 } 232 else if (dateb == 2) { 233 234 display.clearDisplay(); 235 display.setTextColor(WHITE); 236 display.setTextSize(2); 237 display.setFont(&TomThumb); 238 display.setCursor(0, 10); 239 display.println("MONTH:"); 240 display.setTextSize(3); 241 display.setCursor(8, 27); 242 display.print(monthname[month - 1]); 243 display.display(); 244 } 245 else { 246 display.clearDisplay(); 247 display.setTextColor(WHITE); 248 display.setTextSize(2); 249 display.setFont(&TomThumb); 250 display.setCursor(0, 10); 251 display.println("DATE:"); 252 display.setTextSize(3); 253 display.setCursor(37, 27); 254 display.print(d); 255 display.display(); 256 } 257 } 258 else if (pressCount2 == 2) { 259 buttonState3 = digitalRead(buttonPin3); 260 261 if (buttonState3 == LOW && lastButtonState3 == HIGH) { 262 delay(90); 263 264 if (buttonState3 == LOW) { 265 battb++; 266 Serial.println(dateb); 267 if (battb == 3 ) 268 battb = 0; 269 } 270 } 271 int volt = analogRead(voltmeter); 272 //double voltage = map(volt, 0, 1024, 0, 2500); 273 double voltage = (volt / 1023.0)* 5.0; 274 voltage = voltage + 2.64; 275 lastButtonState3 = buttonState3; 276 display.clearDisplay(); 277 display.setTextColor(WHITE); 278 display.setTextSize(2); 279 display.setFont(&TomThumb); 280 display.setCursor(0, 10); 281 display.print("BATTERY: "); 282 display.print(voltage, 1); 283 display.print("v"); 284 delay(100); 285 display.drawRect(18, 12, 80, 20, 1); 286 display.drawRect(97, 17, 5, 10, 1); 287 if (voltage <= 2.99) 288 display.fillRect(19, 12, 10, 20, 1); 289 else if (voltage >= 3.00 && voltage <= 3.20 ) 290 display.fillRect(19, 12, 20, 20, 1); 291 else if (voltage >= 3.21 && voltage <= 3.50 ) 292 display.fillRect(19, 12, 40, 20, 1); 293 else if (voltage >= 3.51 && voltage <= 3.80 ) 294 display.fillRect(19, 12, 60, 20, 1); 295 else if (voltage >= 3.81 && voltage <= 4.30 ) 296 display.fillRect(19, 12, 80, 20, 1); 297 display.display(); 298 } 299 } 300}
Downloadable files
Bottom_part
STL file
bott.STL
Top_part
STL file
topp.STL
Documentation
circuit diagram
fritzing
arduino_watch_bb.png
Comments
Only logged in users can leave comments
mahesh2332005
a year ago
Ok