Skip to content

Instantly share code, notes, and snippets.

@mims92
Created November 5, 2017 14:15
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 mims92/6aa160dc35076e05107feeb3d3fcdd53 to your computer and use it in GitHub Desktop.
Save mims92/6aa160dc35076e05107feeb3d3fcdd53 to your computer and use it in GitHub Desktop.
ESP8266 - C - DHT11 Temperature and humidity sensor
/**
* You need to include SimpleDHT library to Arduino IDE (or whatever IDE you are using).
* https://github.com/mims92/SimpleDHT (fork)
* https://github.com/winlinvip/SimpleDHT (official)
* Please it in the library folder of Arduino.
*/
#include "ESP8266WiFi.h"
#include "SimpleDHT.h"
#define DHTTYPE DHT22
#define DHTPIN 5
SimpleDHT11 dht11;
float humidity, temp_c;
void setup() {
Serial.begin(115200);
getTemperature();
}
void loop() {}
void getTemperature() {
dht11.read2(DHTPIN, &temp_c, &humidity, NULL);
Serial.print(temp_c);
Serial.println("C°");
Serial.print(humidity);
Serial.println("%");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment