Temperature sensor error

I'm on an Arduino UNO, and my temp sensor is DHT11. I ran this code:

const int sensorPin = A5;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  int sensorVal = analogRead(sensorPin);
  Serial.print("Sensor Value: ");
  Serial.print(sensorVal);

  float voltage = (sensorVal/1024.0) * 5.0;
  Serial.print(", Volts: ");
  Serial.print(voltage);

  float temperature = (voltage - .5) * 100;
  Serial.print(", degrees C: ");
  Serial.println(temperature);

  delay(1000);
}

But my output wasn't something normal like 20C, it was Sensor Value: 1023, Volts: 5.00, degrees C: 449.51, I tried changing the jumper wires, changing its position on the breadboard. I tried running some other code that was from the Arduino Projects Book, and I still got wrong numbers. Does anyone know how to fix that?

Have your read the DHT11 Datasheet?

The DHT11 is not an analog sensor that you can read on an analog port. It communicates with a digital protocol:


The best to read its data is to use libraries such as DHT or write your own reading function, as here

Sensor Value: 1023

Looks like a wiring problem as analogRead() returns 1023 when the input voltage equals the reference voltage (here 5V)

Shouldn't you be using the DHT11 library to read from the sensor ?
How is the sensor wired ?

Does anyone know how to fix that?

A search for "Arduino DHT11 tutorial" gets 270000 results so, yeah, somebody does.

Ouch, that hurt :stuck_out_tongue:

Well, thanks for the replies and guides