Translate

Kendali Pagar / Motor Stepper tomatis berbasis Sensor Jarak / Proximity dan sensor Wireless Key

 Kendali Pagar / Motor Stepper tomatis berbasis Sensor Jarak / Proximity dan sensor Wireless Key

            Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang digunakan untuk buka tutup gerbang atau pintu dengan menggunakan arduino dan motor stepper, alat ini dilengkapi dengan sensor proximity atau jarak dan sensor wireless key. untuk lebih jelasnya berikut koding dan daftar komponennya.


a. Arduino Mega




b. Motor Stepper




c. Sensor No Touch




d. Sensor Wireless Key







e. Program Arduino IDE

#define dirPin 2
#define stepPin 3

#define dir2 4
#define step2 5
int Tbremot = 8;
int gerak  = 7 ;
int tutup = 6;
int remot;
int tombol1;
int tombol2;
int speedx = 100;
int speedxx = 0;
int limsw1 = 9;
int limsw2 = 10;
int button = 11;

int limsw1x = 2;
int limsw2x = 2;
int buttonx;
int tanda;

void setup() {
  // Declare pins as output:
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(step2, OUTPUT);
  pinMode(dir2, OUTPUT);
  pinMode(gerak,INPUT_PULLUP);
  pinMode(tutup,INPUT_PULLUP);
  pinMode(Tbremot,INPUT_PULLUP);
  pinMode(limsw1,INPUT_PULLUP); //hijau
  pinMode(limsw2,INPUT_PULLUP); //biru
  pinMode(button,INPUT_PULLUP);
//  Serial.begin(9600);
 
  // Set the spinning direction CW/CCW:
}
void loop() {

    tombol1 = digitalRead(gerak);
    tombol2 = digitalRead(tutup); 
    buttonx = digitalRead(button);

if(buttonx == 0){
  tanda = 1;
 }  
if(buttonx == 1){
  tanda = 0;
 }
    
//cw
if((tombol1 == 0)&&(tanda == 0)){
  digitalWrite(dirPin, HIGH);
  digitalWrite(dir2, LOW);
  
  digitalWrite(stepPin, HIGH);
  digitalWrite(step2, LOW);
   delayMicroseconds(speedx);
   digitalWrite(stepPin, LOW);
    digitalWrite(step2, HIGH);
    delayMicroseconds(speedx);
}

//ccw
if((tombol2 == 0)&&(tanda == 0)){
  digitalWrite(dirPin, LOW);
  digitalWrite(dir2, HIGH);
  digitalWrite(stepPin, LOW);
  digitalWrite(step2, HIGH);
  delayMicroseconds(speedx);
  digitalWrite(stepPin, HIGH);
  digitalWrite(step2, LOW);
  delayMicroseconds(speedx);
}

remot = digitalRead(Tbremot);
//gerak buka
if((remot == 0)&&(tanda == 1)){
delay(200);
gerakbuka();
}

remot = digitalRead(Tbremot);
//gerak tutup
if((remot == 1)&&(tanda == 1)){
delay(200);  
geraktutup();
}

}

void gerakbuka(){
limsw1x = digitalRead(limsw1);
limsw2x = digitalRead(limsw2);
buttonx = digitalRead(button);

if(buttonx == 0){
  tanda = 1;
}
 
if((limsw1x == 0)&&(limsw2x == 1)){
delay(200);
return;
}

  digitalWrite(dirPin, HIGH);
  digitalWrite(dir2, LOW);
  digitalWrite(stepPin, HIGH);
  digitalWrite(step2, LOW);
  delayMicroseconds(speedx);
  digitalWrite(stepPin, LOW);
  digitalWrite(step2, HIGH);
  delayMicroseconds(speedx);
//  Serial.println("BUKA");
//  Serial.println(remot);
gerakbuka();  
}


void geraktutup(){
limsw1x = digitalRead(limsw1);
limsw2x = digitalRead(limsw2);
buttonx = digitalRead(button);

if(buttonx == 0){
  tanda = 1;
}
 
if((limsw1x == 1)&&(limsw2x == 0)){
delay(200);
return;
}

  digitalWrite(dirPin, LOW);
  digitalWrite(dir2, HIGH);  
  digitalWrite(stepPin, HIGH);
  digitalWrite(step2, LOW);
  delayMicroseconds(speedx);
  digitalWrite(stepPin, LOW);
  digitalWrite(step2, HIGH);
  delayMicroseconds(speedx);
//  Serial.println("TUTUP");
//  Serial.println(remot);
geraktutup();
}




f. VIDEO HASILNYA







No comments:

Post a Comment