Send data measured by DHT11 sensor connected to ESP32 via Wifi

ESP32 08-02-24
442 0

Tutorial plan

1- The ESP32 board and WIFI

2- What is the web server for the ESP32 card ?

3- Role of boot.py and main.py files in ESP32 board

4- Mounting the ESP32 board with the DHT11 sensor

5- Program the ESP32 board with Micropython

The ESP32 board and WIFI

The ESP32 is a versatile microcontroller board that is well-known for its built-in Wi-Fi capabilities. Here's an overview of the ESP32 board and its Wi-Fi features:

1- ESP32 Microcontroller:

- The ESP32 is a microcontroller board based on the ESP32 chip, which is developed by Espressif Systems.

- It features a dual-core Xtensa LX6 CPU, which allows for multitasking and processing tasks efficiently.

- The ESP32 includes various built-in peripherals, including GPIO pins, ADCs, DACs, UART, SPI, I2C, and more, making it suitable for a wide range of IoT (Internet of Things) and embedded projects.

2- Wi-Fi Connectivity:

- One of the standout features of the ESP32 is its integrated Wi-Fi capabilities. It supports 2.4 GHz Wi-Fi 802.11 b/g/n, which enables it to connect to wireless networks and the internet.

- The Wi-Fi stack on the ESP32 allows it to act as both a station (client) that can connect to existing Wi-Fi networks and an access point (AP) that can create its own Wi-Fi network for other devices to connect to.

- The ESP32 supports secure Wi-Fi connections using protocols like WPA/WPA2 and even more advanced security features.

3- Applications:

The combination of the ESP32's processing power and built-in Wi-Fi makes it ideal for a wide range of applications, including:

- IoT devices: Sensors and actuators can be connected to the ESP32, which can then transmit data to the cloud or a local server via Wi-Fi.

- Home automation: ESP32 boards can be used to control smart home devices, monitor energy usage, and more.

- Wi-Fi-connected gadgets: You can build Wi-Fi-connected gadgets like weather stations, smart doorbells, and Wi-Fi-controlled robots.

- Internet-connected displays: ESP32 can be used to create web servers, IoT dashboards, and even simple web-based games.

4- Programming:

- The ESP32 can be programmed using various development environments, including the Arduino IDE, PlatformIO, and the Espressif IDF (IoT Development Framework).

- A rich ecosystem of libraries and resources is available for ESP32 development, making it easier to build Wi-Fi-enabled projects.

5- Power Consumption:

The ESP32 is relatively power-efficient, especially when compared to more power-hungry Wi-Fi modules. It offers power-saving features, making it suitable for battery-operated IoT devices.

In summary, the ESP32 board is a popular choice for IoT and embedded projects that require Wi-Fi connectivity. Its combination of a powerful microcontroller, integrated Wi-Fi capabilities, and extensive development support has made it a go-to platform for building a wide range of Wi-Fi-enabled devices and applications.

What is the web server for the ESP32 card ?

The web server for the ESP32 card refers to a program or functionality within the ESP32 microcontroller that enables it to handle HTTP requests, allowing it to function as an embedded web server.

This means that the ESP32 microcontroller can be programmed to act as a server, receiving requests (such as accessing a web page or sending data) from a web browser or any other HTTP client and responding to these requests accordingly.

By using libraries such as WiFi.h and WebServer.h in the Arduino development environment, you can configure and manage the web server on the ESP32 board. This capability enables the creation of IoT (Internet of Things) applications where the ESP32 board can be controlled or communicate with other devices via a web browser, mobile app, or any other HTTP client.

Role of boot.py and main.py files in ESP32 board

In an ESP32 board running MicroPython, the boot.py> and main.py files serve specific roles in the boot process and the execution of user code. Here's a brief explanation of each file:

1-boot.py:

- Role: The boot.py file is executed at boot time, specifically during the MicroPython boot sequence. It contains code that is executed immediately after the ESP32 board is powered on or reset.

- Typical Usage:

Setting up configuration options like Wi-Fi credentials.

Initializing hardware or peripherals that should be available as soon as the board starts.

Customizing the boot process, such as setting up specific logging or system-wide settings.

When the ESP32 boots, it first executes the boot.py file. After the boot.py execution, the ESP32 then proceeds to execute the main.py file, if it exists.

2- main.py:

- Role: The main.py file contains the main user code or application logic that you want the ESP32 to run. It is executed after the boot.py during the boot process. If the main.py file is present, it will be executed automatically on boot. If the main.py file does not exist, the board will still boot normally.

- Typical Usage:

Implementing your project's functionality, which could include tasks such as reading sensors, controlling actuators, communicating with other devices, or running a web server.

Structuring your MicroPython code and organizing it into functions, classes, and modules.

Implementing your custom application logic.

The necessary components to use the DHT11 sensor by the ESP32 card

ESP32 board:

ESP32 card

The ESP32 is a powerful microcontroller developed by Espressif Systems. It's renowned for its integrated Wi-Fi and Bluetooth capabilities, making it a popular choice for various IoT (Internet of Things) applications.

DHT11 Temperature and Humidity Sensor

The DHT11 is a basic, low-cost digital temperature and humidity sensor.

Jumper Wires:

Jumper wires

For making temporary connections and wiring between components.

Breadboard:

Test plate

A breadboard is a useful tool for creating temporary electronic circuits. It allows you to connect components without soldering.

Mounting the ESP32 board with the DHT11 sensor

ESP32 board wiring diagram with DHT11 sensorMounting the ESP32 board with the DHT11 sensor

This represents the basic connections between the DHT11 sensor and the ESP32 board:

- Connect the VCC(+) pin of the DHT11 sensor to the 3.3V pin on the ESP32 board.

- Connect the DATA pin of the DHT11 sensor to a digital pin 2 on the ESP32 board.

- Connect the GND(-) pin of the DHT11 sensor to any ground (GND) pin on the ESP32 board.

Program the ESP32 board with Micropython

To create a web server with MicroPython on the ESP32 to read and send temperature and humidity over Wi-Fi using boot.py and main.py, follow these steps:

1- boot.py: This file will handle the Wi-Fi connection. Make sure to replace 'your_ssid' and 'your_password' with your actual Wi-Fi credentials.

2- main.py: This file will handle reading temperature and humidity from a DHT sensor and sending the data to a server. Make sure to replace 'your_api_endpoint' with the actual API endpoint where you want to send the data.

After saving both boot.py and main.py on your ESP32, it should connect to Wi-Fi on boot and then run the main application to read sensor data and send it to your API endpoint.

Press an EN (Reset) button on the ESP32 board to display the IP address in the Shelle (example IP address is 192.168.1.75).

You can access this data by navigating to the IP address of your ESP32 from a web browser.

0 comment

Leave a comment

Veuillez noter s'il vous plaît*

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

+216 92 886 231

medaliprof@gmail.com

Pictures of the articles

Robotic site created by MedAli-Teacher info