Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-Based Weather Station with OLED Display and RTC

View and Edit Project In Cirkit DesignerImage of ESP32-Based Weather Station with OLED Display and RTC

Circuit Documentation

Summary

This circuit is designed to read temperature and humidity data from a DHT11 sensor, read analog data from a rain sensor, and display the data on an OLED screen. It also uses an RTC DS3231 to timestamp the readings. The main microcontroller used in this circuit is an ESP32 (30 pin).

Component List

  1. ESP32 (30 pin)

    • Description: A powerful microcontroller with built-in Wi-Fi and Bluetooth capabilities.
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
  2. DHT11 Sensor V2

    • Description: A basic, low-cost digital temperature and humidity sensor.
    • Pins: GND, DAT, VCC
  3. OLED 1.3"

    • Description: A small OLED display used to show text and graphics.
    • Pins: GND, VCC, SCL, SDA
  4. RTC DS3231

    • Description: A real-time clock module with a temperature-compensated crystal oscillator.
    • Pins: 32K, SQW, SCL, SDA, VCC, GND
  5. RAIN SENSOR

    • Description: A sensor used to detect the presence of rain.
    • Pins: AO, DO, GRD, VCC
  6. Raspberry Pi 5

    • Description: A powerful single-board computer.
    • Pins: Type-C, Micro HDMI 1, Micro HDMI 2, Camera 1, Camera 2, PoE, Fan, PCIe, USB 3.0, USB 2.0, Ethernet, 5V, GND, 3.3v, GPIO 14, GPIO 15, GPIO 18, GPIO 23, GPIO 24, GPIO 25, GPIO 8, GPIO 7, GPIO 1, GPIO 12, GPIO 16, GPIO 20, GPIO 21, GPIO 2, GPIO 3, GPIO 4, GPIO 17, GPIO 27, GPIO 22, GPIO 10, GPIO 9, GPIO 11, GPIO 0, GPIO 5, GPIO 6, GPIO 13, GPIO 19, GPIO 26

Wiring Details

ESP32 (30 pin)

DHT11 Sensor V2

OLED 1.3"

RTC DS3231

RAIN SENSOR

Code Documentation

/*
 * This Arduino sketch reads temperature and humidity data from a DHT11 sensor,
 * reads analog data from a rain sensor, and displays the data on an OLED screen.
 * It also uses an RTC DS3231 to timestamp the readings.
 */

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <RTClib.h>

#define DHTPIN 15
#define DHTTYPE DHT11
#define RAIN_SENSOR_PIN 34
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1

DHT dht(DHTPIN, DHTTYPE);
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
RTC_DS3231 rtc;

void setup() {
  Serial.begin(115200);
  dht.begin();
  if (!display.begin(SSD1306_I2C_ADDRESS, OLED_RESET)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }
  display.display();
  delay(2000);
  display.clearDisplay();
  if (!rtc.begin()) {
    Serial.println(F("Couldn't find RTC"));
    while (1);
  }
  if (rtc.lostPower()) {
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  int rainValue = analogRead(RAIN_SENSOR_PIN);
  DateTime now = rtc.now();
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.print(F("Time: "));
  display.print(now.hour(), DEC);
  display.print(F(":"));
  display.print(now.minute(), DEC);
  display.print(F(":"));
  display.print(now.second(), DEC);
  display.print(F("\nTemp: "));
  display.print(t);
  display.print(F(" C\nHumidity: "));
  display.print(h);
  display.print(F(" %\nRain: "));
  display.print(rainValue);
  display.display();
  delay(2000);
}

This code initializes the DHT11 sensor, OLED display, and RTC DS3231. In the loop function, it reads the temperature, humidity, and rain sensor values, gets the current time from the RTC, and displays all this information on the OLED screen. The display is updated every 2 seconds.