Teknik Elektronika Industri SMK Negeri 1 Bandar Masilam

L298N H-Bridge Arduino 4WD

L298N H-Bridge Arduino 4WD

Alat dan Bahan yang dibutuhkan :

1x Arduino Uno

1x Motor Driver L298N

4x Motor DC (Sebagai Roda)

1x Battery +9V for Motor L298N

1x Battery +9V for Arduino UNO

Kabel jumper secukupnya

Langkah-langkahnya :


1.    1.  Susun rangkaian seperti gambar berikut :


Keterangan Konfigurasi Kabel :

·         Hubungkan Pin IN1 L298N ke Pin 7 Arduino

·         Hubungkan Pin IN2 L298N ke Pin 6 Arduino

·         Hubungkan Pin IN3 L298N ke Pin 5 Arduino

·         Hubungkan Pin IN4 L298N ke Pin 4 Arduino

·         Solder Pin Motor DC (Contoh lihat pada Gambar diatas)

·         Hubungkan +12V Motor Driver L298N ke +9V Battery

·         Hubungkan Ground Motor Driver L298N ke Battery dan Ke Pin Ground Arduino

1.      2. Jalankan program Arduino-nya.

2.      3. Klik menu "Tools -> Board -> Arduino Uno"

3.      4. Klik menu "Tools -> Port -> ( Pilih Port arduino yang terdeteksi di komputer anda )

4.      5. Lalu masukan Sketch dibawah ini.


// Right side motor control
const int L298N_IN1=7;
const int L298N_IN2=6;

// Left side motor control
const int L298N_IN3=5;
const int L298N_IN4=4;

void setup(){
  pinMode(L298N_IN1,OUTPUT);
  pinMode(L298N_IN2,OUTPUT);
  pinMode(L298N_IN3,OUTPUT);
  pinMode(L298N_IN4,OUTPUT);
}

void loop(){
  startCar();
  delay(1000);
  startCar();
  delay(1000);
  leftTurn();
  delay(1000);
  rightTurn();
  delay(1000);
}
//Mechatronic and Robotic
//Electrical Engineering
//Malikussaleh of University
void startCar()
{
  digitalWrite(L298N_IN1,HIGH);
  digitalWrite(L298N_IN2,LOW);
  digitalWrite(L298N_IN3,HIGH);
  digitalWrite(L298N_IN4,LOW);
}

void stopCar()
{
  digitalWrite(L298N_IN1,LOW);
  digitalWrite(L298N_IN2,LOW);
  digitalWrite(L298N_IN3,LOW);
  digitalWrite(L298N_IN4,LOW);
}

void leftTurn()
{
  digitalWrite(L298N_IN1,LOW);
  digitalWrite(L298N_IN2,HIGH);
  digitalWrite(L298N_IN3,HIGH);
  digitalWrite(L298N_IN4,LOW);
}

void rightTurn()
{
  digitalWrite(L298N_IN1,HIGH);
  digitalWrite(L298N_IN2,LOW);
  digitalWrite(L298N_IN3,LOW);
  digitalWrite(L298N_IN4,HIGH);
}





How To Build An Obstacle Avoiding Robot

How To Build An Obstacle Avoiding Robot

Alat dan Bahan yang dibutuhkan :

1x Arduino Uno

1x Ultra Sonic Sensor

1x Motor Driver L298N

4x Motor DC (Sebagai Roda)

1x Battery +9V for Motor L298N

1x Battery +9V for Arduino UNO

Kabel jumper secukupnya

Langkah-langkahnya :

1.      Susun rangkaian seperti gambar berikut :


Keterangan Konfigurasi Kabel :

·         Hubungkan Pin Vcc Ultrasonic Sensor ke Pin +5V Arduino

·         Hubungkan Pin Echo Ultrasonic Sensor ke Pin 3 Arduino

·         Hubungkan Pin Trigger Ultrasonic Sensor ke Pin 2 Arduino

·         Hubungkan Pin Ground Ultrasonic Sensor ke Pin Ground Arduino

·         Hubungkan Pin IN1 L298N ke Pin 7 Arduino

·         Hubungkan Pin IN2 L298N ke Pin 6 Arduino

·         Hubungkan Pin IN3 L298N ke Pin 5 Arduino

·         Hubungkan Pin IN4 L298N ke Pin 4 Arduino

·         Solder Pin Motor DC (Contoh lihat pada Gambar diatas)

·         Hubungkan +12V Motor Driver L298N ke +9V Battery

·         Hubungkan Ground Motor Driver L298N ke Battery dan Ke Pin Ground Arduino

1.      Jalankan program Arduino-nya.

2.      Klik menu "Tools -> Board -> Arduino Uno"

3.      Klik menu "Tools -> Port -> ( Pilih Port arduino yang terdeteksi di komputer anda )

4.      Lalu masukan Sketch dibawah ini.

#include <NewPing.h>

#define TRIGGER_PIN  2  // Arduino pin tied to trigger pin on ping censor(CENTER censor)
#define ECHO_PIN     3 // Arduino pin tied to echo pin on ping censor(CENTER censor)
#define MAX_DISTANCE 200
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
unsigned int pingSpeed = 50;
unsigned long pingTimer;     // Holds the next ping time.
int distance;
int distanceL;
int distanceR;

//MotorSetting; Using DFRobot L298 2A Motor Controller

int M1 = 4;
int E1 = 5;
int M2 = 7;
int E2 = 6;
int pwm_speed;
int speedVal = 255;
//char command = '\0';

