ESP8266/Temp
< ESP8266
Temperature Sensing with Dallas DS18B20
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) // Pass the GPIO pin number sensor(s) is connected to OneWire oneWire(13); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); // Put this in setup() sensors.begin(); // Put this where you want to read temp sensors.requestTemperatures(); sensors.getTempCByIndex(0);
Hack for Fahrenheit and float conversion
sensors.requestTemperatures(); float tempFloat = sensors.getTempCByIndex(0) * 1.8 + 32; // convert to F int tempReading = int(tempFloat); int tempReadingTenth = int((tempFloat - tempReading) * 10); // Hack around %f // For use with sprintf() // sprintf(buff, 100, "Temperature: %d.%d", tempReadig, tempReadingTenth);
Dallas Library[edit]
http://www.milesburton.com/?title=Dallas_Temperature_Control_Library
Library Download:
References[edit]
- Sensor Data Sheet
- Arduino Reference Project
- ESP8266 Reference Project