SUPER CLOCK
This is a superclock it tells the time with HOURS.MINUTES.SECONDS and also contains three extra features tempeture,humidity,light inside the room. It also uses 3 led's to display if the humdity is normal high or low with red being high green being normal and blue being low.
Downloads
Supplies
Materials used : Breadboard, Male to male wires ,oled 0.96 display screen,Arduino UNO,3x 220ohm resistors,3 rgb led's,DHT-11 temperture humidity sensor , Photosensitive sensor.
Software : arduino IDE
WIRING
Its important to get the wires corectly
Wiring Instructions:
1. Power
Connect Arduino 5V to the Breadboard Red Rail (+).
Connect Arduino GND to the Breadboard Blue Rail (-).
2. OLED Display (The Screen)
VCC Red Rail (+)
GND Blue Rail (-)
SCL Arduino Pin A5 (Clock)
SDA Arduino Pin A4 (Data)
3. DHT11 Sensor (Temp/Humidity)
Signal (S) Arduino Digital Pin 2
VCC (+) Red Rail (+)
GND (-) Blue Rail (-)
4. Photoresistor Module (Light)
VCC Red Rail (+)
GND Blue Rail (-)
A0 (Signal) Arduino Analog Pin A0
5. RGB LED (Status Light)
Common Leg (Longest) Blue Rail (-)
Red Leg 220Ω Resistor Arduino Pin 9
Green Leg 220Ω Resistor Arduino Pin 10
Blue Leg 220Ω Resistor Arduino Pin 11
PROGRAMING
In the Arduino IDE, go to Tools > Manage Libraries and install these:
Adafruit SSD1306 (for the display)
Adafruit GFX (graphics core)
DHT sensor library (by Adafruit)
here's the code ready for you to import:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <DHT.h>
// --- Pin Definitions ---
#define DHTPIN 2
#define DHTTYPE DHT11
#define LDR_PIN A0
#define LED_R_PIN 9
#define LED_G_PIN 10
#define LED_B_PIN 11
// OLED Screen Setup
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Initialize DHT sensor
DHT dht(DHTPIN, DHTTYPE);
// --- GLOBAL VARIABLES ---
float temperature = 0;
float humidity = 0;
int light_raw = 0;
// --- CLOCK VARIABLES (Start Time) ---
int hours = 12; // Set your start Hour here
int minutes = 00; // Set your start Minute here
int seconds = 00;
// --- TIMER VARIABLES (For Multitasking) ---
unsigned long previousMillisClock = 0; // Tracks the last time clock updated
unsigned long previousMillisSensors = 0;// Tracks the last time sensors read
const long intervalClock = 1000; // 1 second (1000ms)
const long intervalSensors = 3000; // 3 seconds (3000ms)
void setup() {
Serial.begin(9600);
pinMode(LED_R_PIN, OUTPUT);
pinMode(LED_G_PIN, OUTPUT);
pinMode(LED_B_PIN, OUTPUT);
dht.begin();
// NOTE: If display fails, try 0x3D
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed."));
for(;;);
}
display.clearDisplay();
display.display();
}
// Function to set RGB Color
void set_rgb_color(int r, int g, int b) {
analogWrite(LED_R_PIN, r);
analogWrite(LED_G_PIN, g);
analogWrite(LED_B_PIN, b);
}
// Status Logic
void check_status_and_alert(float temp, float humid) {
if (temp > 30.0) { set_rgb_color(255, 0, 0); return; } // Red
if (temp < 18.0) { set_rgb_color(0, 0, 255); return; } // Blue
if (humid > 70.0) { set_rgb_color(255, 255, 0); return; } // Yellow
set_rgb_color(0, 255, 0); // Green
}
// Helper function to print leading zeros (e.g. 09 instead of 9)
void printDigits(int digits) {
if(digits < 10) display.print("0");
display.print(digits);
}
void update_oled_display() {
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
// --- TOP SECTION: CLOCK ---
display.setTextSize(2);
display.setCursor(18, 0); // Center the time roughly
printDigits(hours);
display.print(":");
printDigits(minutes);
display.print(":");
printDigits(seconds);
// Draw a line under the time
display.drawLine(0, 18, 128, 18, SSD1306_WHITE);
// --- BOTTOM SECTION: SENSORS ---
display.setTextSize(1);
// Temperature
display.setCursor(0, 25);
display.print("Temp: "); display.print(temperature, 1); display.print(" C");
// Humidity
display.setCursor(0, 40);
display.print("Humid: "); display.print(humidity, 0); display.print(" %");
// Light
display.setCursor(0, 55);
int light_percent = map(light_raw, 0, 1023, 0, 100);
display.print("Light: "); display.print(light_percent); display.print(" %");
display.display();
}
void loop() {
unsigned long currentMillis = millis(); // Get the current uptime of the Arduino
// 1. --- CLOCK LOGIC (Runs every 1 second) ---
if (currentMillis - previousMillisClock >= intervalClock) {
previousMillisClock = currentMillis; // Reset timer
seconds++;
if (seconds > 59) {
seconds = 0;
minutes++;
if (minutes > 59) {
minutes = 0;
hours++;
if (hours > 23) {
hours = 0;
}
}
}
// Update screen every second to show seconds ticking
update_oled_display();
}
// 2. --- SENSOR LOGIC (Runs every 3 seconds) ---
if (currentMillis - previousMillisSensors >= intervalSensors) {
previousMillisSensors = currentMillis; // Reset timer
// Read Sensors
float h = dht.readHumidity();
float t = dht.readTemperature();
int l = analogRead(LDR_PIN);
// Error Check
if (!isnan(h) && !isnan(t)) {
temperature = t;
humidity = h;
light_raw = l;
// Check Alerts
check_status_and_alert(t, h);
// Debug to Serial Monitor
Serial.print("Update: ");
Serial.print(hours); Serial.print(":"); Serial.print(minutes);
Serial.print(" | T: "); Serial.println(t);
}
}
// NO delay() here! The loop runs as fast as possible to check the timers.
}
Running
ONCE you ve completed both steps go to the serial monitor and see if its displaying anything once you start running if it sasy DHT error you have to check your wiring to see if anything is wrong if not then it should provide you with the clock and the other features!