landslide monitoring and prediction node — ESP32 simulation

An interactive ESP32 circuit simulation you can run free in your browser on Velxio, by pjnit.

Components

Sketch code

/*
=========================================================
 NODE 1 - LANDSLIDE MONITORING SYSTEM
=========================================================

 ESP32 DevKit V1

 DS1307:
   Address = 0x68
   Direct I2C register reading
   Same logic as the tested DS1307 RTC Reader

 Sensors:

   1. Rain Gauge / Signal Generator
      GPIO32

   2. Soil Moisture - 20 cm
      GPIO34

   3. Soil Moisture - 50 cm
      GPIO35

   4. Strain Gauge / FSR402 proxy
      GPIO33

   5. BME280
      I2C

   6. MPU6050
      I2C

   7. DS1307 RTC
      I2C address 0x68

 Sampling:
   First reading = immediately
   Subsequent readings = every 5 minutes

 RTC:
   Direct I2C reading
   No virtual millis() clock
   No RTC library time calculation

 Commands:
   D = Download stored data
   R = Reset stored data
   T = Show RTC time

=========================================================
*/


#include <Wire.h>

#include <Adafruit_BME280.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>


// =====================================================
// DS1307
// =====================================================

#define DS1307_ADDR 0x68


// =====================================================
// SENSOR PINS
// =====================================================

#define RAIN_PIN       32
#define SOIL20_PIN     34
#define SOIL50_PIN     35
#define STRAIN_PIN     33


// =====================================================
// I2C PINS
// =====================================================

// BME280 + MPU6050
#define SENSOR_SDA     21
#define SENSOR_SCL     22


// DS1307
#define RTC_SDA       25
#define RTC_SCL       26


// =====================================================
// SAMPLING
// =====================================================

#define SAMPLE_INTERVAL_SECONDS 300


// =====================================================
// OBJECTS
// =====================================================

Adafruit_BME280 bme;

Adafruit_MPU6050 mpu;


// =====================================================
// SENSOR STATUS
// =====================================================

bool bmeOK = false;
bool mpuOK = false;
bool rtcOK = false;


// =====================================================
// RTC TIME STRUCTURE
// =====================================================

struct RTCDateTime
{
  int second;
  int minute;
  int hour;

  int day;
  int month;
  int year;

  int dayOfWeek;
};


// =====================================================
// DATA STORAGE
// =====================================================

#define MAX_RECORDS 200

String storedData[MAX_RECORDS];

int recordCount = 0;


// =====================================================
// RTC TIMING VARIABLES
// =====================================================

unsigned long lastSampleEpoch = 0;

bool firstReading = true;


// =====================================================
// BCD TO DECIMAL
// =====================================================

byte bcdToDec

More projects by pjnit