Temperature Monitoring Data Logger using Raspberry Pi Pico
4649 5
Taher Ujjainwala

Temperature Monitoring Data Logger using Raspberry Pi Pico

With temperature monitoring, you can easily monitor, track and generate graphs to understand the...

Description:-

With temperature monitoring, you can easily monitor, track and generate graphs to understand the daily temperature trends. Data monitoring and generating trends is one of the major applications in the field of Internet of Things. Internet of Things is the capability to connect any device over Internet. Each device can be programmed for one or more applications. Temperature Monitoring is one of the well known application widely used by many industries to monitor server room temperature, environment temperature trends and so on. I use internal storage of Pico to store the data with time stamp in new line format. This saves the cost of external SD card module and memory card. Pico gives freedom to select the file type and allows user to store the data in easy friendly format.

Raspberry Pi Pico Project

Project Used Hardware

Raspberry Pi Pico, DHT22, RTC - DS3231 module

Project Used Software

Thonny IDE - Python

Project Hardware Software Selection

Hardware selection:

Raspberry Pi Pico - Pico is tiny, fast and versatile board developed by Raspberry Pi. It is build using RP2040 a new microcontroller which supports Python environment Pico uses Arm cortex (processor) which is designed for small and affordable applications Pico is developed with wide range of programmable options I/O, UART, I2C, SPI, etc DHT22 - Temperature and Humidity sensor DHT22 is low cost digital temperature and humidity sensor. It measure temperature and humidity of surrounding air with refresh rate of 2 seconds DHT22 works on 3 to 5V and uses 2.5mA of maximum current Temperature Range: -40 to +80 degree Celcius with an accuracy of 0.5 degree Humidity Range: 0-100% with an accuracy of 2-5% RTC Module - DS3231 - I2C based Time and Clock module It is used to measure time and date. It is powered independently and worked on I2C protcol.

Software Selection:

Thonny IDE Easy to use and light weight software Support Python 3.7 and very easy to install Simply debugger, explains scopes, highlight syntax errors and texts

Circuit Diagram

Raspberry Pi Pico Tutorial

 

I am using DHT22 and RTC - DS3231 module interfaced with Raspberry Pi Pico DHT22 connections with Pico - Power pins are connected with vcc and ground respectively, Data of DHT22 is connected with Pin 15 on Pico RTC - DS3231 connections with Pico - Power pins are connected with vcc and ground respectively, SDA and SCL pins are connected on SCL and SDA on Pico.

Code

# More than 30,000 datapoints can be stored.
# Practical example: Saving data at every minute will give
# Approx Backup time = 30000/1/60/24 = approx 20 days of backup
from machine import Pin, I2C
from DHT22 import DHT22
from urtc import DS3231
import time

# Initializing I2C
i2crtc = I2C(0, scl=Pin(21), sda=Pin(20), freq=100000)
exRTC = DS3231(i2crtc)

# Getting Date and Time from RTC
pDT = exRTC.datetime()
print("Present Date & Time :", pDT)

# Iitializing DHT22 Pin
dht22 = DHT22(Pin(15, Pin.IN, Pin.PULL_UP))

while True:
    # Reading Temperature and Humidty from DHT22
    T, H = dht22.read()

    # Getting Date and Time from RTC
    pDT = exRTC.datetime()
    print(pDT[0], pDT[1], pDT[2], pDT[3], pDT[4], pDT[5], pDT[6], T, H)

    # Backing up data into internal storage in the below syntax
    # year, month, day, weekday, hour, minute, second, temperature, humidity
    with open('Databackup.txt', 'a+') as file:
        file.write(str(pDT[0]) + ", " + str(pDT[1]) + ", " + str(pDT[2]) + ", " + str(pDT[3]) + ", " +
                   str(pDT[4]) + ", " + str(pDT[5]) + ", " + str(pDT[6]) + ", " + str(T) + ", " + str(H))
        file.write('\n')
        file.close()

    # Since DHT22 updates temperature and humidity every 2 seconds
    time.sleep(2)