
git
Git is a distributed version control system that tracks changes in any set of computer files.
This week I explored input devices by testing two different types of sensors:
The goal was to compare the performance of analog vs. digital sensors in terms of accuracy, range, and ease of integration.
The DHT11 and DHT22 are digital sensors that provide temperature and humidity data through a single-wire communication protocol.
Feature | DHT11 | DHT22 |
---|---|---|
Temperature Range | 0–50°C | -40–80°C |
Humidity Range | 20–80% RH | 0–100% RH |
Temperature Accuracy | ±2°C | ±0.5°C |
Humidity Accuracy | ±5% RH | ±2–5% RH |
Update Rate | 1 Hz | 0.5 Hz |
Used a 10kΩ pull-up resistor between VCC and DATA.
/**
* DHT11 Sensor Reader
* This sketch reads temperature and humidity data from the DHT11 sensor and prints the values to the serial port.
* It also handles potential error states that might occur during reading.
*
* Author: Dhruba Saha
* Version: 2.1.0
* License: MIT
*/
// Include the DHT11 library for interfacing with the sensor.
#include
// Create an instance of the DHT11 class.
// - For Arduino: Connect the sensor to Digital I/O Pin 2.
// - For ESP32: Connect the sensor to pin GPIO2 or P2.
// - For ESP8266: Connect the sensor to GPIO2 or D4.
DHT11 dht11(D2);
void setup() {
// Initialize serial communication to allow debugging and data readout.
// Using a baud rate of 9600 bps.
Serial.begin(9600);
// Uncomment the line below to set a custom delay between sensor readings (in milliseconds).
// dht11.setDelay(500); // Set this to the desired delay. Default is 500ms.
}
void loop() {
int temperature = 0;
int humidity = 0;
// Attempt to read the temperature and humidity values from the DHT11 sensor.
int result = dht11.readTemperatureHumidity(temperature, humidity);
// Check the results of the readings.
// If the reading is successful, print the temperature and humidity values.
// If there are errors, print the appropriate error messages.
if (result == 0) {
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C\tHumidity: ");
Serial.print(humidity);
Serial.println(" %");
} else {
// Print error message based on the error code.
Serial.println(DHT11::getErrorString(result));
}
}
RTDs like the PT100 offer accurate and reliable temperature measurement. Since the PT100 is analog, I used a MAX31865 breakout board to convert the signal into digital data via SPI.
MAX31865 to XIAO ESP32S3:
Used the Adafruit MAX31865
library:
#include
#define SDA_PIN 4 // Define SDA pin (D4 on XIAO RP2040)
#define SCL_PIN 5 // Define SCL pin (D5 on XIAO RP2040)
void setup() {
Serial.begin(115200); // Start Serial Monitor
Wire.setSDA(SDA_PIN); // Set custom SDA pin
Wire.setSCL(SCL_PIN); // Set custom SCL pin
Wire.begin(); // Initialize I2C with custom SDA and SCL pins
delay(1000); // Allow time for Serial to initialize
}
void loop() {
int temperature = 25; // Dummy temperature value, replace with actual reading logic
// Send temperature data to ESP32 S3 via I2C
Wire.beginTransmission(8); // Start communication with ESP32 S3 at address 8
Wire.write(temperature); // Send temperature value
Wire.endTransmission(); // End communication
// Wait 1 second before sending data again
delay(1000);
}
This week, I learned how to integrate both digital and analog temperature sensors into my microcontroller system. DHT11/DHT22 were easier to set up, while the RTD provided more precise data. The experience helped me understand signal types, sensor protocols, and accuracy trade-offs.