Skip to content

Instantly share code, notes, and snippets.

@abdul-rehman-2050
Created January 18, 2021 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdul-rehman-2050/c776df35d9991012ef17a1808dc2155e to your computer and use it in GitHub Desktop.
Save abdul-rehman-2050/c776df35d9991012ef17a1808dc2155e to your computer and use it in GitHub Desktop.
DS18b20 Temperature sensor interfacing with ESP8266
/*
Here is the complete tutorial for this code
http://www.fypsolutions.com/examples/ds18b20-interfacing-with-esp8266-nodemcu-board/
*/
#include <DallasTemperature.h>
#include <OneWire.h>
#define ONE_WIRE_BUS D1 //D2 pin of nodemcu
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature ds18b20(&oneWire); // Pass the oneWire reference to Dallas Temperature.
void setup(void)
{
Serial.begin(9600);
ds18b20.begin();
}
void loop(void)
{
ds18b20.requestTemperatures(); // Send the command to get temperatures
Serial.print("Temp: ");
Serial.println(ds18b20.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
delay(500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment