The DS18B20() function will get the temperature from a DS18B20 temperature sensor. This device can be purchased on eBay for about $5 in a variety of packages including a waterproof probe version.
MMBasic 5.0: DS18B20() has been renamed to TEMPR(), DS18B20 START is TEMPR START.
The DS18B20 can be powered separately by a 3V to 5V supply or it can operate on parasitic power as shown on the right. Multiple sensors can be used but a separate I/O pin and pullup resistor is required for each one.
To get the current temperature you just use the DS18B20() function in an expression.
PRINT "Temperature: " DS18B20(pin)
Where ‘pin’ is the I/O pin to which the sensor is connected. You do not have to configure the I/O pin, that is handled by MMBasic.
The returned value is in degrees C with a resolution of 0.25ºC and is accurate to ±0.5 ºC. If there is an error during the measurement the returned value will be 1000.
The time required for the overall measurement is 200mS and the running program will halt for this period while the measurement is being made. This also means that interrupts will be disabled for this period. If you do not want this you can separately trigger the conversion using the DS18B20 START command then later use the DS18B20() function to retrieve the temperature reading. The DS18B20() function will always wait if the sensor is still making the measurement.
DS18B20 START 15 < do other tasks > PRINT "Temperature: " DS18B20(15)