1

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?

3
  • Your 1st stop should be the specification sheets for the two parts. You should find the STMicro accelerometer spec sheet at st.com. I'm not sure about the DHT22. Since I've had my share of problems with the DHT22, I'd look else where. But that's just personal preference.
    – st2000
    Jul 1, 2023 at 15:48
  • Also, where is the accelerometer? If it's buried next to heat generating parts then it may not reflect ambient temperature. Remember, the accelerometer needs its temperature to compensate for its own acceleration sensors. Not for telling you what the ambient temperature is.
    – st2000
    Jul 1, 2023 at 15:54
  • you title question cannot be answered without knowing the ambient temperature ... you can answer it yourself anyway
    – jsotola
    Jul 1, 2023 at 18:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.