Temperature and Humidity Sensor With MicroPython Using Bharat Pi Board

by bharatpi in Circuits > Electronics

217 Views, 0 Favorites, 0 Comments

Temperature and Humidity Sensor With MicroPython Using Bharat Pi Board

WhatsApp Image 2024-04-21 at 1.57.39 PM.jpeg
WhatsApp Image 2024-04-21 at 1.51.48 PM.jpeg

In this blog, you’ll learn how to use the temperature and humidity Sensor with the ESP32 to get the readings using Micropython firmware. This tutorial covers how to wire the sensor to the ESP32 boards and provides a simple Micropython script to get the temperature and humidity readings.

In this project, we are using Bharat Pi which has both ESP32 microcontroller and a SimCom A7672S 4G/LTE module. Bharat Pi is an IoT prototyping board for students, innovators, startups, and developers. A simplified board with an all-in-one compute, network and storage on a single board to build rapid prototypes.

In the rapidly advancing world of the Internet of Things (IoT) and home automation, understanding and controlling the environment around us has become essential. Temperature and humidity are critical parameters that influence our comfort, health, and the behaviour of various systems.

Supplies

WhatsApp Image 2024-04-21 at 1.38.23 PM.jpeg
WhatsApp Image 2024-04-21 at 12.46.45 PM.jpeg
WhatsApp Image 2024-04-14 at 3.44.58 PM.jpeg

Required Components:

To complete this tutorial you need the following parts:

1. DHT11 Temperature and Humidity Sensor

2. ESP32 (Bharat Pi board)

3. Jumper Wires

5. USB Cable

To follow this instruction you need an IDE to write and upload the code to your board, you can use Thonny IDE or uPycraft IDE. you also need Micropython firmware installed in your ESP32 boards.

If you don't have the setup means then you can check the README file of installing and setup of uPyCraft and Thonny IDE in our Bharat Pi github page you can find the link below,

https://github.com/Bharat-Pi/MicroPython/blob/main/README.md

Schematic – ESP32 With DHT11 Sensor

WhatsApp Image 2024-04-21 at 12.51.13 PM.jpeg


In this section, we will see how to connect DHT 11 sensor with ESP32. The DHT 11 sensor will be connected with the ESP32 board with its 3 pins (GND, VCC, DATA).

Follow the schematic diagram for the ESP modules and connect them accordingly. Connect the ESP32 device with the DHT 11 sensor as shown in the schematic diagram above:

DHT 11 Sensor Pinout

VCC - Power Supply

DATA - GPIO

GND - GND

Wire the DHT 11 sensor to the ESP32 as shown in the following schematic diagram. We’re connecting the VCC pin to 3V/5V, and the DATA pin to GPIO 23, but you can use any other suitable pins, then GND to GND pin.

ESP32 Wiring With DHT 11 Sensor

DHT 11 Sensor - ESP32

VCC - 3V / 5V

DATA - GPIO 23

GND - GND

DHT11 Sensor

FDFUVTGLV84102O.jpg


What are Temperature and Humidity Sensors?

Temperature sensors, as the name suggests, measure the ambient temperature of the surrounding environment. These sensors can be classified into contact and non-contact types. Contact sensors, like thermocouples and thermistors, physically come in direct contact with the object to be measured. Non-contact sensors, such as infrared temperature sensors (IR sensors), measure temperature remotely by detecting the thermal radiation emitted by the object.

On the other hand, humidity sensors, or hygrometers, measure the moisture content in the air. They are essential in various applications, including weather forecasting, indoor climate control, industrial processes, and even agricultural practices.

Temperature Sensors:

  • Thermocouples work on the principle of the Seebeck effect, where two dissimilar metals produce a voltage proportional to the temperature difference between the hot and cold junctions.
  • Thermistors are resistors whose resistance changes with temperature. They are of two types: negative temperature coefficient (NTC) and positive temperature coefficient (PTC) thermistors.
  • Infrared temperature sensors detect the infrared energy emitted by an object and convert it into an electrical signal, which is then used to calculate the temperature.

Humidity Sensors:

  • Capacitive humidity sensors measure the change in capacitance of a capacitor due to the absorption of water molecules on its surface.
  • Resistive humidity sensors, also known as hygroscopic sensors, use a moisture-absorbing material whose resistance changes with humidity levels.
  • Thermal conductivity humidity sensors measure the cooling effect of water vapor on a heated sensing element.

Here’s the pinout of the DHT11 Sensor :

VCC

DATA

GND

CODE (DHT 11 Sensor)

Screenshot (14).png

CODE :





from machine import Pin
from time import sleep
import dht
 
sensor = dht.DHT11(Pin(23))
 
while True:
    sensor.measure()
    temp = sensor.temperature()
    hum = sensor.humidity()
 
    print('Temperature=', temp, 'C')
    print('Humidity=', hum, '%')
 
    sleep(3)


Demonstartion

Screenshot (15).png

After uploading the code to your board,the temperature and humidity readings should be printed on the console.


Applications

Weather Monitoring: Temperature and humidity sensors are essential components of weather stations, providing accurate data for forecasting and climatology studies.

Indoor Climate Control: In HVAC systems, these sensors ensure that indoor conditions are optimized for human comfort and energy efficiency.

Agriculture and Greenhouses: Monitoring temperature and humidity levels helps optimize crop growth and yield in controlled environments.

Food Storage and Transport: In the food industry, these sensors are used to maintain ideal conditions for storing and transporting perishable goods.

Healthcare: Temperature and humidity monitoring is crucial in healthcare settings to ensure a safe and comfortable environment for patients.

Home Automation: Smart homes use these sensors to adjust heating, cooling, and ventilation based on environmental conditions.