Created
January 18, 2021 13:17
-
-
Save abdul-rehman-2050/c776df35d9991012ef17a1808dc2155e to your computer and use it in GitHub Desktop.
DS18b20 Temperature sensor interfacing with ESP8266
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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