John,

could you post your schematic?

The problem is most likely a missing (or incorrect) resistor.
If you want to run the Sensor on "parasitic power" have close look at the datasheet regarding the timing.

BTW
I'm sure there are already several code examples on this forum.