There is a known issue with this sensor and all sensors that use one wire. The reason is because the IO pins are not fast enough in switching from input to output so the data is lost. However there is a workaround for this issue which is using two pins instead of one, one pin would be the input and the other pin the output. Please check the following threads where this topic has been discussed before, you will find some example codes and diagrams to know how you should connect your sensor:
- Edison + Arduino Expansion + DFRobot I/O Expansion Shield v7: cannot get readings from Digital pins.
- 3 Pin ultrasonic sensor in galileo
- DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one
You will find other workarounds in those threads like this one: Re: DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one. I hope you find this information useful.