Landslide monitoring and prediction — ESP32 simulation

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

Components

Sketch code

#include <Wire.h>
#include <RTClib.h>

RTC_DS1307 rtc;

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

#define PZ1_PIN   34       // Piezometer at 1 m
#define PZ3_PIN   35       // Piezometer at 3 m
#define INCL_PIN  32       // Inclinometer proxy


// =====================================================
// ADC CONFIGURATION
// =====================================================

const float VS = 3.3f;
const float ADC_MAX = 4095.0f;


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

const unsigned long SAMPLE_INTERVAL_SECONDS = 30;


// =====================================================
// TIME-SERIES STORAGE
// =====================================================

#define MAX_RECORDS 200

struct DataRecord
{
  String mode;
  String timestamp;

  unsigned long sec;

  float pz1;
  float pz3;
  float inclination;
};

DataRecord records[MAX_RECORDS];

int recordCount = 0;


// =====================================================
// RTC TIMER
// =====================================================

unsigned long lastSampleTime = 0;

bool firstReading = true;


// =====================================================
// SETUP
// =====================================================

void setup()
{
  Serial.begin(115200);

  delay(1000);

  Serial.println();
  Serial.println("======================================");
  Serial.println(" NODE 2 - LANDSLIDE MONITORING");
  Serial.println("======================================");

  Serial.println("PZ1 = 1 meter depth");
  Serial.println("PZ3 = 3 meter depth");
  Serial.println("INCL = Inclinometer");
  Serial.println();


  // =================================================
  // ADC
  // =================================================

  analogReadResolution(12);

  pinMode(PZ1_PIN, INPUT);
  pinMode(PZ3_PIN, INPUT);
  pinMode(INCL_PIN, INPUT);


  // =================================================
  // I2C
  // =================================================

  Wire.begin(21, 22);


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

  if (!rtc.begin())
  {
    Serial.println("ERROR: DS1307 RTC NOT FOUND!");

    while (1)
    {
      delay(1000);
    }
  }


  // =================================================
  // INITIAL RTC TIME
  // =================================================

  if (!rtc.isrunning())
  {
    Serial.println("RTC was not running.");
    Serial.println("Setting initial RTC time...");

    rtc.adjust(
      DateTime(
        2026,
        9,
        14,
        12,
        0,
        0
      )
    );
  }


  Serial.println();
  Serial.println("RTC READY");
  Serial.println();


  // =================================================
  // COMMANDS
  // =================================================

  Serial.println("Commands:");
 

More projects by pjnit