In keeping with my policy of generating more-useful demos for various arduino widgets - here's one for the Dallas DS18B20 sensor.
What's special here is yes, it's yet another state machine, and no, it doesn't block. It simply maintains an array of temperature measurements, and sets a flag when it updates them. I'm using the waterproof version here for soil temperatures. I've tested this with up to two sensors on the same wire, it seems to call them the same unit # and detect how many there are pretty reliably, though as always, YMMV. There are some interesting comments in the basic library that indicate possibilities of errors, which is why I set the delay a little extra long. But really, this is temperature. Do you really need to go faster than 1/second for a (possible array of) measurement here?
The idea behind this series of sketches is that you should be able to easily take them and incorporate them in your own work. They're supposed to be friendly, let you change things easily with #defines and contain state machines that do the work - or return immediatly - when called from "loop()" so your loop remains responsive to other things - no blocking here, though some things might take a few cycles, delay() is verboten outside of the setup()-called functions.
In theory, this is supposed to support up to 8 sensors on the same wire. Dunno if you need to keep reducing the pullup resistance. I'm doing two with one 4.7k pullup just fine here. Here it is running on my laptop with one sensor in cold water on the floor, and the other looking at the exhaust from the laptop fan.
And here's the sketch:
You might notice that at the top I have a define about REQUIRESALARMS commented out. The default is true, and if you don't need them, uncommenting this saves you a little ram space. The compiler already seems to be smart enough to leave out unreachable code...It seems to save a few bytes but not affect this sketch, since I'm not using alarms here - it's actually faster to just read the temperatures and do that in arduino code anyway.