Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Wemos D1 Mini Data Logger with DHT22, RTC, and SD Card

This project uses a Wemos D1 Mini (ESP8266-based) to log temperature and humidity data from a DHT22 sensor to an SD card. It includes a Real-Time Clock (RTC) module for accurate timestamps, synchronized via Wi-Fi and NTP.


Features

  • Temperature & Humidity Logging: Reads data from a DHT22 sensor.
  • Accurate Timestamps: Uses a DS3231 RTC module for precise timekeeping.
  • NTP Time Synchronization: Automatically updates the RTC time via Wi-Fi and Network Time Protocol (NTP) to ensure accuracy, especially after power loss.
  • SD Card Storage: Logs all sensor data with timestamps to a log.csv file on a Micro SD card. All timestamps are logged in Coordinated Universal Time (UTC).
  • Easy Setup: Clear pinout and configuration details.
  • Data Visualization Script: A Python script is provided to easily plot the collected data.

Components Needed

  • Wemos D1 Mini (or any ESP8266 development board)
  • DHT22 Temperature & Humidity Sensor
  • DS3231 RTC Module (I2C)
  • Micro SD Card Module (SPI)
  • Micro SD Card
  • Breadboard and Jumper Wires (for connections)
  • USB Cable (for Wemos D1 Mini power and programming)

Wiring Diagram

This table shows how to connect your components to the Wemos D1 Mini. Remember that the D-pins on the Wemos D1 Mini don't directly correspond to the ESP8266 GPIO numbers.

Komponente Pin der Komponente An ESP8266 Pin (GPIO-Nummer) Wemos D1 Mini Pin-Label
Alle Komponenten VCC 3V3 3V3
Alle Komponenten GND GND GND
DHT22 Sensor Data (Signal) GPIO16 D0
RTC-Modul (I2C) SDA GPIO4 D2
RTC-Modul (I2C) SCL GPIO5 D1
Micro SD-Modul SCK GPIO14 D5
Micro SD-Modul MOSI GPIO13 D7
Micro SD-Modul MISO GPIO12 D6
Micro SD-Modul CS GPIO15 D8

Important Note on abs() Ambiguity: The provided Arduino code handles a common ambiguity error with the abs() function when dealing with uint32_t values. This is resolved by explicitly casting to long before calling abs(), ensuring correct compilation on ESP8266.


Software Setup

  1. Arduino IDE: Download and install the Arduino IDE.
  2. ESP8266 Board Manager:
    • Go to File > Preferences.
    • In "Additional Boards Manager URLs," add: http://arduino.esp8266.com/stable/package_esp8266com_index.json
    • Go to Tools > Board > Boards Manager...
    • Search for "esp8266" and install the "ESP8266 by ESP8266 Community" package.
    • Select your board: Tools > Board > ESP8266 Boards > LOLIN(WEMOS) D1 R2 & mini (or your specific ESP8266 board).
  3. Install Arduino Libraries: Go to Sketch > Include Library > Manage Libraries... and install the following:
    • SimpleDHT by pallep
    • RTClib by Adafruit
    • NTPClient by Fabrice Weinberg
    • SD (usually pre-installed with the ESP8266 board package, under "ESP8266 Libraries")
    • Wire (comes with Arduino IDE)
    • SPI (comes with Arduino IDE)

Configuration

  1. Open the Sketch: Open the provided .ino file in the Arduino IDE.

  2. Update Wi-Fi Credentials: THIS IS CRITICAL! Find these lines in the code and replace "SSID" and "PASSWORD" with your actual Wi-Fi network name and password:

    const char* ssid = "SSID";       // <<--- CHANGE THIS
    const char* password = "PASSWORD";   // <<--- CHANGE THIS
  3. Time Offset: The code is configured to always use Coordinated Universal Time (UTC) for the RTC and logged timestamps. Therefore, the utcOffsetInSeconds is set to 0. No adjustment is needed here unless you explicitly want to log in a local timezone (which is not recommended for consistent data logging).

    const long utcOffsetInSeconds = 0; // Always use UTC

Uploading the Code

  1. Connect: Connect your Wemos D1 Mini to your computer using a USB cable.
  2. Select Port: Go to Tools > Port and select the correct COM port for your Wemos D1 Mini.
  3. Upload: Click the "Upload" button (right arrow icon) in the Arduino IDE.

Monitoring and Data

Once uploaded, open the Serial Monitor (Tools > Serial Monitor) in the Arduino IDE. Set the baud rate to 115200. You'll see:

  • Messages indicating Wi-Fi connection status.
  • RTC initialization and time synchronization (to UTC).
  • SD card initialization and creation of log.csv (if it doesn't exist).
  • Real-time sensor readings (temperature, humidity) and the timestamp being logged.

Your data will be stored in a file named log.csv on the Micro SD card. You can remove the SD card from the module and insert it into a computer to access the collected data. The log.csv file will have columns for timestamp_utc, temperature_c, and humidity_pct, with timestamp_utc specifically indicating that the time is in UTC.


Data Visualization (Python)

To plot the log.csv data, you can use the following Python script.

Requirements

Make sure you have Python installed, along with the necessary libraries:

pip install pandas matplotlib

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages