//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);
}
#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"); } } }