Introduction

This week I explored input devices by testing two different types of sensors:

  • RTD (Resistance Temperature Detector) - analog temperature sensor with high precision.
  • DHT11 - digital temperature and humidity sensor.

The goal was to compare the performance of analog vs. digital sensors in terms of accuracy, range, and ease of integration.

DHT11 Sensor

About the Sensor

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

Wiring

  • VCC → 3.3V
  • GND → GND
  • DATA → Digital Pin D2

Used a 10kΩ pull-up resistor between VCC and DATA.

Code (Arduino IDE)

/**
	* 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));
	   }
   }
   

Results

  • Successfully received temperature and humidity data.
  • DHT22 provided more accurate and wider-range readings compared to DHT11.

RTD Sensor

About the Sensor

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.

Wiring

MAX31865 to XIAO ESP32S3:

  • VCC → 3.3V
  • GND → GND
  • SCK → D13
  • SDI → D11
  • SDO → D12
  • CS → D10

Code (Arduino IDE)

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);
	}
	

Results

  • Readings were very stable and accurate.
  • RTD sensors are more reliable for precision measurements but require more complex setup.

Conclusion

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.