Temperature & Humidity Detector With IOT and Flask

I Nyoman Arista Wisnawa

Sosial Media


1 orang menyukai ini
Suka

Summary

Temperature & Humidity Detector use Wokwi Simulator to make the hardware simulation and using Python Flask for the Backend. This system also connected to mysql Database to manage data. This temperature & humidity detector system have 3 endpoint in the backend. The endpoints are:

  1. GET /api: Fetching all datas in the database.
  2. POST /api: Send temperature and humidity that captured by the sensor to the database.
  3. PUT /api: Update data in the database.

Description

BACKGROUND

This project provide a hands-on learning experience for individuals interested in IoT development. The goal of this project is to develop a basic IoT system that capable of monitoring temperature and humidity levels, providing valuable data for home automation systems. Temperature and humidity detector are reliable for monitoring environmental conditions, specifically room temperature and humidity.

USED TECHNOLOGY

This section provides a list of technologies and platform that used in this project.

  • Wokwi Simulator: Wokwi is a free online simulator that allows users to design and simulate electronic circuits, including microcontrollers like Arduino and ESP32. It provides a user-friendly interface to connect components, write code, and visualize the circuit's behavior in real-time, making it a great tool for learning electronics and IoT development. In this project, wokwi is used to make the hardware simulation and the code for the hardware.
  • ESP microcontroller: This project is using ESP microcontroller. ESP32 is a popular series of low-cost, low-power microcontrollers with built-in Wi-Fi and Bluetooth capabilities. They are widely used in IoT projects, home automation, and other electronic devices due to their versatility and ease of use.
  • Python Flask: Flask is a python framework that allows developers to quickly build applications. Flask provides a flexible foundation for handling requests, routing URLs, and rendering templates. Flask's simplicity and modular design make it a popular choice for both beginners and experienced developers.
  • MySQL: MySQL is a popular open-source relational database management system used to store and manage data efficiently. MySQL allows users to create, retrieve, update, and delete data within databases, making it a crucial component for many web applications and other software systems.

IMPLEMENTATION

First, we need to make the table in database mysql. The table contains id as a primary key, temperature, humidity, and timestamp. The details can be seen in picture 1.

Picture 1. Creating the database in mysql

Then, create a simulation with wokwi's components that are needed and code on wokwi. As explained earlier, we will use the ESP32 microcontroller, DHT22 sensor and 16x2 LCD. The cable connections are as follows:

  1. DHT22:
  • Connect the VCC pin of the DHT22 to the 3.3V power supply of the ESP32.
  • Connect the GND pin of the DHT22 to the GND of the ESP 32.
  • Connect the SDA pin of the DHT22 to digital pin 15 of the ESP32.

    2. LCD16x2:

  • The SDA and SCL pins of the LCD are connected to the ESP32's digital pins 21 and 22 respectively for I2C communication.
  • The VCC and GND pins of the LCD are connected to the 3.3V power supply and ground of the ESP32.

Picture 2. Wokwi components and their connections

After we finish connecting the Wokwi components, create the backend code and code for the wokwi hardware. For the wokwi hardware code, this project uses several libraries such as WiFi, LiquidCrystal_I2C, HTTPClient, and ArduinoJson.

Picture 3. Libraries

Picture 4. Set up function on wokwi code

Picture 5. Backend Code

ATTACHMENTS

Picture 6. Run the Simulation, Connect to the WiFi

Picture 7. Run the backend

Picture 8. GET response

Picture 9. POST response

Picture 10. PUT response

Picture 11. Backend response to the wokwi request

Informasi Course Terkait
  Kategori: Cloud Computing
  Course: Cloud Computing