A compact, ESP8266-powered temperature and humidity sensor featuring a 0.96" OLED display, onboard web server, and a 3D-printed enclosure. Designed for easy deployment and seamless integration with home automation platforms like Home Assistant.
OLED Display (0.96")
Displays live temperature (°F) and humidity (%) readings directly on the device.
Built-in Web Interface
Accessible on the local network, it provides real-time sensor data via a clean, responsive interface.
3D-Printed Enclosure
Custom housing designed for durability, airflow, and visual appeal.
Wi-Fi Config Portal
Web-based SSID/password input, removing the need to hardcode credentials.
SQL Upload Support
Push sensor data to a backend for centralized logging.
Grafana Integration
Feed time-series data into Grafana dashboards for long-term trends and visualization.
Home Assistant Support
Expose sensor values over MQTT or HTTP endpoints to integrate with smart home automations.
After connecting the sensor to Wi-Fi, you can access its IP address via any browser to view the real-time temperature and humidity readings. The web interface uses ESPAsyncWebServer
and updates values dynamically every 10 seconds.
Adafruit_DHT
, Adafruit_SSD1306
, ESPAsyncWebServer
, WiFi
, etc./downloads/
in the public repoThe sensor is powered by a Wemos D1 Mini, DHT22 sensor, and a 0.96" OLED screen. It uses ESPAsyncWebServer
to serve a small web page that displays live sensor data.
//Board Archives
#include <Arduino.h>
#include <Wire.h>
//DHT Archives
#include <Adafruit_Sensor.h>
#include <DHT.h>
//OLED Arhives
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Fonts\Picopixel.h>
//WiFi + WebServer Archives
#include <ESP8266WiFi.h>
#include <Hash.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
//Network Connection
const char* ssid = "WhiteElephant_IOT";
const char* password = "strawberryjam";
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
#define DHTPIN 14 // Digital pin connected to the DHT sensor
// Uncomment the type of sensor in use:
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
// current temperature & humidity, updated in loop()
float t = 0.0;
float h = 0.0;
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0; // will store last time DHT was updated
// Updates DHT readings every 10 seconds
const long interval = 10000;
//webpage code
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">
<style>
html {
font-family: Arial;
display: inline-block;
margin: 0px auto;
text-align: center;
}
h2 { font-size: 3.0rem; }
p { font-size: 3.0rem; }
.units { font-size: 1.2rem; }
.dht-labels{
font-size: 1.5rem;
vertical-align:middle;
padding-bottom: 15px;
}
</style>
</head>
<body>
<h2>ESP8266 DHT Server</h2>
<p>
<i class="fas fa-thermometer-half" style="color:#059e8a;"></i>
<span class="dht-labels">Temperature</span>
<span id="temperature">%TEMPERATURE%</span>
<sup class="units">°F</sup>
</p>
<p>
<i class="fas fa-tint" style="color:#00add6;"></i>
<span class="dht-labels">Humidity</span>
<span id="humidity">%HUMIDITY%</span>
<sup class="units">%</sup>
</p>
</body>
<script>
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("temperature").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/temperature", true);
xhttp.send();
}, 10000 ) ;
setInterval(function ( ) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("humidity").innerHTML = this.responseText;
}
};
xhttp.open("GET", "/humidity", true);
xhttp.send();
}, 10000 ) ;
</script>
</html>)rawliteral";
// Replaces placeholder with DHT values
String processor(const String& var){
Serial.println(var);
if(var == "TEMPERATURE"){
return String(t);
}
else if(var == "HUMIDITY"){
return String(h);
}
return String();
}
void setup() {
// Serial port for debugging purposes
Serial.begin(115200);
//DHT Startup
dht.begin();
//Display Startup
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.println("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println(".");
}
// Print ESP8266 Local IP Address
Serial.println(WiFi.localIP());
// Route for root / web page
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/html", index_html, processor);
});
server.on("/temperature", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", String(t).c_str());
});
server.on("/humidity", HTTP_GET, [](AsyncWebServerRequest *request){
request->send_P(200, "text/plain", String(h).c_str());
});
// Start server
server.begin();
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you updated the DHT values
previousMillis = currentMillis;
// Read temperature as Celsius (the default)
//float newT = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float newT = dht.readTemperature(true);
// if temperature read failed, don't change t value
if (isnan(newT)) {
Serial.println("Failed to read from DHT sensor!");
}
else {
t = newT;
Serial.println(t);
}
// Read Humidity
float newH = dht.readHumidity();
// if humidity read failed, don't change h value
if (isnan(newH)) {
Serial.println("Failed to read from DHT sensor!");
}
else {
h = newH;
Serial.println(h);
}
}
Serial.println("Do I EVEN GET HERE????!!!");
// clear display
display.clearDisplay();
// display title
display.setCursor(0, 0);
display.setTextColor(BLACK, WHITE);
display.setTextSize(1);
display.print("Max's IOT Sensor");
display.setTextColor(WHITE);
display.setCursor(0, 7);
display.setFont(&Picopixel);
display.print("BETA_v2 // Test");
// display humid
display.setCursor(0, 30);
display.setFont(NULL);
display.setTextColor(BLACK, WHITE);
display.setTextSize(1);
display.print("Humidity:");
display.setCursor(0, 35);
display.setTextColor(WHITE);
display.print(dht.readHumidity());
display.setCursor(35, 35);
display.print("%");
// display temp
display.setCursor(0, 45);
display.setTextColor(BLACK, WHITE);
display.print("Temp:");
display.setCursor(0, 55);
display.setTextColor(WHITE);
//display.print((dht.readTemperature() * 1.8) + 32, 2);
display.print(dht.readTemperature(true));
display.setCursor(35, 55);
display.print("F");
display.display();
delay(2000);
}
DHT22
SSD1306
via I2C (address 0x3C
)