admin@medantechno.com
0852 0 7117 555
medantechno.com
Loading...... Refresh
Loading Slide Show...
08 Februari 2017

Arduino driver motor L293D diy

Kali ini kita akan buat Arduino driver motor L293D diy.

Alat dan bahan yang dibutuhkan : 

  1. PCB bolong
  2. IC L293D 
  3. kabel jumper

Skema :

Breadboard

On Project

 

Code Arduino:


//Created by medantechno.com

#include <Servo.h> 
// --------------------------------------------------------------------------- Motors
int motor_left[] = {2, 3};
int motor_right[] = {4, 5};
int event;
int lampu_mundur = 6;
int lampu_maju   = 7;

Servo myservo; 
int pos = 90; 


// --------------------------------------------------------------------------- Setup
void setup() 
{
  Serial.begin(9600);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object   
  myservo.write(pos); 
  // Setup motors
  int i;
  for(i = 0; i < 2; i++)
  {
    pinMode(motor_left[i], OUTPUT);
    pinMode(motor_right[i], OUTPUT);
  }
  
  pinMode(13, OUTPUT);
  pinMode(lampu_maju, OUTPUT);
  
  

}

// --------------------------------------------------------------------------- Loop
void loop() { 
  
if (Serial.available() > 0) 
{
    kedip();

    event = Serial.read();
    if(event=='N')
    {
      servo_atas();
    }  
    
    if(event=='T')
    {
      servo_turun();
    }  
    
    if(event=='r')
    {
       digitalWrite(lampu_maju,HIGH); 
       Serial.println("lampu on");      
              Serial.println(event);      
    }
    
    if(event=='f')
    {
       digitalWrite(lampu_maju,LOW); 
       Serial.println("lampu off");      
       Serial.println(event);      
    }
    
    if(event=='1')
    {
      drive_forward();
      Serial.println("maju...terus...");      
    }
    
    if(event=='2')
    {
      drive_backward();
      Serial.println("mundur...terus...");      
    }
    
    
    if(event=='3')
    {
      motor_stop();
      Serial.println("stop...");      
    }


    if(event=='4')
    {
      turn_right();
      Serial.println("kanan terus.."); 
    }

    if(event=='5')
    {
      turn_left();
      delay(200);
      Serial.println("kiri terus");  
    }
    


    if(event=='a')
    {
      drive_forward();
      delay(500);
      motor_stop();
      Serial.println("maju...");      
    }
    
    if(event=='A')
    {
      drive_forward();
      delay(1000);
      motor_stop();
      Serial.println("maju lama...");      
    }
    
    
    if(event=='b')
    {
      drive_backward();
      delay(500);
      motor_stop();
      Serial.println("mundur...");      
    }
    
    
    if(event=='B')
    {
      drive_backward();
      delay(1000);
      motor_stop();
      Serial.println("mundur lama...");      
    }
    

    if(event=='c')
    {
      turn_right();
      delay(100);
      motor_stop();
      Serial.println("kanan.."); 
    }

    if(event=='d')
    {
      turn_left();
      delay(100);
      motor_stop();
      Serial.println("kiri");  
    }
    
}
  
  
  
/*
drive_forward();
delay(500);
motor_stop();
Serial.println("1");

drive_backward();
delay(500);
motor_stop();
Serial.println("2");

turn_left();
delay(200);
motor_stop();
Serial.println("3");

turn_right();
delay(200);
motor_stop();
Serial.println("4"); 

motor_stop();
delay(1000);
motor_stop();
Serial.println("5");

*/

}

// --------------------------------------------------------------------------- Drive

void motor_stop(){
digitalWrite(motor_left[0], LOW); 
digitalWrite(motor_left[1], LOW); 

digitalWrite(motor_right[0], LOW); 
digitalWrite(motor_right[1], LOW);
delay(25);
}

void drive_forward(){
digitalWrite(motor_left[0], HIGH); 
digitalWrite(motor_left[1], LOW); 

digitalWrite(motor_right[0], HIGH); 
digitalWrite(motor_right[1], LOW); 
}

void drive_backward(){
digitalWrite(motor_left[0], LOW); 
digitalWrite(motor_left[1], HIGH); 

digitalWrite(motor_right[0], LOW); 
digitalWrite(motor_right[1], HIGH); 
}

void turn_left(){
digitalWrite(motor_left[0], LOW); 
digitalWrite(motor_left[1], HIGH); 

digitalWrite(motor_right[0], HIGH); 
digitalWrite(motor_right[1], LOW);
}

void turn_right(){
digitalWrite(motor_left[0], HIGH); 
digitalWrite(motor_left[1], LOW); 

digitalWrite(motor_right[0], LOW); 
digitalWrite(motor_right[1], HIGH); 
}

void kedip()
{
    digitalWrite(13,HIGH);
    delay(10);  
    digitalWrite(13,LOW);
    delay(10);  
    digitalWrite(13,HIGH);
    delay(10);
    digitalWrite(13,LOW);      
}

void servo_atas()
{
  
  if(pos>=170)
  {
      Serial.println(pos);     
      Serial.println("Mentok Up"); 
  }else{
    pos += 5;
    myservo.write(pos); 
    Serial.println(pos); 

  }

}

void servo_turun()
{
   if(pos<=5)
  {
      Serial.println(pos);     
      Serial.println("Mentok turun"); 
  }else{
    pos -= 5;
    myservo.write(pos); 
    Serial.println(pos); 

  }
}

 




Artikel Lainnya


Portofolio

  • Agenda
  • Date Title
    15 Februari 2017 Parking Gate Job
    13 September 2016 Finishing pay-inm.co.id
    14 September 2016 Finishing Company Profil Masjid Al-iklas Medan


Share...

  • Partner