void setup() {
  Serial.begin(9600); // Open serial monitor at 9600 baud to see ping results.

  pinMode(M1, OUTPUT);
  pinMode(M2, OUTPUT);
  pinMode(10, OUTPUT);
  delay(250);
}

void loop() {
      distance  = sonar.ping_cm();
      Serial.println(distance);
      if (distance > 25){
        Drive("Forward");
        Serial.println("maju");
      }
      else if (distance < 25 && distance > 10)
      {
          Drive("TurnRight");
          delay(250);
          Drive("Stop");
          distanceR = sonar.ping_cm();
          Drive("TurnLeft");
          delay (250);
          Drive ("Stop");
          distanceL = sonar.ping_cm();
            if (distanceR > distanceL) {
              Drive ("TurnRight");
              Serial.println("kanan");
              delay (250);
              Drive ("Forward");
             
            }
            else {
              Drive ("TurnLeft");
              Serial.println("kiri");
              delay (250);
              Drive ("Forward");
            }
     }
     else {
        Drive ("Backward");
        Serial.println("mundur");
        delay (100);
        Drive ("Stop");
     }
}
//Mechatronic and Robotic//
//Electrical Engineering//
//Malikussaleh of University//


/////////////////Directions Setup/////////////////////////
void Drive(String Direction) {
  if (Direction == "Backward") {
    // Serial.println("Backward");
    analogWrite(E1, 255);
    analogWrite(E2, 255);
    digitalWrite(M1, LOW);
    digitalWrite(M2, LOW);
  }
  if (Direction == "Forward") {
    // Serial.print("Forward");
    analogWrite(E1, 255);
    analogWrite(E2, 255);
    digitalWrite(M1, HIGH);
    digitalWrite(M2, HIGH);
   
  }

  if (Direction == "Stop") {
    //Serial.print("Stop");
    analogWrite(E1, 0);
    analogWrite(E2, 0);
  }

  if (Direction == "TurnRight") {
    //Serial.print("Turning Right");
    analogWrite(E1, 255);
    analogWrite(E2, 255);
    digitalWrite(M1, LOW);
    digitalWrite(M2, HIGH);
  }

  if (Direction == "TurnLeft") {
    // Serial.print("Turning Left");
    analogWrite(E1, 255);
    analogWrite(E2, 255);
    digitalWrite(M1, HIGH);
    digitalWrite(M2, LOW);
  }
}

void test_speed() {
  // constrain speed value to between 0-255
  if (speedVal > 250) {
    speedVal = 255;
    Serial.println(" MAX ");
  }
  if (speedVal < 0) {
    speedVal = 0;
    Serial.println(" MIN ");
  }
}
//--------------------------------------
/*
long microsecondsToCentimeters(long microseconds) {
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  //return microseconds / 29 / 2;
  return microseconds / 10; //basically 58
}*/
/////////////////////////////////////////////////////////////////////////

Menampilkan Teks pada LCD 16x2 di Arduino (How to Control LCD Display)

Menampilkan Teks pada LCD 16x2 di Arduino (How to Control LCD Display)

Menampilkan Teks pada LCD 16x2 di Arduino (How to Control LCD Display)

Alat dan Bahan yang dibutuhkan :
1x Arduino Uno
1x LCD 16x2
1x Potensiometer
1x Breadboard
Kabel jumper secukupnya
Langkah-langkahnya :

1.    1.     Susun rangkaian seperti gambar berikut pada breadboard




Keterangan Konfigurasi Kabel :
·         Hubungkan pin D7 LCD ke pin 2 Arduino
·         Hubungkan pin D6 LCD ke pin 3 Arduino
·         Hubungkan pin D5 LCD ke pin 4 Arduino
·         Hubungkan pin D4 LCD ke pin 5 Arduino
·         Hubungkan pin E LCD ke pin 11 Arduino
·         Hubungkan pin RW LCD ke Ground
·         Hubungkan pin RS LCD ke pin 12 Arduino
·         Hubungkan pin VDD(+) LCD ke +5v Arduino
·         Hubungkan pin VSS(-) LCD ke Ground
·         Hubungkan kaki 1 Potensiometer ke +5v Arduino
·         Hubungkan kaki 2 Potensiometer ke V0 LCD
·         Hubungkan kaki 3 Potensiometer ke Ground
2.      Jalankan program Arduino-nya.
3.      Klik menu "Tools -> Board -> Arduino Uno"
4.      Klik menu "Tools -> Port -> ( Pilih Port arduino yang terdeteksi di komputer anda )
5.      Lalu masukan Sketch dibawah ini.


#include <LiquidCrystal.h>

LiquidCrystal lcd (12, 11, 5, 4, 3, 2);

void setup()
{
  lcd.begin(16, 2);
  lcd.clear();
}

void loop()
{
  lcd.print("Welcome");
  delay (6000);


  lcd.setCursor(1, 2);
  lcd.print ("Engineer");
  delay (6000);

  lcd.clear();
  lcd.print ("Arduino");
  lcd.blink();
  delay (9000);


  //Mechatronic and Robotic
  //Electrical Engineering
  //University of Malikussaleh


  lcd.noBlink();
  lcd.setCursor(1, 2);
  lcd.print("Programming LCD");
  lcd.cursor();
  delay(1000);

  lcd.clear();
  lcd.print("Way of Life");
  lcd.noCursor();

  delay(3000);

  lcd.setCursor(1, 2);
  lcd.print("Arduino");

  delay(1000);

 

  lcd.clear();
  lcd.print("Play Again");

  delay(3000);
  lcd.clear();

  lcd.display();

  delay(1000);
}

 Semoga Bermanfaat...