Espruino Project: IoT Temperature and Humidity Monitor
Introduction
In this project, we will create an IoT-based Temperature and Humidity Monitor using Espruino, an ESP8266 or ESP32 board, and a DHT11 sensor. The data will be displayed on a web server, allowing real-time monitoring over WiFi.
Components Required
- ESP8266 or ESP32 (with Espruino firmware installed)
- DHT11/DHT22 Temperature & Humidity Sensor
- Jumper Wires
- Breadboard
Wiring Diagram
Connect the components as follows:
DHT11 Pin | ESP8266 Pin |
---|---|
VCC | 3.3V |
GND | GND |
Data | D4 (GPIO2) |
For ESP32, you can use any GPIO pin (e.g., GPIO4).
Setting Up Espruino
- Flash Espruino Firmware
- Follow the installation guide from the Espruino website.
- Connect via Espruino Web IDE
- Open the Web IDE and connect to the board via USB or WiFi.
Writing the Code
Create a new JavaScript file in the Espruino Web IDE and upload the following code:
// Load required modules
var wifi = require("Wifi");
var dht = require("DHT11").connect(D4);
var http = require("http");
// Connect to WiFi
wifi.connect("Your_SSID", {password: "Your_PASSWORD"}, function() {
console.log("Connected to WiFi");
// Start Web Server
http.createServer(function (req, res) {
var temp = dht.read().temp;
var hum = dht.read().rh;
res.writeHead(200, {'Content-Type': 'text/html'});
res.end("<h1>Temperature: " + temp + "°C</h1><h2>Humidity: " + hum + "%</h2>");
}).listen(80);
console.log("Server running at http://" + wifi.getIP().ip);
});
How It Works
- The ESP8266/ESP32 connects to a WiFi network.
- It reads temperature and humidity data from the DHT11 sensor.
- The data is served on a web page via an HTTP server.
- You can access the web page from any device on the same network.
Testing the Project
- Power on the ESP8266/ESP32 and open the Espruino Web IDE.
- Upload the code and check the console for the device’s IP address.
- Open a web browser and enter
http://<device-ip>
. - You should see real-time temperature and humidity readings.
Enhancements
- Add graphical charts using JavaScript (Chart.js) for better visualization.
- Send data to a cloud server (e.g., Firebase, ThingSpeak) for remote monitoring.
- Use an OLED display for local data display.
Conclusion
This Espruino-based IoT project is an excellent way to get started with JavaScript on microcontrollers. It demonstrates how Espruino simplifies embedded development while integrating with web technologies. Let us know if you have any questions or need further improvements!
Read this: