# **Introduction**
**Title:** IoT-based Weather Monitoring System
**Student:** Abdulrahman AlAllaf, Student ID: aa224ji
**Project Overview:**
This project aims to create a basic Internet of Things (IoT) device that can monitor and display temperature and humidity in real-time using the Raspberry Pi Pico, DHT11 sensor, and I2C LCD Display. The Raspberry Pi Pico works as the central processing unit of the system that reads data from the sensor and processes it to be displayed on the LCD screen.
**Estimated Time:** Approximately 6-8 days, including both hardware assembly and software configuration.
**Objective:** The objective is to understand how to implement an IoT project using available microcontrollers, sensors, and display modules, thereby broadening knowledge about IoT applications.
# **Project Rationale**
**Purpose:** The project was chosen due to its real-world relevance. The device serves to monitor and display temperature and humidity. It's a handy tool for home, offices, or any indoor environment where understanding the weather conditions is important.
**Insights:** Building this device will provide insights into the practical applications of IoT, how different hardware components interact, and how data can be collected, processed, and displayed using relatively simple technologies.
# **Hardware Components Details**
**Raspberry Pi Pico:** It is a tiny, fast, and versatile board built using the RP2040, a dual-core ARM Cortex M0+ processor with flexible clock running up to 133MHz. It's a highly cost-effective board with a large range of programmability.

The documentation for the Raspberry Pi Pico can be found here https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html#rp2040-device
**DHT11 Temperature and Humidity Sensor:** The DHT11 is a basic and low cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and outputs a digital signal on the data pin.

**I2C LCD Display:** The display used here can display 16 characters per line in 2 lines and is used to communicate with the Raspberry Pi Pico for displaying data.

**Jumper Wire Cables male to female**

**USB to Micro USB cable**

**Breadboard 840 points**

All hardware components used in this project were bought from a local electronics store for 25$.
# Computer Setup
This device is programmed using MicroPython, an implementation of Python 3 designed to run on microcontrollers. I used the PyMakr plugin for Visual Studio Code (VSCode) as my integrated development environment (IDE) for this project.
Here's a step-by-step guide for setting up your computer:
1. Download and install VSCode:
2. Install the PyMakr plugin: After installing VSCode, open it and click on the Extensions button on the Activity Bar. Search for "PyMakr" and install it.
3. Install Node.js: PyMakr requires Node.js to work.
4. Firmware Flashing: Connect your Raspberry Pi Pico to your computer. In Pymakr, set up a new device and select 'Raspberry Pi Pico' for the board.
5. Code Development: Write the code in Pymakr and run it on the Raspberry Pi Pico.
# **Putting Everything Together**
The project involves connecting the DHT11 sensor and the I2C LCD Display to the Raspberry Pi Pico.
**Installation Process:**
1. Connect the power pin (VCC) of the DHT11 sensor to the 3.3V pin on the Raspberry Pi Pico.
2. Connect the ground pin (GND) of the DHT11 sensor to the ground pin of the Raspberry Pi Pico.
3. Connect the data pin of the DHT11 sensor to GPIO 15 pin on Raspberry Pi Pico.
4. Connect the I2C pins (SDA, SCL) of the LCD display to the corresponding I2C pins on the Raspberry Pi Pico.
5. Connect the power and ground pins of the LCD display to the 3.3V and ground pins on the Raspberry Pi Pico.
**Circuit Diagram:**

**Electrical Calculations:** All the components used in this project are designed to work with the 3.3V power supply from the Raspberry Pi Pico, eliminating the need for additional resistors. Current draw for each component is within the Raspberry Pi Pico's supply capabilities.
# **Platform**
The platform for this project is based on a local setup with the Raspberry Pi Pico microcontroller board. The reason for choosing Raspberry Pi Pico is its easy availability and support for MicroPython programming.
# **The Code**
In this project, the core functionalities involve reading data from the DHT11 sensor, processing it, and displaying it on the LCD. First, we initialize the DHT11 sensor and the LCD Display on their respective pins. Then, The DHT11 sensor is read, and the temperature and humidity values are stored. The data processing is straightforward as the DHT11 sensor directly gives us temperature and humidity values. The temperature and humidity values are displayed on the LCD. While this project doesn't include network communication, in a situation where data needs to be transmitted over Wi-Fi, additional steps would be required to set up the Wi-Fi connectivity, configure the data transmission protocol (like MQTT), and send the data.
Here are some of the core functions of the code:
Setting Up I2C and LCD Display:
```
# Setting up I2C and LCD display
i2c_bus = I2C(id=1, scl=Pin(27), sda=Pin(26), freq=100000)
lcd_disp = I2cLcd(i2c_bus, 0x27, 2, 16)
```
Initialization of the DHT11 Sensor:
```
# Initializing DHT11 sensor
data_pin = Pin(15, Pin.OUT, Pin.PULL_DOWN)
temp_sensor = DHT11(data_pin)
```
Data Collection:
```
while True:
u_time.sleep(1)
# Reading temperature and humidity
temp = temp_sensor.temperature
humidity = temp_sensor.humidity
print("Temperature: {}".format(temp))
print("Humidity: {}".format(humidity))
u_time.sleep(1)
```
Displaying Data on the LCD:
```
lcd_disp.clear()
lcd_disp.move_to(0,0)
lcd_disp.putstr('Temp :')
lcd_disp.move_to(7,0)
lcd_disp.putstr(str(temp)+" C")
lcd_disp.move_to(0,1)
lcd_disp.putstr('Humi :')
lcd_disp.move_to(7,1)
lcd_disp.putstr(str(humidity)+" %")
```
LCD Setup:
```
class LcdApi:
def __init__(self, num_lines, num_columns):
"""Initializes the LCD with the given number of lines and columns"""
self.num_lines = min(num_lines, 4)
self.num_columns = min(num_columns, 40)
self.cursor_x = 0
self.cursor_y = 0
self.implied_newline = False
self.backlight = True
self._setup_lcd()
def _setup_lcd(self):
"""Setup function for lcd display initialization"""
self.display_off()
self.backlight_on()
self.clear()
self.hal_write_command(self.LCD_ENTRY_MODE | self.LCD_ENTRY_INC)
self.hide_cursor()
self.display_on()
```
Get the Current Humidity and Temperature reading from the Sensor:
```
def humidity(self):
"""Get the current humidity reading from the sensor."""
self.measure()
return self._humidity
def temperature(self):
"""Get the current temperature reading from the sensor."""
self.measure()
return self._temperature
```
# **Transmitting the Data / Connectivity**
In this project, data isn't transmitted to the internet or a local server, it's directly displayed on the I2C LCD Display.
# **Presenting the Data**
The data from the DHT11 sensor is presented directly on the I2C LCD Display connected to the Raspberry Pi Pico. The data is refreshed in real-time, providing a live feed of the temperature and humidity conditions.

# **Finalizing the Design**
**Final Results:** The final result of the project is a fully functioning weather monitoring system that can read and display temperature and humidity in real-time.
**Reflections:** The project provides a good introduction to IoT device building, showcasing how to connect sensors to a microcontroller and process and display sensor data. If there were to be improvements, integrating a Wi-Fi module to enable IoT capabilities and data logging to a remote server or cloud platform could be considered.
**Video Presentation:**
https://youtube.com/shorts/N8MtJ8rNHec?feature=share