Sam El Saati (se223xm)
This project that I have named IndaHouse involves building a temperature and humidity monitoring system using a Raspberry Pi Pico WH, a DHT11 sensor, and a MongoDB backend. The data collected by the sensor is logged into a MongoDB database and visualized using MongoDB Atlas Charts. The entire system is developed using MicroPython for the Pico WH, Node.js for the backend, and Thonny as the IDE. This project is ideal for smart home applications where monitoring indoor environmental conditions is crucial.
Estimated Time to Complete: Approximately 4-6 hours
The primary goal of this project is to create a cost-effective and reliable system for monitoring indoor temperature and humidity levels. This data can be used to gain insights into home comfort levels, detect unusual environmental changes, and potentially trigger alerts or automated actions based on the sensor readings.
- Why This Project: I chose this project because it provides valuable insights into environmental conditions within the home, which can be crucial for maintaining a comfortable and healthy living environment.
- Purpose: The device serves to monitor indoor climate conditions, which can help in making informed decisions about heating, cooling, and humidity control.
- Insights: By analyzing the data over time, trends in temperature and humidity can be identified, allowing for optimization of heating, ventilation, and air conditioning (HVAC) systems.
- Raspberry Pi Pico WH: Microcontroller with built-in Wi-Fi, used as the main processing unit.
- DHT11 Temperature and Humidity Sensor: Sensor used to measure temperature and humidity.
- RGB LED Module: Provides visual feedback when readings are taken.
- Piezo Speaker: Emits a sound to indicate data logging.
- Jumper Wires: Used for connections between the Pico and other components.
- Breadboard: For prototyping the circuit.
- Cable Stripper: For stripping cables in a clean professional way (optional).
- Raspberry Pi Pico WH: SEK 109 - Bought from Electrokit
- DHT11 Sensor: SEK 49 - Available on Electrokit
- RGB LED Module: SEK 22 - Available on Electrokit
- Piezo Speaker: SEK 39 - Available on Electrokit
- Jumper Wires: SEK 55 - Pack from Electrokit
- Breadboard: SEK 69 - Available on Electrokit
- Cable stripper: SEK 169 - Available on Electrokit (Optional)
- Thonny: This is the chosen IDE for developing and uploading MicroPython code to the Raspberry Pi Pico WH. It is simple, user-friendly, and supports direct interaction with MicroPython environments.
- Install Thonny: Download and install Thonny from thonny.org.
- Install MicroPython on Pico:
- Connect the Pico WH to your computer while holding down the BOOTSEL button.
- Download the MicroPython UF2 file from micropython.org.
- Drag and drop the UF2 file onto the
RPI-RP2
drive that appears when you connect the Pico.
- Upload Code:
- Write your MicroPython code in Thonny.
- Save the script as
main.py
on the Pico to run automatically on startup.
- Node.js Installation: Install Node.js from nodejs.org to run the backend server.
- MongoDB Setup: Set up a MongoDB Atlas account for cloud database storage and visualization.
(circuit diagram)
- DHT11 Sensor:
- Data Pin -> GPIO 15
- VCC -> 3.3V
- GND -> Ground
- RGB LED Module:
- Red Pin -> GPIO 16
- Green Pin -> GPIO 17
- Blue Pin -> GPIO 18
- GND -> Ground
- Piezo Speaker:
- Positive Pin -> GPIO 9
- Negative Pin -> Ground
-
Raspberry Pi Pico WH:
- Operating Voltage: 3.3V (logic level)
- GPIO Max Current per Pin: 12mA
- Total Max Current for All GPIOs: 50mA
-
DHT11 Sensor:
- Operating Voltage: 3.3V - 5V
- Current Consumption: 0.3mA (during measurement)
-
RGB LED Module:
- Operating Voltage: 3.3V
- Current per Color (Red, Green, Blue): Typically 20mA per channel at full brightness
-
Piezo Speaker:
- Operating Voltage: 3.3V - 5V
- Current Consumption: Typically 20mA
- Current Consumption: 0.3mA
- PWM Settings: The red and blue LEDs are both set to 50% brightness (50% duty cycle).
- Current per LED at 50% Duty Cycle:
- Red LED: 20mA * 0.5 = 10mA
- Blue LED: 20mA * 0.5 = 10mA
- Total Current for RGB LED (Purple): 10mA (Red) + 10mA (Blue) = 20mA
- Current Consumption: 20mA
Adding up the current draw from all components:
- DHT11 Sensor: 0.3mA
- RGB LED Module (Purple at 50% brightness): 20mA
- Piezo Speaker: 20mA
Total Current Consumption:
- Total: 0.3mA + 20mA + 20mA = 40.3mA
The total current draw from all GPIOs is 40.3mA, which is under the 50mA recommended limit for the Raspberry Pi Pico WH. This means the Pico WH should be able to handle the load without issues.
All components are operating at 3.3V, which is the standard output from the Raspberry Pi Pico WH, so there are no voltage level issues.
IndaHouse is now optimized for power consumption, and should operate reliably within the specifications of the Raspberry Pi Pico WH.
- Functionality: MongoDB Atlas provides a robust, cloud-based NoSQL database solution with built-in visualization tools.
- Scalability: MongoDB Atlas scales seamlessly from development to production environments, with options for free and paid subscriptions.
- Reason for Choosing: MongoDB Atlas was chosen for its ease of use, scalability, and integrated data visualization capabilities.
def connect_wifi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
while not wlan.isconnected():
time.sleep(1)
print('Connected to Wi-Fi:', wlan.ifconfig())
This function handles the Wi-Fi connection process, ensuring the Raspberry Pi Pico WH is connected to your home network before starting with data logging.
def main():
connect_wifi()
while True:
try:
dht_sensor.measure()
temperature = dht_sensor.temperature()
humidity = dht_sensor.humidity()
send_data(temperature, humidity)
print(f"Data sent: Temp={temperature}, Humidity={humidity}")
except OSError as e:
print('Failed to read sensor or send data:', e)
time.sleep(60)
This loop continuously reads the temperature and humidity every 60 seconds, sending the data to the Node.js backend. Smooth error handling is added to avoid crash of the script
- Frequency: Data is transmitted every 60 seconds.
- Protocol: The Raspberry Pi Pico WH uses HTTP over Wi-Fi to send data to the Node.js backend.
- Data Format: The data is sent as a JSON payload containing temperature, humidity, and a timestamp.
- Wi-Fi was chosen for its ubiquity and ease of integration with home networks.
- HTTP POST requests were used for simplicity and compatibility with the Node.js backend.
- Platform: MongoDB Atlas Charts
- Dashboard: The MongoDB Atlas Charts dashboard visualizes the temperature and humidity data over time, offering insights into trends and anomalies.
(screenshot of the MongoDB Atlas Charts dashboard)
- Frequency of Data Storage: Data is stored in MongoDB every 60 seconds.
- Database Choice: MongoDB was chosen for its flexibility and scalability, which suits both development and production environments.
- The temperature and humidity monitoring system was successfully implemented, with real-time data visualization in MongoDB Atlas Charts.
- The system proved to be reliable and could be expanded with additional sensors or integrated into larger smart home systems.
- What Went Well: The project was straightforward and provided valuable insights into environmental monitoring.
- Improvements: Future iterations could include more advanced sensors, automated alerts, or integration with other smart home systems.
(picture of the final setup showing the Raspberry Pi Pico WH, sensor, and the other components on the breadboard.)
{%youtube 1RgMqwnBYuA %} (promotional video about the project, produced fully by me.)
{%youtube TODFrJAMpig %} (video showing the project in action, reading, sending, receiving, etc....)