Translate

Kendali Motor DC da LED via IOT BLYNK 2.0

Kendali Motor DC da LED via IOT BLYNK 2.0


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengendalikan motor dc dan led dengan menggunakan IOT Blynk 2.0. pada interface Blynk terdapat beberapa tombol switch yang dapat digunakan untuk mengendalikan arah putaran motor dan ON OFF led. untuk lebih jelasnya berikut adalah skema dan kodingnya.


a. Skema

link sumber: https://projectiot123.com/2023/11/22/motor-speed-control-using-ibt-2-and-arduino/




b. Program ESP8266

#define BLYNK_TEMPLATE_ID "TMPL6mWi-xxxx"
#define BLYNK_TEMPLATE_NAME "telur"
#define BLYNK_AUTH_TOKEN "APJjyV28gzQqQTjYaeEj-KUAJF8TAxxx"
#define BLYNK_PRINT Serial  

#include <Wire.h>
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

int led = D1;
int tanda;
int pinValue, pinValue2, pinValue3, pinValue4, pinValue5;
int pwm1 = D6;
int pwm2 = D7;
int pwm3 = D4;
int pwm4 = D5;

BlynkTimer timer;

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

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

  if(pinValue == 1){    
    analogWrite(pwm1,50);  
    analogWrite(pwm2,0); 
  }
  
  if(pinValue == 0) {
    analogWrite(pwm1,0);  
    analogWrite(pwm2,0);  
  }
  
}

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

  if(pinValue2 == 1){
    analogWrite(pwm1,0);  
    analogWrite(pwm2,50); 
  }
  
  if(pinValue2 == 0) {
    analogWrite(pwm1,0);  
    analogWrite(pwm2,0);   
  }

}

BLYNK_WRITE(V2)
{
  pinValue3 = param.asInt();   

  if(pinValue3 == 1){
   digitalWrite(led,HIGH); 
  }
  
  if(pinValue3 == 0) {
   digitalWrite(led,LOW);
  }

}


BLYNK_WRITE(V3)
{
  pinValue4 = param.asInt();   

  if(pinValue4 == 1){    
    analogWrite(pwm3,50);  
    analogWrite(pwm4,0); 
  }
  
  if(pinValue4 == 0) {
    analogWrite(pwm3,0);  
    analogWrite(pwm4,0);  
  }
  
}

BLYNK_WRITE(V4)
{
  pinValue5 = param.asInt();   

  if(pinValue5 == 1){
    analogWrite(pwm3,0);  
    analogWrite(pwm4,50); 
  }
  
  if(pinValue5 == 0) {
    analogWrite(pwm3,0);  
    analogWrite(pwm4,0);   
  }

}

void sendSensor()
 delay(100);
}

void setup() {
  
  pinMode(led,OUTPUT);
  pinMode(pwm1,OUTPUT);
  pinMode(pwm2,OUTPUT);
  pinMode(pwm3,OUTPUT);
  pinMode(pwm4,OUTPUT);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  timer.setInterval(1000L, sendSensor);
}

void loop() {
  Blynk.run();
  timer.run();
  delay(200);  
}



c. VIDEO HASILNYA




No comments:

Post a Comment