I have an Arduino Nano RP2040 Connect with two temperature sensors. A DHT22 is connected to D2 and pulled up with a 5 kΩ resistor to 5V, and a LSM6DSOX IMU is built in to the board. Here's my code:
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <Arduino_LSM6DSOX.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT_Unified dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
IMU.begin();
}
void loop() {
delay(1000);
sensors_event_t event;
dht.temperature().getEvent(&event);
Serial.print(F("DHT22: "));
Serial.print(event.temperature);
Serial.print(F("°C and "));
float temperature_float = 0;
IMU.readTemperatureFloat(temperature_float);
Serial.print("LSM6DSOX: ");
Serial.print(temperature_float);
Serial.println(" °C");
}
When I run it, I get this in the serial monitor:
DHT22: 24.50°C and LSM6DSOX: 28.94°C
Why is there such a large difference (4.5°C/8.1°F) between the sensors?