0

$USD

$USD
PROJECTS IoTArduinoESP8266

Landslide Detector Based on Internet of Things

DFRobot Jan 02 2020 1605

This project can detect both possible and actual landslides, and send an alert to all those who are connected.

Things used in this project

Hardware components

Arduino UNO & Genuino UNO ×2

NodeMCU ESP8266 Breakout Board ×1

SparkFun Soil Moisture Sensor (with Screw Terminals) ×1

Seeed Grove - Vibration Sensor (SW-420) ×1

SparkFun Ultrasonic Sensor - HC-SR04 ×1

Adafruit Standard LCD - 16x2 White on Blue ×1

HC-12 SI4463 ×2

DFRobot I2C 16x2 Arduino LCD Display Module ×1

Buzzer ×1


Software apps and online services
Blynk

Story

To join an Internet of Things National Competition in Indonesia, i with my team looking for a solution using the Internet of Things. Then we decided to make this thing, a landslide detector based on the IoT.

We are using Blynk in this project to connect between this detector and an Android device

In this project, I used at least two devices.

The first device is an Arduino Uno R3 that will gather the data from all sensor reading. Then all the data will be sent to the second device using an HC-12 module.

The second set of devices that I used was a NodeMCU ESP8266 and Arduino Nano. This setup will receive the data from the first device using HC-12 module controlled by Arduino Nano, and the received data sent by Arduino Uno to NodeMCU trough Serial communication. Then the data that receive by NodeMCU will be sent to Blynk database from WiFi network that can be accessed with us.

Why use Arduino Uno, not directly connect HC-12 to NodeMCU ESP8266?

Since our team got a trouble when using HC-12 with NodeMCU, and we decided to try to transit the data first to Arduino Uno and send it to NodeMCU via serial communication, and the good news is it works. At least it solve our problem.

I hope this project helps you. If you have any suggestion or better solution for our problem, send it on the comment space. Happy learning!


Schematics


Code

Arduino 1 | First Device Arduino

//HC-12 Library
#include <SoftwareSerial.h>
SoftwareSerial HC12(10,11); //hc12 tx, hc12 rx

//Ultrasonic Sensor
const int trigPin = 4;
const int echoPin = 5;
long duration;
int distanceCm;

//Vibrate Sensor
int vib = 6;
int val;
int getar = 0;

void setup()
{
  //All Device Begin
  Serial.begin(9600);
  HC12.begin(9600);

  //Ultrasonic pin configuration
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  //Soil Moisture + Vibrate Sensor pin Confuguration
  pinMode(A0, INPUT);
  pinMode (vib, INPUT);
}

void loop()
{
  float sensorValue = analogRead(A0);
  float persen=((1024-sensorValue)/1024)*100;
  Serial.println(persen);
  HC12.println(persen);
  delay(500);
  
  distanceCm= duration*0.034/2;

  int getar= digitalRead(vib);  

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  
//aman dan waspada
  if (getar == 1 && distanceCm >= 5)
  {
    if (persen >= 0 && persen <= 85)
    {
      Serial.println("Aman"); 
      HC12.println(1100); //aman
      delay(500);
    }
    else if (persen >= 85 && persen <= 90)
    {
      Serial.println("Waspada");
      HC12.println(1110); //waspada
      delay(500);
    }
    else if (persen >= 90 && persen <= 100)
    {
      Serial.println("Bahaya");
      HC12.println(1101); //waspada
      delay(500);
    }
  }
//bahaya
  else if (getar == 0 && distanceCm <= 5 )
  {
    if (persen >= 0 && persen <= 100)
    {
      Serial.println("Bahaya");
      HC12.println(1101); //bahaya
      delay(500);
    }
  }

  else if (distanceCm <= 5)
  {
    Serial.println("Bahaya");
    HC12.println(1101);
    delay(500);
  }
  delay(100);  
} 


Arduino 2 | Second Device Arduino

#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2);
SoftwareSerial HC12(10, 11); // HC-12 TX Pin, HC-12 RX Pin

int O_aman = 7;
int O_waspada = 8;
int O_bahaya = 9;
int buzzer = 12;

void setup(){
  Serial.begin(9600);
  HC12.begin(9600);
  pinMode(buzzer, OUTPUT);
  pinMode(O_aman, OUTPUT);
  pinMode(O_waspada, OUTPUT);
  pinMode(O_bahaya, OUTPUT);
  lcd.begin();
  lcd.setCursor(0,0);
  lcd.print("     SISTEM");
  lcd.setCursor(0,1);
  lcd.print("   PERINGATAN");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" BAHAYA LONGSOR");
  lcd.setCursor(0,1);
  lcd.print("    POLINEMA");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("SCANNING");
  delay(500);
  lcd.setCursor(0,0);
  lcd.print("SCANNING.");
  delay(500);
  lcd.setCursor(0,0);
  lcd.print("SCANNING..");
  delay(500);
  lcd.setCursor(0,0);
  lcd.print("SCANNING...");
  delay(500);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("SCANNING.");
  delay(500);
  lcd.setCursor(0,0);
  lcd.print("SCANNING..");
  delay(500);
  lcd.setCursor(0,0);
  lcd.print("SCANNING...");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,0);  
}

void loop() {
  if(HC12.available() >1){
    int input = HC12.parseInt();
    //float soil = HC12.read();
   
    //aman
    if(input == 1100)
    {
      Serial.println("2");
      lcd.clear();
      lcd.print("STATUS : AMAN");
      delay(1000);
    }
    else 
    {
      Serial.println("1");
    }
    //waspada
    if(input == 1110)
    {
      Serial.println("4");
      lcd.clear();
      lcd.print("STATUS : WASPADA");
      digitalWrite(buzzer, HIGH);
      delay(200);
      lcd.clear();
      lcd.print("STATUS : WASPADA");
      digitalWrite(buzzer, LOW);
      delay(200);
    }
    else 
    {
      Serial.println("3");
    }
    //bahaya
    if(input == 1101)
    { 
      Serial.println("6");
      lcd.clear();
      lcd.print("STATUS : BAHAYA");
      digitalWrite(buzzer, HIGH);
      delay(500);
      lcd.clear();
      lcd.print("STATUS : BAHAYA");
      digitalWrite(buzzer, LOW);
      delay(500);
    }
    else 
    {
      Serial.println("5");
    }
  }
  HC12.flush();
  delay(20);
}


NodeMCU | Second Device Arduino

//Blynk Library
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
 
//Blynk Timer Configuration
BlynkTimer timer;

//LED pin definition
#define led_aman 4 //D2
#define led_waspada 0 //D3
#define led_bahaya 2 //D4

#define BLYNK_PRINT Serial

//Wifi Configuration
char auth[] = "XXXXXXXXXXXXXXXX"; //Blynk Auth
char ssid[] = "XXXXXXXXXXXXXXXX"; //Wifi SSID
char pass[] = "XXXXXXXXXXXXXXXX"; //Wifi Pass
int flag=0;

//LED Widget Configuration
WidgetLED led1(V1); //aman
WidgetLED led2(V2); //waspada
WidgetLED led3(V3); //bahaya

void setup() 
{
  //All Device begin
  Blynk.begin(auth, ssid, pass);
  Serial.begin(9600);
  Blynk.run();
  timer.run();
  pinMode(led_aman,OUTPUT);
  pinMode(led_waspada,OUTPUT);
  pinMode(led_bahaya,OUTPUT);
}

void loop() 
{
  if(Serial.available()>0)
  {
    int data = Serial.read();
      if(data=='1')
        {
          digitalWrite(led_aman,LOW);
          led1.off();
          delay(500);
        }
      else if(data=='2')
        {
          digitalWrite(led_aman,HIGH);
          led1.on();
          delay(500);
        }
      else if(data=='3')
        {
          digitalWrite(led_waspada,LOW);
          led2.off();
          delay(500);
        }
      else if(data=='4')
        {
          digitalWrite(led_waspada,HIGH);
          led2.on();
          delay(500);
          Blynk.notify("Kondisi Waspada");
        }
       else if(data=='5')
        {
          digitalWrite(led_bahaya,LOW);
          led3.off();
          delay(500);
        }
        else if(data=='6')
        {
          digitalWrite(led_bahaya,HIGH);
          led3.on();
          delay(1000);
          Blynk.notify("Kondisi Bahaya");
        }
  }
}