Translate

Kendali Pagar MANUAL / OTOMATIS via Sensor PIR dan IOT BLYNK 2.0

Kendali Pagar MANUAL / OTOMATIS via Sensor PIR dan IOT BLYNK 2.0


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengendalikan sebuah pintu pagar dengan 2 mode yaitu manual dan otomatis. untuk cara manual yaitu dengan menggunakan fitur IOT blynk yang terdapat 2 buah tombol untuk kendalinya sedangkan untuk fitur otomatis yaitu buka tutup pagar dengan menggunakan sensor PIR. untuk lebih jelasnya berikut adalah koding dan skemanya.



a. Skema

Sumber: 
https://projectiot123.com/product/ibt2-bts7960b-bts7960-43a-h-bridge-motor-driver-in-pakistan/




b. Program Arduino IDE

#define BLYNK_TEMPLATE_ID "TMPL6wOC--xxx"
#define BLYNK_TEMPLATE_NAME "monitor daya"
#define BLYNK_AUTH_TOKEN "VOK0cWiFN5ycHj3SV_snEDXTfTfeixxx"
#define BLYNK_PRINT Serial  

#define  BLYNK_PRINT Serial  
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);

//int buzzer = D3;
int sw1 = D7;
int sw2 = D3;
int sw1x = 0;
int sw2x = 0;

int pwm1 = D5;
int pwm2 = D6;
int mark = 0;
int pinValue;
int pinValue2;
int sensorpir;
int tanda;

BlynkTimer timer;

char ssid[] = "hotspothpku";
char pass[] = "12345678";

BLYNK_WRITE(V0)
{
  pinValue = param.asInt();   

  if((pinValue == 1)&&(tanda == 1)){
    lcd.clear();
    bukapagarx();
  }
  
  if((pinValue == 0)&&(tanda == 1)) {
     lcd.clear(); 
    tutuppagarx(); 
  }
  
//  Serial.print("button value is: "); 
//  Serial.println(pinValue);
}

BLYNK_WRITE(V1)
{
  pinValue2 = param.asInt();   

  if(pinValue2 == 1){
    tanda = 1;
  }
  
  if(pinValue2 == 0) {
    tanda = 0;
  }

}

void sendSensor()
 delay(100);
}

void setup() {
  // put your setup code here, to run once:
  lcd.begin();
  lcd.clear();
  lcd.noCursor();

  //pinMode(buzzer,OUTPUT);
  //digitalWrite(buzzer,LOW);
  pinMode(sw1,INPUT_PULLUP);
  pinMode(sw2,INPUT_PULLUP);

  pinMode(pwm1,OUTPUT);
  pinMode(pwm2,OUTPUT);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(1000L, sendSensor);
}

void loop() {

sensorpir = analogRead(A0);
sw1x = digitalRead(sw1);
sw2x = digitalRead(sw2);

  lcd.setCursor(0,0);
  lcd.print("SW1= ");
  lcd.print(sw1x);
  lcd.print("  SW2= ");
  lcd.print(sw2x);

  lcd.setCursor(0,1);
  lcd.print("PIR= ");
  lcd.print(sensorpir);
  lcd.print("  ");
  lcd.print(tanda);
  
//buka pagar
if((sensorpir >= 100)&&(mark == 0)&&(tanda == 0)){
 lcd.clear(); 
 bukapagar(); 
 delay(5000); 
}

//tutup pagar
if((sensorpir < 100)&&(mark == 1)&&(tanda == 0)){
 lcd.clear(); 
 tutuppagar();  
}

  Blynk.run();
  timer.run();
  delay(200);  
}

void bukapagar(){
lcd.setCursor(0,1);
lcd.print("BUKA    ");

analogWrite(pwm1,100);  
analogWrite(pwm2,0);  

sw1x = digitalRead(sw1);

if(sw1x == 1){
analogWrite(pwm1,0);  
analogWrite(pwm2,0);
mark = 1;
lcd.clear(); 
return; 
}
  
bukapagar();  
}

void tutuppagar(){
lcd.setCursor(0,1);
lcd.print("TUTUP  ");
  
analogWrite(pwm1,0);  
analogWrite(pwm2,100);  

sw2x = digitalRead(sw2);

if(sw2x == 1){
analogWrite(pwm1,0);  
analogWrite(pwm2,0);
mark = 0;
//digitalWrite(buzzer,HIGH);
//delay(3000);
//digitalWrite(buzzer,LOW);
lcd.clear(); 
return; 
}
  
tutuppagar();  
}

void bukapagarx(){
lcd.setCursor(0,1);
lcd.print("BUKA    ");

analogWrite(pwm1,100);  
analogWrite(pwm2,0);  

sw1x = digitalRead(sw1);

if(sw1x == 1){
analogWrite(pwm1,0);  
analogWrite(pwm2,0);
lcd.clear(); 
return; 
}
  
bukapagarx();  
}

void tutuppagarx(){
lcd.setCursor(0,1);
lcd.print("TUTUP  ");
  
analogWrite(pwm1,0);  
analogWrite(pwm2,100);  

sw2x = digitalRead(sw2);

if(sw2x == 1){
analogWrite(pwm1,0);  
analogWrite(pwm2,0);
//digitalWrite(buzzer,HIGH);
//delay(3000);
//digitalWrite(buzzer,LOW);
lcd.clear(); 
return; 
}
  
tutuppagarx();  
}



c. Interface IOT BLYNK


d. VIDEO HASILNYA





No comments:

Post a Comment