ESP8266 Arduino Integration: Installation & DHT11 Sensor Test
Arduino Support for ESP8266 with Simple Test Code
The NodeMCU is more than just a WiFi module; it includes a powerful microcontroller with a 32-bit Tensilica processor. It boasts a power-saving architecture, compact size, and high durability, making it an excellent choice for IoT applications. In this tutorial, we’ll guide you through setting up Arduino support for the ESP8266 and running a simple test using a DHT11 temperature and humidity sensor.
Installing the ESP8266 Board Package
Step 1: Download Arduino IDE
Before proceeding, download and install the Arduino IDE from the official website: Arduino Software
Step 2: Add ESP8266 Board Support
- Open Arduino IDE.
- Navigate to File > Preferences.
- In the Additional Boards Manager URLs field, enter the following URL:
http://arduino.esp8266.com/stable/package_esp8266com_index.json
- Click OK to save the changes.
Step 3: Install the ESP8266 Package
- Go to Tools > Board > Boards Manager.
- In the search box, type ESP8266.
- Select the ESP8266 by ESP8266 Community package and click Install.
Step 4: Select the ESP8266 Board
- Restart the Arduino IDE.
- Go to Tools > Board and select Generic ESP8266 Module.
Now, your Arduino IDE is ready to program the ESP8266!
Testing with DHT11 Temperature & Humidity Sensor
The DHT11 sensor is a popular choice due to its affordability, accuracy, and pre-calibration. Below is the pin configuration:
DHT11 Pinout
- VCC → Connect to 3.3V or 5V on NodeMCU
- GND → Connect to GND on NodeMCU
- Data → Connect to D1 (GPIO 5) on NodeMCU
Installing Required Libraries
To use the DHT11 sensor, install the necessary libraries:
- Download the DHT sensor library.
- Extract the
.zip
file and rename the folder toDHT
. - Move the
DHT
folder to the Arduino libraries directory. - Download the Adafruit Unified Sensor Driver Library.
- Extract the
.zip
file and rename the folder toAdafruit_sensor
. - Move the
Adafruit_sensor
folder to the Arduino libraries directory. - Restart the Arduino IDE.
Code Example: Reading Temperature & Humidity
Copy and paste the following code into the Arduino IDE. Replace YOUR_NETWORK_NAME
and YOUR_NETWORK_PASSWORD
with your actual WiFi credentials.
#include <ESP8266WiFi.h>
#include "DHT.h"
#define DHTTYPE DHT11
const char* ssid = "YOUR_NETWORK_NAME";
const char* password = "YOUR_NETWORK_PASSWORD";
WiFiServer server(80);
const int DHTPin = 5;
DHT dht(DHTPin, DHTTYPE);
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
server.begin();
Serial.println(WiFi.localIP());
}
void loop() {
WiFiClient client = server.available();
if (client) {
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
client.println("<html><body><h1>ESP8266 - Temperature and Humidity</h1>");
client.println("<h3>Temperature: " + String(t) + " *C</h3>");
client.println("<h3>Humidity: " + String(h) + " %</h3>");
client.println("</body></html>");
delay(1);
client.stop();
}
}
Running the Test
- Upload the code to your NodeMCU using the Arduino IDE.
- Open the Serial Monitor at a baud rate of 115200.
- Once connected, the ESP8266’s IP address will appear in the Serial Monitor.
- Open a web browser and enter the displayed IP address.
- You should see the temperature and humidity data displayed in your browser.
Conclusion
With this setup, you can easily integrate the ESP8266 with the Arduino IDE and interface it with sensors like the DHT11. This tutorial provides a solid foundation for building IoT projects involving temperature and humidity monitoring.
Pingback: NodeMcu to DHT Interface in Blynk app - IoTbyHVM
Pingback: Arduino ESP32 support on Windows and Ubuntu - IoTbyHVM
Pingback: Using Mq135 Sensor with InfluxDB - IoTbyHVM
Pingback: ESP32 BLE with DHT11 - How To - IoTbyHVM
Pingback: ESP8266 as a MQTT Broker | How To Make ESP8266 as a MQTT Broker
Pingback: Using Node js and Arduino with LED Blinking Program
Pingback: IoT OS and RTOS for Internet of Things devices - IoTbyHVM
Pingback: ESP32 BLE Tutorials | How to use ESP32 with BLE
Pingback: ESP8266 Static IP Address Using Arduino Example - ESP
Pingback: GPIO pins of ESP8266 and How to use efficiently -IoTbyHVM
Pingback: Heroku | How To use | Getting started with Heroku ...
Pingback: Install Ubuntu Core on Raspberry Pi 2 or 3 - IoTbyHVM
Pingback: How to Fix Ubuntu Update Errors - IoTbyHVM - Bits & Bytes of IoT
Pingback: NodeRed Alternatives - Visual programming tools -IoTbyHVM
Pingback: ESP8266 Web Server | ESP8266 Web Server AP (Access Point)
Pingback: Portable OS - Your pocket operating systems - TopX
Pingback: ESP8266 Parsing JSON - IoTbyHVM - Bits & Bytes of IoT
Pingback: Blynk Tutorials | Blynk IoT Platform | How To use Blynk
Pingback: espcom_sync_failed [ERROR Solved] - IoTbyHVM - Bits & Bytes of IoT
Pingback: Interface LDR module with NodeMCU - IoTbyHVM - Bits & Bytes of IoT
Pingback: Interface MQ135 (Gas Sensor) with NodeMCU - IoTbyHVM
Pingback: Top 10 IoT Cloud Platforms - CompileIoT
Pingback: Arduino IDE | Arduino | Open Source Hardware/Softawre | Arduino Vs RPi
Pingback: Android Things - OS for IoT and embedded devices - IoTbyHVM - Bits & Bytes of IoT
Pingback: InfluxDB | Time Series Database ? | TickStack | Tickscript ?