Translate

Robot Lengan / ARM dan Monitor Suhu LM35 BLYNK (IOT)

Robot Lengan / ARM dan Monitor Suhu LM35 BLYNK (IOT)


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuat alat yang bisa mengendalikan robot lengan dan juga monitoring suhu via blynk, alat ini menggunakan nodemcu dan arduino sebagai kontrollernya, untuk lebih jelasnya berikut adalah skema dan programnya. 



a. Skema Alat





b. Program Arduino IDE Robot Lengan

#include<Wire.h>
#include<Servo.h>

Servo myservo1;
Servo myservo2;
Servo myservo3;
Servo myservo4;

int a;
int b;
int c;
int d;
int e;
int btset = 6;
int btsetx;

void setup(){
myservo1.attach(7);
myservo2.attach(9);
myservo3.attach(10);
myservo4.attach(11);
pinMode(btset,INPUT_PULLUP);

 myservo1.write(40);
 myservo2.write(60);
 myservo3.write(130);
 myservo4.write(150);
 delay(3000);
}

void loop(){

btsetx = digitalRead(btset);

//memanen
if(btsetx == 0){ 
lepas();  
kanan();  
turun();
maju();
japit();
mundur();
naik();

kiri();  
turun();
maju();
lepas();
mundur();
naik();
}

//menanam
if(btsetx == 1){
japit();
turun();
maju();
mundur();
naik();     
kananx();
turun();
maju();
mundur();
naik();
tengahx();  
turun();
maju();
mundur();
naik();
kirix();
}

}

void kananx(){
  for(a=40;a<=80;a++){
  myservo1.write(a);
  delay(50);
  }
  return;
}

void tengahx(){
  for(a=80;a<=120;a++){
  myservo1.write(a);
  delay(50);
  }
  return;
}

void kirix(){
  for(a=120;a>=40;a--){
  myservo1.write(a);
  delay(50);
  }
  return;
}

void kanan(){
  for(a=40;a<=120;a++){
  myservo1.write(a);
  delay(50);
  }
  return;
}

void kiri(){
  for(a=120;a>=40;a--){
  myservo1.write(a);
  delay(50);
  }
  return;
}

void mundur(){
  for(b=130;b>=60;b--){
  myservo2.write(b);
  delay(50);
  }
  return;
}

void maju(){
  for(b=60;b<=130;b++){
  myservo2.write(b);
  delay(50);
  }
  return;
}

void turun(){
  for(c=130;c>=90;c--){
  myservo3.write(c);
  delay(50);
  }
  return;
}

void naik(){
  for(c=90;c<=130;c++){
  myservo3.write(c);
  delay(50);
  }
  return;
}

void japit(){
  for(e=150;e>=120;e--){
  myservo4.write(e);
  delay(50);
  }
  return;
}

void lepas(){
  for(e=120;e<=150;e++){
  myservo4.write(e);
  delay(50);
  }
  return;
}



c. Program Arduino IDE Monitor Suhu

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
 
    // You should get Auth Token in the Blynk App.
    // Go to the Project Settings (nut icon).
    char auth[] = "gjghgjThghfxfxdaklhhbhjbhhvGHGhjV";
    char ssid[] = "myhotspothp";
    char pass[] = "1234567890";

    int dataadc;
 
    float suhu;
    int tempPin = A0;   //Output lm35 ke A0 dan LED ke pin D4
 
    SimpleTimer timer;
 
    void setup()
    {
      Serial.begin(9600); // See the connection status in Serial Monitor
      Blynk.begin(auth, ssid, pass);
 
      // Setup a function to be called every second
      timer.setInterval(1000L, sendUptime);
    }
 
    // that you define how often to send data to Blynk App.
    void sendUptime()
    {
     // shows the value temp on virtual pin 10
      Blynk.virtualWrite(V6, suhu);
    }
 
    void loop()
    {
      Blynk.run(); // Initiates Blynk
      timer.run(); // Initiates SimpleTimer
   
       dataadc = analogRead(tempPin);
       suhu = dataadc * (3.2 / 1023.0) * 100.0;
   
    }

    

d. VIDEO HASILNYA





No comments:

Post a Comment