Meshtastic Environmental Monitor

Meshtastic Environmental Sensor Network Project

Heltec WiFi LoRa 32 + Multiple Sensors

Project Overview

Build a mesh network of environmental monitoring nodes that collect sensor data and share it across the network. Each node can read sensors and display/transmit data to other nodes in the mesh.

Hardware Required

Per Node:

  • Heltec WiFi LoRa 32 V3 (or V2)
  • DHT22 Temperature/Humidity Sensor
  • BMP280 Barometric Pressure Sensor (I2C)
  • Light Dependent Resistor (LDR)
  • 10kΩ resistor (for LDR)
  • Jumper wires
  • Breadboard
  • LiPo battery (optional for portable operation)
  • Micro/USB-C cable

Pin Connections

DHT22 Temperature/Humidity Sensor

  • VCC → 3.3V
  • GND → GND
  • Data → GPIO 13

BMP280 Pressure Sensor (I2C)

  • VCC → 3.3V
  • GND → GND
  • SDA → GPIO 21
  • SCL → GPIO 22

LDR Light Sensor

  • One leg → 3.3V
  • Other leg → GPIO 37 (ADC) and 10kΩ resistor to GND

Built-in Components (No wiring needed)

  • LoRa Radio (SX1276)
  • OLED Display (128x64)
  • WiFi/Bluetooth (ESP32)

Software Setup

Step 1: Flash Meshtastic Firmware

  1. Go to https://flasher.meshtastic.org/
  2. Connect Heltec board via USB
  3. Select "Heltec WiFi LoRa 32 V3" (or your version)
  4. Flash the firmware
  5. Configure via Meshtastic app

Step 2: Custom Sensor Code

#include <WiFi.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_BMP280.h>
#include <DHT.h>
#include <ArduinoJson.h>

// Pin definitions
#define DHT_PIN 13
#define DHT_TYPE DHT22
#define LDR_PIN 37
#define OLED_SDA 4
#define OLED_SCL 15
#define OLED_RST 16

// Sensor objects
DHT dht(DHT_PIN, DHT_TYPE);
Adafruit_BMP280 bmp;
Adafruit_SSD1306 display(128, 64, &Wire, OLED_RST);

// Data structure
struct SensorData {
  float temperature;
  float humidity;
  float pressure;
  int lightLevel;
  String nodeId;
  unsigned long timestamp;
};

void setup() {
  Serial.begin(115200);
  
  // Initialize I2C for OLED and BMP280
  Wire.begin(OLED_SDA, OLED_SCL);
  
  // Initialize sensors
  dht.begin();
  
  if (!bmp.begin(0x76)) {
    Serial.println("BMP280 not found!");
  }
  
  // Initialize OLED
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c)) {
    Serial.println("OLED not found!");
  }
  
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println("Sensor Node Starting");
  display.display();
  delay(2000);
}

void loop() {
  // Read sensors
  SensorData data = readSensors();
  
  // Display on OLED
  displaySensorData(data);
  
  // Send via Meshtastic (JSON format)
  sendMeshtasticMessage(data);
  
  delay(30000); // Send every 30 seconds
}

SensorData readSensors() {
  SensorData data;
  
  // Read DHT22
  data.temperature = dht.readTemperature();
  data.humidity = dht.readHumidity();
  
  // Read BMP280
  data.pressure = bmp.readPressure() / 100.0; // Convert to hPa
  
  // Read LDR
  int rawLight = analogRead(LDR_PIN);
  data.lightLevel = map(rawLight, 0, 4095, 0, 100);
  
  // Add metadata
  data.nodeId = WiFi.macAddress();
  data.timestamp = millis();
  
  return data;
}

void displaySensorData(SensorData data) {
  display.clearDisplay();
  display.setCursor(0, 0);
  
  display.println("SENSOR NODE");
  display.println("------------");
  display.print("Temp: ");
  display.print(data.temperature, 1);
  display.println("C");
  
  display.print("Humid: ");
  display.print(data.humidity, 1);
  display.println("%");
  
  display.print("Press: ");
  display.print(data.pressure, 1);
  display.println(" hPa");
  
  display.print("Light: ");
  display.print(data.lightLevel);
  display.println("%");
  
  display.display();
}

void sendMeshtasticMessage(SensorData data) {
  // Create JSON message
  StaticJsonDocument<200> doc;
  doc["node"] = data.nodeId;
  doc["temp"] = data.temperature;
  doc["humid"] = data.humidity;
  doc["press"] = data.pressure;
  doc["light"] = data.lightLevel;
  doc["time"] = data.timestamp;
  
  String jsonString;
  serializeJson(doc, jsonString);
  
  // Send via Serial to Meshtastic (if using custom firmware)
  Serial.println("SENSOR_DATA:" + jsonString);
}

Project Extensions

1. Data Logging

  • Add SD card module to log sensor data
  • Store data with timestamps for analysis

2. Alerting System

  • Set thresholds for temperature, humidity, etc.
  • Send alert messages when limits exceeded

3. Web Dashboard

  • Create simple web server on one node
  • Display real-time data from all nodes in network

4. GPS Integration

  • Add GPS module for location data
  • Create mobile environmental monitoring stations

5. Power Management

  • Implement deep sleep between readings
  • Solar charging for outdoor deployment

Learning Objectives

Technical Skills

  • Mesh Networking: Understanding decentralized communication
  • Sensor Integration: Multiple sensor types and protocols
  • Data Serialization: JSON formatting for transmission
  • Display Programming: OLED graphics and text
  • Power Management: Battery operation considerations

Network Concepts

  • Mesh Topology: How messages route through network
  • Data Redundancy: Multiple paths for reliability
  • Range Testing: Understanding LoRa propagation
  • Network Scaling: Adding/removing nodes dynamically

Experiments to Try

1. Range Testing

  • Deploy nodes at increasing distances
  • Measure packet success rates
  • Map coverage area

2. Network Resilience

  • Remove nodes and observe mesh healing
  • Test message routing through intermediary nodes

3. Data Analysis

  • Collect environmental data over time
  • Compare readings from different locations
  • Identify patterns and anomalies

4. Performance Optimization

  • Adjust transmission intervals
  • Optimize message size
  • Balance battery life vs data frequency

Assessment Ideas

  • Students document network topology
  • Compare sensor readings between nodes
  • Analyze message routing efficiency
  • Design custom sensor integrations
  • Present findings on mesh network behavior

Safety Notes

  • Use appropriate voltage levels (3.3V for most sensors)
  • Double-check wiring before powering on
  • Handle LiPo batteries safely
  • Follow local regulations for LoRa frequency usage

This project combines practical electronics, networking concepts, and real-world data collection while demonstrating the power of mesh networks for IoT applications.