AM2302 Temperature & Humidity Sensor
AM2302 Temperature & Humidity Sensor
The AM2302 is a digital temperature and humidity sensor module designed for various Internet of Things (IoT) applications, home automation, and environmental monitoring projects. This sensor module is capable of measuring both temperature and relative humidity with high accuracy and reliability.
The AM2302 sensor module is designed to measure the ambient temperature and relative humidity in the surrounding environment. It uses a thermistor to measure temperature and a capacitive humidity sensor to measure relative humidity. The sensor module outputs digital signals that can be easily read by microcontrollers such as Arduino, Raspberry Pi, or other IoT development boards.
0% to 99.9% RH (Relative Humidity)
2% RH
0.1% RH
Digital serial signal (Manchester code)
Single-bus communication protocol
3.3V to 5.5V
<2mA (average)
High accuracy and reliability
Fast response time
Low power consumption
Compatible with various microcontrollers and development boards
The AM2302 sensor module is typically packaged in a compact, 3-pin (VCC, GND, OUT) SIP (Single In-Line Package) module with a dimension of 15mm x 10mm x 5mm.
-40C to 80C (-40F to 176F)
-50C to 100C (-58F to 212F)
Before using the AM2302 sensor module, please refer to the datasheet for specific usage guidelines, calibration requirements, and any necessary precautions to ensure accurate and reliable measurements.
AM2302 Temperature & Humidity Sensor Documentation
Overview
The AM2302 is a digital temperature and humidity sensor that uses a capacitive sensor to measure relative humidity and a thermistor to measure temperature. It is a popular choice for IoT applications due to its high accuracy, wide range, and low power consumption.
Pinout
The AM2302 sensor has four pins:
VCC: Power supply (3.3V to 5V)
GND: Ground
DOUT: Digital output (1-wire protocol)
Communication Protocol
The AM2302 uses a 1-wire protocol to communicate with the microcontroller. The protocol consists of a 40-bit data frame, which includes:
16 bits for humidity data
16 bits for temperature data
8 bits for checksum
Code Examples
Example 1: Raspberry Pi (Python)
This example uses the `pyAM2302` library to read temperature and humidity data from the AM2302 sensor connected to a Raspberry Pi.
```python
import time
from pyAM2302 import AM2302
# Create an instance of the AM2302 class
sensor = AM2302()
while True:
# Read temperature and humidity data
temperature, humidity = sensor.read()
# Print the data
print(f'Temperature: {temperature:.1f}C, Humidity: {humidity:.1f}%')
# Wait for 1 second before taking the next reading
time.sleep(1)
```
Example 2: Arduino (C++)
This example uses the `DHT` library to read temperature and humidity data from the AM2302 sensor connected to an Arduino board.
```c++
#include <DHT.h>
#define DHTPIN 2 // Pin 2 for data output
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
// Wait a few seconds between readings
delay(2000);
// Read temperature and humidity data
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Print the data
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}
```
Example 3: ESP32 (MicroPython)
This example uses the `machine` module to read temperature and humidity data from the AM2302 sensor connected to an ESP32 board.
```python
import machine
import utime
# Create a onewire object
ow = machine.Pin(4) # Pin 4 for data output
d = machine.DHT(ow, machine.DHT.AM2302)
while True:
# Read temperature and humidity data
d.measure()
# Print the data
print(f'Temperature: {d.temperature():.1f}C, Humidity: {d.humidity():.1f}%')
# Wait for 1 second before taking the next reading
utime.sleep(1)
```
Note: Make sure to install the required libraries and adapt the pin connections according to your specific setup.