Wifi Binary Clock

Introduction: Wifi Binary Clock

Inspired by a binary clock that was difficult to read, and very inaccurate, I set out to create a simple to read binary clock that set itself over a wifi connection. Once the WiFi credentials have been entered into the Arduino code as well as the desired timezone offset, and the code is uploaded to the ESP32 board the ESP32 gets the time and then converts it into a usable format,then the clock will adjust for daylight savings, tell you if it is AM or PM and on Monday mornings the clock will reset the time, over its wifi connection, so that the clock stays accurate and will not be ahead or behind.

unfortunately, this is my first Instructables as well as being my first time using an ESP32 development board, so there was a lot of trial and error with little to no recording of the process.

Step 1: Gather Materials

For this clock I used

1) A picture frame. Mine is roughly 8.25in x 6.25in but the size can be adjusted to your preference.

2) 20 LED's (I choose green but any color works)

3) 5 rectifying diodes

4) 7 ≈ 70Ω resistors

5) 1 ESP32 Development Board

6) 1 USB to micro USB cable

7) 1 Sheet of foam board with black paper on each side of it.

Step 2: Assemble the Clock

I then took the foam board and cut a rectangular piece that fit into the back of the picture frame. I then gently sketched where I thought the LED's would look the best with the columns for the hours minutes and seconds spread apart enough to read the clock easily.

I then gently poked a hole in the foam everywhere I was going to place an LED. After testing that the LED's all work, to help diffuse the light go over each LED with sandpaper to give them a frosted finish. With the LEED's in their appropriate places in the Foam board, I then began to wire the circuit following this schematic.

Step 3: Programing

Once I had downloaded everything I needed to use the Arduino IDE to program the ESP32 board I started with the WiFi time example and went from there. And ended with this final version of the Arduino code. Just a heads up I am not an expert and could probably clean up my code, however, this worked for me.

#include <wifi.h>
#include "time.h"

int second=0, minute=0, weekday=0, hour24=0, hour=0, min_ones=0, sec_ones=0, day_of_the_month=0, month=0, year=0, DST=0; // initializing time variables int A=15, B=2, C=4, D=5, E=18, F=19, G=21, H=22, I=23, J=33, K=26, L=25;

const char* ssid = "********"; // your wifi ssid const char* password = "********"; // your wifi password

const char* ntpServer = "pool.ntp.org"; const long gmtOffset_sec = 0; // offset for your timezone const int daylightOffset_sec = 0; //daylight savings offset

void printsetTime() { struct tm timeinfo; if(!getLocalTime(&timeinfo)){ Serial.println("Failed to obtain time"); return; } }

void printLocalTime() { //connect to WiFi Serial.printf("Connecting to %s ", ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(" CONNECTED"); delay(2000); //init and get the time configTime(gmtOffset_sec, daylightOffset_sec, ntpServer); printsetTime();

//disconnect WiFi WiFi.disconnect(true); WiFi.mode(WIFI_OFF); }

void setup() { pinMode(A,OUTPUT); pinMode(B,OUTPUT); pinMode(C,OUTPUT); pinMode(D,OUTPUT); pinMode(E,OUTPUT); pinMode(F,OUTPUT); pinMode(G,OUTPUT); pinMode(H,OUTPUT); pinMode(I,OUTPUT); pinMode(J,OUTPUT); pinMode(K,OUTPUT); pinMode(L,OUTPUT);

Serial.begin(115200); printLocalTime(); }

void loop() { struct tm *local,*gm; time_t t; t = time(NULL); local = localtime(&t); second =( local-> tm_sec); minute =( local-> tm_min); hour24 =( local-> tm_hour); weekday = (local-> tm_wday); day_of_the_month = (local-> tm_mday); month = (local-> tm_mon); year = (local-> tm_year); min_ones =(minute %10); sec_ones =(second %10); month = month+1; year = year-100; year = year+2000; if(DST==1){ hour24= hour24 +1; } if(DST==0){ hour24= hour24; }

digitalWrite(J,LOW); if(hour24 > 12){ hour = hour24 -12; digitalWrite(L,HIGH); digitalWrite(K,LOW); }

if(hour24 > 11 && hour24 < 13){ hour = hour24; digitalWrite(L,HIGH); digitalWrite(K,LOW); }

if(hour24 < 12){ hour = hour24; digitalWrite(K,HIGH); digitalWrite(L,LOW); }

if( month < 3 && month > 11){ DST=0; } if( month > 3 && month < 11){ DST=1; }

int previousSunday = day_of_the_month - weekday; if (month == 3 && previousSunday >= 8 && weekday > 0){ DST=1; } if (month == 3 && previousSunday >= 8 && weekday == 0 && hour24 > 1){ DST=1; } if (month == 3 && previousSunday >= 8 && weekday == 0 && hour24 < 2){ DST=0; } if (month == 3 && previousSunday < 8){ DST=0; } if (month == 11 && previousSunday >0 && weekday > 0){ DST=0; } if (month == 11 && previousSunday <= 7 && weekday == 0 && hour24 > 1){ DST=0; } if (month == 11 && previousSunday >= 0 && weekday == 0 && hour24 < 2){ DST=1; } if(day_of_the_month == 14 && hour24 == 24 && minute == 0 && second == 0){ printLocalTime(); } if(day_of_the_month == 28 && hour24 == 24 && minute == 0 && second == 0){ printLocalTime(); }

delay(1); digitalWrite(K,LOW); digitalWrite(L,LOW);

Serial.print(hour24); Serial.print(":"); Serial.print(hour); Serial.print(":"); Serial.print(minute); Serial.print(":"); Serial.print(second); Serial.print(" weekday = " ); Serial.print(weekday); Serial.print(" day of the month = " ); Serial.print(day_of_the_month); Serial.print(" month = " ); Serial.print(month); Serial.print(" DST = " ); Serial.print(DST); Serial.print(" "); Serial.println(previousSunday); delay(1);

digitalWrite(A,HIGH); digitalWrite(B,HIGH); digitalWrite(C,HIGH); digitalWrite(D,HIGH);

//seconds ones place digitalWrite(I, HIGH); if(sec_ones == 1 || sec_ones == 3 || sec_ones == 5 || sec_ones == 7 || sec_ones == 9) { digitalWrite(D,LOW);delay(1);digitalWrite(D,HIGH);} if(sec_ones == 2 || sec_ones == 3 || sec_ones == 6 || sec_ones == 7) { digitalWrite(C,LOW);delay(1);digitalWrite(C,HIGH);} if(sec_ones == 4 || sec_ones == 5 || sec_ones == 6 || sec_ones == 7) { digitalWrite(B,LOW);delay(1);digitalWrite(B,HIGH);} if(sec_ones == 8 || sec_ones == 9) { digitalWrite(A,LOW);delay(1);digitalWrite(A,HIGH);} digitalWrite(I, LOW); //seconds tens place digitalWrite(H, HIGH); //seconds tens place if((second >= 10 && second < 20) || (second >= 30 && second < 40) || (second >= 50 && second < 60)) { digitalWrite(D,LOW);delay(1);digitalWrite(D,HIGH);} if(second >= 20 && second < 40) {digitalWrite(C,LOW);delay(1);digitalWrite(C,HIGH);} if(second >= 40 && second < 60) {digitalWrite(B,LOW);delay(1);digitalWrite(B,HIGH);} digitalWrite(H, LOW);

//minutes ones place digitalWrite(G, HIGH); if(min_ones == 1 || min_ones == 3 || min_ones == 5 || min_ones == 7 || min_ones == 9) { digitalWrite(D,LOW);delay(1);digitalWrite(D,HIGH);} if(min_ones == 2 || min_ones == 3 || min_ones == 6 || min_ones == 7) { digitalWrite(C,LOW);delay(1);digitalWrite(C,HIGH);} if(min_ones == 4 || min_ones == 5 || min_ones == 6 || min_ones == 7) { digitalWrite(B,LOW);delay(1);digitalWrite(B,HIGH);} if(min_ones == 8 || min_ones == 9) { digitalWrite(A,LOW);delay(1);digitalWrite(A,HIGH);} digitalWrite(G, LOW); //minutes tens place digitalWrite(F, HIGH); if((minute >= 10 && minute < 20) || (minute >= 30 && minute < 40) || (minute >= 50 && minute < 60)) { digitalWrite(D,LOW);delay(1);digitalWrite(D,HIGH);} if(minute >= 20 && minute < 40) {digitalWrite(C,LOW);delay(1);digitalWrite(C,HIGH);} if(minute >= 40 && minute < 60) {digitalWrite(B,LOW);delay(1);digitalWrite(B,HIGH);} digitalWrite(F, LOW); //hour digitalWrite(E, HIGH); if(hour == 1 || hour == 3 || hour == 5 || hour == 7 || hour == 9 ||hour == 11) { digitalWrite(D,LOW);delay(1);digitalWrite(D,HIGH);} if(hour == 2 || hour == 3 || hour == 6 || hour == 7 || hour == 10 ||hour == 11) { digitalWrite(C,LOW);delay(1);digitalWrite(C,HIGH);} if(hour == 4 || hour == 5 || hour == 6 || hour == 7 ||hour == 12) { digitalWrite(B,LOW);delay(1);digitalWrite(B,HIGH);} if(hour == 8 || hour == 9 ||hour == 10 ||hour == 11 ||hour == 12) { digitalWrite(A,LOW);delay(1);digitalWrite(A,HIGH);} digitalWrite(E, LOW); }

**** I am not an expert ****

Step 4: Reading the Finished Clock

The clock is comprised of three vertical sections, the first section is the hour section, containing one column of four LED's. To get the time in hours we must add up the illuminated LED's, the bottom led has a value of 1 the second from the bottom has a value of two, the third a value of four, and the top LED has a value of 8. So you then add up the LED's that are illuminated. for example, if the bottom and top LED's where on that would be a 1 and an 8 so it would be hour 9. The process is similar for the minutes and seconds except that they each have two columns, one for the tens place and one for the minutes place.

Step 5: Optional 3D Printed Light Diffusion

The clock is finished now, however for those with access to a 3D printer, it would be beneficial to 3D print white caps for the individual LED's to help diffuse the lights.

Share

    Recommendations

    • Water Contest

      Water Contest
    • Metalworking Contest

      Metalworking Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    Discussions