Skip to main content
ESPBoards

ESP32 MW33 Digital Temperature and Humidity Sensor Module

The MW33 module is a reliable solution for measuring temperature and humidity, offering calibrated digital output and ease of integration with microcontrollers. With a temperature measurement range of 0°C to 50°C and a humidity range of 20% to 95%, the MW33 is suitable for various applications, including environmental monitoring and HVAC systems.

Jump to Code Examples

Arduino Core Image
ESP-IDF Image
ESPHome Image
PlatformIO Image
MicroPython Image

Quick Links

MW33 Digital Temperature and Humidity Sensor Module Datasheet ButtonMW33 Digital Temperature and Humidity Sensor Module Specs ButtonMW33 Digital Temperature and Humidity Sensor Module Specs ButtonMW33 Digital Temperature and Humidity Sensor Module Specs Button

MW33 Price

Normally, the MW33 Digital Temperature and Humidity Sensor Module costs around Approximately $3 per unit.
The prices are subject to change. Check current price:

Amazon com

Amazon de logo

Aliexpress logo

About MW33 Digital Temperature and Humidity Sensor Module

The MW33 is a digital sensor module designed to measure ambient temperature and humidity. It integrates a DHT11 sensor, which utilizes a capacitive humidity sensor and a thermistor to provide accurate readings. The module communicates via a single-wire digital interface, making it easy to interface with microcontrollers like the ESP32. It's suitable for various applications, including environmental monitoring and HVAC systems.

MW33 Sensor Technical Specifications

Below you can see the MW33 Digital Temperature and Humidity Sensor Module Technical Specifications. The sensor is compatible with the ESP32, operating within a voltage range suitable for microcontrollers. For precise details about its features, specifications, and usage, refer to the sensor’s datasheet.

  • Protocol: Single-Wire Digital
  • Operating Voltage: 3.3V to 5V
  • Temperature Range: 0°C to 50°C
  • Humidity Range: 20% to 95% RH
  • Temperature Accuracy: ±2°C
  • Humidity Accuracy: ±5% RH
  • Sampling Rate: 0.5 Hz (once every 2 seconds)
  • Dimensions: 19mm x 17mm

MW33 Sensor Pinout

Below you can see the pinout for the MW33 Digital Temperature and Humidity Sensor Module. The VCC pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND pin is the ground connection and must be connected to the ground of your ESP32!

The MW33 pinout is as follows:

  • VCC: Connect to a 3.3V or 5V power supply.
  • DATA: Outputs digital signal; connect to a digital input on your microcontroller.
  • GND: Connect to the ground of the microcontroller.

Code Examples

Below you can find code examples of MW33 Digital Temperature and Humidity Sensor Module with ESP32 in several frameworks:

Arduino Core Image

ESP32 MW33 Arduino IDE Code Example

Example in Arduino IDE

Fill in your main Arduino IDE sketch file with the following code to use the MW33 Digital Temperature and Humidity Sensor Module:

#include "DHT.h"

#define DHTPIN 4 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(115200);
Serial.println("MW33 Sensor Example");

dht.begin();
}

void loop() {
// Wait a few seconds between measurements
delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!
float humidity = dht.readHumidity();
// Read temperature as Celsius (the default)
float temperature = dht.readTemperature();

// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" % ");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
}

This Arduino sketch demonstrates how to interface with the MW33 sensor module, which integrates a DHT11 sensor. It initializes the sensor on digital pin 4 and reads the temperature and humidity every 2 seconds. The readings are then printed to the Serial Monitor. The code includes checks to ensure that the sensor readings are valid.

Connect your ESP32 to your computer via a USB cable, Ensure the correct Board and Port are selected under Tools, Click the "Upload" button in the Arduino IDE to compile and upload the code to your ESP32.

ESP-IDF Image

ESP32 MW33 ESP-IDF Code Example
Example in Espressif IoT Framework (ESP-IDF)

If you're using ESP-IDF to work with the MW33 Digital Temperature and Humidity Sensor Module, here's how you can set it up and read data from the sensor. Fill in this code in the main ESP-IDF file:

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "dht.h"

#define DHT_PIN GPIO_NUM_4

