ESPTutorials/DIY

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

  1. Flash Espruino Firmware
  2. 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

  1. The ESP8266/ESP32 connects to a WiFi network.
  2. It reads temperature and humidity data from the DHT11 sensor.
  3. The data is served on a web page via an HTTP server.
  4. You can access the web page from any device on the same network.

Testing the Project

  1. Power on the ESP8266/ESP32 and open the Espruino Web IDE.
  2. Upload the code and check the console for the device’s IP address.
  3. Open a web browser and enter http://<device-ip>.
  4. 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:

Espruino: JavaScript on Microcontrollers

Using JavaScript with NodeMCU: A Comprehensive Guide

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *