Sara is probably the best one to comment on the code aspect of your question, but hardware-wise, you might want to try a different pair of pins for connecting the sensor. D19 is used as the status pin of the Xbee socket, and is used in all of the code examples we use for radio, wifi, and cellular telemetry. D18 is kind of reserved for being used as either the card detect pin of the microSD card socket (if you enable SJ10), or you can use it for reading a trigger from the RTC via SJ6. So picking a pair of pins that’s totally free would be good in case you want to add telemetry or other features to your board. D4, D5, D6, D7, D10, and D11 are free, which is why I put them on the Grove sockets. The other digital pins that are available on the 20-pin header are bought out for compatibility with things you might put on a protoshield, but aren’t necessarily free for any sort of output or input from a sensor or other device.