void app_main() {
setDHTgpio(DHT_PIN);

while (1) {
printf("Reading MW33 sensor...\n");

int ret = readDHT();
errorHandler(ret);

printf("Humidity: %.1f%%\n", getHumidity());
printf("Temperature: %.1f°C\n", getTemperature());

vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}

This ESP-IDF example demonstrates how to read data from the MW33 sensor module using GPIO pin 4. The `readDHT()` function reads the sensor data, and the humidity and temperature values are retrieved using `getHumidity()` and `getTemperature()` functions, respectively. The readings are printed to the console every 2 seconds.

Update the I2C pins (I2C_MASTER_SDA_IO and I2C_MASTER_SCL_IO) to match your ESP32 hardware setup, Use idf.py build to compile the project, Use idf.py flash to upload the code to your ESP32.

ESPHome Image

ESP32 MW33 ESPHome Code Example

Example in ESPHome (Home Assistant)

Fill in this configuration in your ESPHome YAML configuration file (example.yml) to integrate the MW33 Digital Temperature and Humidity Sensor Module

sensor:
- platform: dht
pin: GPIO4
model: DHT11
temperature:
name: "Living Room Temperature"
humidity:
name: "Living Room Humidity"
update_interval: 60s

This ESPHome configuration defines the MW33 sensor, which uses the DHT11 model. The sensor is connected to GPIO4, and two entities are created: one for temperature and one for humidity, with user-friendly names such as 'Living Room Temperature' and 'Living Room Humidity.' The sensor data is updated every 60 seconds, ensuring regular monitoring.

Upload this code to your ESP32 using the ESPHome dashboard or the esphome run command.

PlatformIO Image

ESP32 MW33 PlatformIO Code Example

Example in PlatformIO Framework

For PlatformIO, make sure to configure the platformio.ini file with the appropriate environment and libraries, and then proceed with the code.

Configure platformio.ini

First, your platformio.ini should look like below. You might need to include some libraries as shown. Make sure to change the board to your ESP32:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/DHT sensor library @ ^1.4.4
monitor_speed = 115200

ESP32 MW33 PlatformIO Example Code

Write this code in your PlatformIO project under the src/main.cpp file to use the MW33 Digital Temperature and Humidity Sensor Module:

#include "DHT.h"

#define DHTPIN 4 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(115200);
Serial.println("MW33 Sensor Example");

dht.begin();
}

void loop() {
delay(2000); // Wait 2 seconds between measurements

float humidity = dht.readHumidity();
float temperature = dht.readTemperature();

if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from MW33 sensor!");
return;
}

Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" % ");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
}

This PlatformIO example uses the Adafruit DHT library to interact with the MW33 sensor. It reads temperature and humidity values every 2 seconds and prints them to the Serial Monitor. The configuration is designed for the ESP32 and ensures compatibility with the MW33's DHT11 sensor module.

Upload the code to your ESP32 using the PlatformIO "Upload" button in your IDE or the pio run --target upload command.

MicroPython Image

ESP32 MW33 MicroPython Code Example

Example in Micro Python Framework

Fill in this script in your MicroPython main.py file (main.py) to integrate the MW33 Digital Temperature and Humidity Sensor Module with your ESP32.

from machine import Pin
from time import sleep
import dht

# Initialize the DHT sensor
sensor = dht.DHT11(Pin(4))

print("MW33 Sensor Example")

while True:
try:
sensor.measure()
temperature = sensor.temperature()
humidity = sensor.humidity()

print("Temperature: {:.1f}°C".format(temperature))
print("Humidity: {:.1f}%".format(humidity))
except Exception as e:
print("Error reading from MW33 sensor:", e)

sleep(2)

This MicroPython script demonstrates how to use the DHT11 sensor on the MW33 module. It initializes the sensor on GPIO4, retrieves temperature and humidity readings, and prints the results to the console every 2 seconds. Exception handling ensures that errors are caught and reported without halting the program.

Upload this code to your ESP32 using a MicroPython-compatible IDE, such as Thonny, uPyCraft, or tools like ampy.

Conclusion

We went through technical specifications of MW33 Digital Temperature and Humidity Sensor Module, its pinout, connection with ESP32 and MW33 Digital Temperature and Humidity Sensor Module code examples with Arduino IDE, ESP-IDF, ESPHome and PlatformIO.