This circuit is designed to display the current date, time, and temperature on an 8x8 WS2812 RGB LED matrix. The ESP32 Devkit V1 microcontroller is used as the central processing unit, which connects to a Wi-Fi network to retrieve the current time from an NTP server and reads temperature data from a DHT22 sensor. The ESP32 controls the LED matrix to display the information and communicates with the DHT22 sensor to get temperature readings.
/*
* Date, Time, and Temperature Display Project
* This code displays the current date, time, and temperature on an 8x8 WS2812
* RGB LED matrix. The date and time are updated every second using an NTP
* client. The temperature is read from a DHT22 sensor connected to GPIO 4.
*/
#include <WiFi.h>
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <DHT.h>
#include <Adafruit_NeoPixel.h>
// WiFi credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
// NTP Client settings
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", 0, 60000);
// DHT22 settings
#define DHTPIN 4 // GPIO4 on ESP32 connected to DHT22 Out
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
// WS2812 settings
#define LED_PIN 5 // GPIO5 on ESP32 connected to WS2812 DIN
#define NUM_LEDS 64
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
delay(100);
// Connect to WiFi
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
// Initialize NTP Client
timeClient.begin();
// Initialize DHT22 sensor
dht.begin();
// Initialize WS2812 LED matrix
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Update the NTP client
timeClient.update();
// Get the current date and time
unsigned long epochTime = timeClient.getEpochTime();
struct tm *ptm = gmtime ((time_t *)&epochTime);
int monthDay = ptm->tm_mday;
int currentMonth = ptm->tm_mon+1;
int currentYear = ptm->tm_year+1900;
int currentHour = ptm->tm_hour;
int currentMinute = ptm->tm_min;
int currentSecond = ptm->tm_sec;
// Read temperature from DHT22 sensor
float temperature = dht.readTemperature();
// Display the date, time, and temperature on the Serial Monitor
Serial.print("Date: ");
Serial.print(currentYear);
Serial.print("-");
Serial.print(currentMonth);
Serial.print("-");
Serial.print(monthDay);
Serial.print(" Time: ");
Serial.print(currentHour);
Serial.print(":");
Serial.print(currentMinute);
Serial.print(":");
Serial.print(currentSecond);
Serial.print(" Temperature: ");
Serial.print(temperature);
Serial.println(" *C");
// Display the date, time, and temperature on the LED matrix
displayDateTimeTemperature(currentYear, currentMonth, monthDay, currentHour,
currentMinute, currentSecond, temperature);
// Wait for a second before updating again
delay(1000);
}
void displayDateTimeTemperature(int year, int month, int day, int hour, int minute,
int second, float temperature) {
// Clear the LED matrix
strip.clear();
// Display the date, time, and temperature on the LED matrix
// This is a placeholder function. You will need to implement the actual
// code to display the date, time, and temperature on the LED matrix.
// You can use the Adafruit_NeoPixel library functions to set the color
// of individual LEDs in the matrix.
// Example: Set the first LED to red
strip.setPixelColor(0, strip.Color(255, 0, 0));
// Show the updated LED matrix
strip.show();
}
Note: The displayDateTimeTemperature
function is a placeholder and needs to be implemented to display the actual date, time, and temperature on the LED matrix using the Adafruit_NeoPixel library functions.