ESP8266/Temp

From Noisebridge Wiki
Revision as of 04:43, 10 February 2026 by Maintenance script (talk | contribs) (Imported from Noisebridge wiki backup)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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]