i have a project in which i must use android to read temperature from arduino uno using dht11 sensor
What i want to do, is adding a test to check if the sensor is connected or not, because sometimes the sensor is not connected and i would like to send a message back saying that dht11 sensor is not connected
The dht11 sensor has 3 pins. Two of them are for the power source. If the sensor isn't connected properly, then there is no valid value that you'll get from the sensor?
}else{
Serial.println("The sensor is not connected");
}
If you're using the library from the Playground, the .read() method only returns a 0 for a successful read. If there's a timeout (like when the sensor isn't there) it returns -2.
So check the return value of .read() before using the .humidity and .temperature values.
I just tried an idea I found on the web: I have a soil humidity sensor connected to pin A0. I also connected pin D2 to A0 with a jumper wire (no resistor needed). Then I wrote a HIGH signal to D2 OUTPUT, that can be AnalogRead at A0 as a value of 1023. If the sensor senses a "normal" soil humidity it will usually be lower than 1023 and it kinda "overrides" the HIGH signal from D2.
If the sensor works/is connected you get values lower than 1023, if it is disconnected you get 1023 at A0. For me it worked well.