Gustavo Reynaga
Published © CC0

ESP-201 (ESP8266) Temperature & Humidity Web Server

Create a Web Server with ESP-201 and DHT11 sensor.

BeginnerFull instructions provided1 hour7,472
ESP-201 (ESP8266) Temperature & Humidity Web Server

Things used in this project

Hardware components

ESP-201
×1
SparkFun FTDI Basic Breakout - 3.3V
SparkFun FTDI Basic Breakout - 3.3V
×1
Resistor 10k ohm
Resistor 10k ohm
×3
Capacitor 220 µF
Capacitor 220 µF
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×2
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Solderless Breadboard Full Size
Solderless Breadboard Full Size
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino core for ESP8266 WiFi chip

Story

Read more

Schematics

Temperature & Humidity Web Server With ESP-201 and DHT11 sensor.

Create a Web Server with ESP-201 and DHT11 sensor

Code

Temperature & Humidity Web Server With ESP-201 and DHT11 sensor.

Arduino
Create a Web Server with ESP-201 and DHT11 sensor
/*
 * Source: http://www.elec-cafe.com/esp8266-temperature-humidity-webserver-with-a-dht11-sensor/
 * Modify by: Gustavo Reynaga @gsreynaga MazMaker http://www.mazportal.com
 *
 */

#include <ESP8266WiFi.h>
#include <DHT11.h>

const char* ssid     = "ssid"; // Your ssid
const char* password = "password"; // Your Password

int pin = 2;

WiFiServer server(80);
DHT11 dht11(pin);

double Fahrenheit(double celsius) {
return ((double)(9 / 5) * celsius) + 32;
}

double Kelvin(double celsius) {
return celsius + 273.15;
}

void setup() {
Serial.begin(115200);
delay(10);
Serial.println();

// Connect to WiFi network
WiFi.mode(WIFI_STA);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("ESP-201 is online");

// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.println(WiFi.localIP());
}

void loop() {
int err;
float temp, humi;
if ((err = dht11.read(humi, temp)) == 0)
{
Serial.print("temperature:");
Serial.print(temp);
Serial.print(" humidity:");
Serial.print(humi);
Serial.println();
}
else
{
Serial.println();
Serial.print("Error No :");
Serial.print(err);
Serial.println();
}
WiFiClient client = server.available();
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");  // the connection will be closed after completion of the response
client.println("Refresh: 5");  // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE html>");
client.println("<html xmlns='http://www.w3.org/1999/xhtml'>");
client.println("<head>\n<meta charset='UTF-8'>");
client.println("<title>ESP8266 Temperature & Humidity DHT11 Sensor</title>");
client.println("</head>\n<body>");
client.println("<H2>ESP8266 & DHT11 Sensor</H2>");
client.println("<H3>Humidity / Temperature</H3>");
client.println("<pre>");
client.print("Humidity (%)         : ");
client.println((float)humi, 2);
client.print("Temperature (C)  : ");
client.println((float)temp, 2);
client.print("Temperature (F)  : ");
client.println(Fahrenheit(temp), 2);
client.print("Temperature (K)  : ");
client.println(Kelvin(temp), 2);
client.println("</pre>");
client.println("<H3>www.algun_sitio.com</H3>");//Put your Web Page here
client.println("<img src='http://www.algun_sitio.com/logos/logo_video.png'>");// Put your image here
client.print("</body>\n</html>");
delay(DHT11_RETRY_DELAY); //delay for reread
}

Credits

Gustavo Reynaga

Gustavo Reynaga

12 projects • 73 followers
Iam a teacher

Comments