Arduino-Based Temperature Data Logger
Arduino-Based Temperature Data Logger file X9WJRw8Me73eyMR7BQNgwo

Arduino-Based Temperature Data Logger

Introduction

This project involves building a temperature data logger using an Arduino microcontroller, a temperature sensor (DHT11/DHT22), and an SD card module. The system will periodically record temperature readings and store them on an SD card for later analysis.

Real-world applications:

  • Monitoring environmental conditions
  • Tracking temperature changes in storage facilities
  • Data logging for scientific experiments

Learning Objectives

By completing this project, you will:

  • Learn how to interface a temperature sensor with Arduino
  • Understand how to store data on an SD card
  • Gain experience in working with time-based data logging
  • Learn basic data retrieval and analysis techniques

Tools and Components

  • Arduino Uno (or compatible board)
  • DHT11 or DHT22 temperature and humidity sensor
  • SD card module
  • MicroSD card (FAT32 formatted)
  • Jumper wires
  • Breadboard
  • 10kΩ pull-up resistor (for DHT sensor)
  • Power source (USB cable or battery pack)

Background and Definitions

Arduino Microcontroller

An Arduino is an open-source microcontroller platform used for building electronics projects. It has a programmable interface that allows it to interact with sensors and other hardware components.

DHT11/DHT22 Sensor

These sensors measure temperature and humidity. The DHT22 is more accurate and has a wider range than the DHT11.

  • DHT11: Accuracy of ±2°C, range 0–50°C
  • DHT22: Accuracy of ±0.5°C, range -40–80°C

SD Card Module

This module allows the Arduino to store data on a microSD card. It communicates with the Arduino using the SPI (Serial Peripheral Interface) protocol.

Step-by-Step Guide

1. Wiring the Components

Connect the components as follows:

  • DHT11/DHT22 Sensor:
    • VCC → 5V
    • GND → GND
    • Data → Digital Pin 2 (with 10kΩ pull-up resistor to VCC)
  • SD Card Module:
    • VCC → 5V
    • GND → GND
    • MISO → Digital Pin 12
    • MOSI → Digital Pin 11
    • SCK → Digital Pin 13
    • CS → Digital Pin 4

2. Install Required Libraries

Ensure you have the following libraries installed in the Arduino IDE:

  • DHT sensor library: Adafruit DHT Sensor Library
  • SD card library: Built-in SD Library

3. Write and Upload the Code

Upload the following code to your Arduino board:

#include <SPI.h>
#include <SD.h>
#include <DHT.h>

#define DHTPIN 2
#define DHTTYPE DHT11  // Change to DHT22 if using that model
#define CSPIN 4

DHT dht(DHTPIN, DHTTYPE);
File dataFile;

void setup() {
  Serial.begin(9600);
  dht.begin();
  if (!SD.begin(CSPIN)) {
    Serial.println("SD card initialization failed!");
    return;
  }
  Serial.println("SD card initialized.");
}

void loop() {
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();
  
  if (isnan(temperature) || isnan(humidity)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  
  dataFile = SD.open("datalog.txt", FILE_WRITE);
  if (dataFile) {
    dataFile.print("Temperature: ");
    dataFile.print(temperature);
    dataFile.println(" C");
    dataFile.close();
    Serial.println("Data written to SD card.");
  } else {
    Serial.println("Error opening datalog.txt");
  }
  delay(5000);  // Log data every 5 seconds
}

Testing and Debugging Tips

  • SD Card Issues: Ensure the SD card is formatted to FAT32 and properly inserted.
  • DHT Sensor Not Responding: Check the wiring and ensure a pull-up resistor is connected.
  • Data Not Logging: Verify that the SD card is correctly initialized and has enough storage space.

Extensions and Improvements

  • Add a real-time clock (RTC) module to timestamp data entries.
  • Display the temperature on an LCD screen.
  • Upload data to an IoT cloud platform for remote monitoring.
  • Use a battery power source for portability.

Conclusion

This project teaches key concepts in data logging and sensor interfacing with Arduino. By storing temperature readings on an SD card, you can analyze trends and use the data for various applications such as weather monitoring and industrial temperature tracking.