Arnov Sharma
Published © MIT

Internet-Week Clock

The Week Clock is a straightforward desk clock that indicates the current day.

BeginnerFull instructions provided1 hour155
Internet-Week Clock

Things used in this project

Hardware components

NextPCB PCB
×1
Beetle ESP32 C6 Mini Development Board for Wireless Smart Wearable Device
DFRobot Beetle ESP32 C6 Mini Development Board for Wireless Smart Wearable Device
×1

Software apps and online services

Fusion
Autodesk Fusion
Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Seperator

Left Stand

Right Stand

Fusion360File

Schematics

SCH

Code

CODE FINAL

C/C++
#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>

// Define LED pins
#define LED_PIN_1 0
#define LED_PIN_2 1
#define LED_PIN_3 4
#define LED_PIN_4 5
#define LED_PIN_5 6
#define LED_PIN_6 7
#define LED_PIN_7 2

const int ledPins[] = {LED_PIN_1, LED_PIN_2, LED_PIN_3, LED_PIN_4, LED_PIN_5, LED_PIN_6, LED_PIN_7};

// Number of LEDs
const int numLEDs = 7;
const int ledBrightness = 128; // 50% brightness (128 out of 255)

// WiFi credentials
const char* ssid = "UR SSID";
const char* password = "UR PASS";

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 19800, 60000); // IST timezone offset (19800 seconds)

unsigned long lastChange = 0;

// Function to connect to Wi-Fi
void connectToWiFi() {
    Serial.print("Connecting to WiFi...");
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED && millis() < 20000) { // Limit connection attempt to 20 seconds
        delay(500);
        Serial.print(".");
    }
    if (WiFi.status() == WL_CONNECTED) {
        Serial.println("Connected to WiFi");
    } else {
        Serial.println("Failed to connect to WiFi");
    }
}

void setup() {
    Serial.begin(9600); // Changed baud rate to 9600
    for (int i = 0; i < numLEDs; i++) {
        pinMode(ledPins[i], OUTPUT);
        Serial.print("Setting up LED "); // Adding more debug info
        Serial.println(ledPins[i]);
        digitalWrite(ledPins[i], LOW); // Initialize all LEDs to 'off'
    }
    connectToWiFi();
    timeClient.begin();
}

void loop() {
    Serial.println("Loop started");  // Debugging line
    if (WiFi.status() == WL_CONNECTED) {
        timeClient.update();
        int dayOfWeek = timeClient.getDay();
        Serial.print("Day of Week: ");  // Debugging line
        Serial.println(dayOfWeek);      // Debugging line

        // Mapping dayOfWeek to correct LED (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
        int ledIndex = (dayOfWeek + 6) % 7;
        Serial.print("LED Index: ");    // Debugging line
        Serial.println(ledIndex);       // Debugging line

        for (int i = 0; i < numLEDs; i++) {
            digitalWrite(ledPins[i], LOW); // Turn off all LEDs
            Serial.print("Turning off LED "); // Debugging line
            Serial.println(ledPins[i]);  // Debugging line
        }

        digitalWrite(ledPins[ledIndex], HIGH); // Turn on the correct LED for the day at 50% brightness
        Serial.print("Turning on LED "); // Debugging line
        Serial.println(ledPins[ledIndex]); // Debugging line
    } else {
        // Default behavior to turn all LEDs off if not connected to Wi-Fi
        Serial.println("Wi-Fi not connected, turning off all LEDs"); // Debugging line
        for (int i = 0; i < numLEDs; i++) {
            digitalWrite(ledPins[i], LOW); // Turn off all LEDs
        }
    }
    delay(1000); // Update every second
    Serial.println("Loop ended"); // Debugging line
}

Credits

Arnov Sharma
330 projects • 337 followers
Just your average MAKER
Contact

Comments

Please log in or sign up to comment.