Kamis, 21 Maret 2024

LA M2P4

 



Percobaan 4
Interrupt Arduino - Kontrol Motor Servo dengan PWM

1. Foto Hardware dan Diagram Blok [Kembali]

    
        1. Arduino Uno



        2.Motor Servo


        3. Keypad



Diagram Blok:

2. Prosedur Percobaan  [Kembali]

1. Susun semua elemen perangkat
2. Buatlah sebuah skrip di dalam aplikasi Arduino IDE
3. Setelah selesai, unggulkan skrip ke papan Arduino
4. Aktifkan skrip dalam simulasi dan uji dengan modul yang ada


Rangkaian Simulasi
 


Prinsip Kerja

Pada rangkaian ini, terdapat Arduino Uno, keypad, dan Motor Servo. Arduino digunakan untuk menghubungkan keypad dan servo motor. Saat sebuah tombol pada keypad ditekan, Arduino akan membaca input tersebut dan menentukan sudut yang sesuai untuk motor servo berdasarkan tombol yang ditekan. Misalnya, tombol 1 akan mengatur motor servo pada sudut 0 derajat, tombol 2 pada sudut 45 derajat, dan seterusnya sesuai dengan konfigurasi yang telah ditentukan. Setelah menentukan sudut yang sesuai, Arduino mengirimkan sinyal kontrol ke motor servo, yang kemudian akan berputar ke sudut yang telah ditentukan oleh Arduino.

4. Flowchart dan Listing Program [Kembali]

Flowchart
http://www.plantuml.com/plantuml/png/hPD1IyCm5CVl-HH_JqjlpcswhGm6mvEeO4-UPDYtDInDGl8owRUtPiXw45gmboGyylln9tbl6tZlETPQi69DACYVBNRMiBSQHHEOQY7I9R4kYAEJMIw-AgK9adsaJ030-ets9KxKk7PJnaNEKrqT8DigRZPuUVruUdpFm1KPo8R2XKpqhgBFqmyEvoa4AYzqrx31P3hvaqw6PticX1IUBMvHqj4JXQk7TA2EwswmQxxebSq6orRzoUQ3PTDPVxJ5SDkoFzlzgDaUndosvPWVklfNfvbI7SIl5TBORgTRmyf4WhRMANFCnHLfrpHOOjkUOgs_0G00

Listing Program:
 
#include <Servo.h>
#include <Keypad.h>

Servo servoMotor;
const int servoPin = 11; // PWM pin for servo
const int numRows = 4;    // Number of rows in keypad
const int numCols = 3;    // Number of columns in keypad

char keys[numRows][numCols] = {
    {'1', '2', '3'},
    {'4', '5', '6'},
    {'7', '8', '9'},
    {'*', '0', '#'}
};

byte rowPins[numRows] = {9, 8, 7, 6}; // Rows 0 to 3
byte colPins[numCols] = {5, 4, 3};     // Columns 0 to 2

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, numRows, numCols);

void setup() {
    servoMotor.attach(servoPin);
    servoMotor.write(90); // Initial position
    Serial.begin(9600);
}

void loop() {
    char key = keypad.getKey();
    if (key != NO_KEY) {
        Serial.println(key);
        // Perform actions based on the key pressed
        switch (key) {
            case '1':
                // Move servo to position 0 degrees
                servoMotor.write(0);
                break;
            case '2':
                // Move servo to position 45 degrees
                servoMotor.write(45);
                break;
            case '3':
                // Move servo to position 90 degrees
                servoMotor.write(90);
                break;
            case '4':
                // Move servo to position 135 degrees
                servoMotor.write(135);
                break;
            case '5':
                // Move servo to position 180 degrees
                servoMotor.write(180);
                break;
            case '6':
                // Move servo to position 135 degrees
                servoMotor.write(135);
                break;
            case '7':
                // Move servo to position 90 degrees
                servoMotor.write(90);
                break;
            case '8':
                // Move servo to position 45 degrees
                servoMotor.write(45);
                break;
            case '9':
                // Move servo to position 0 degrees
                servoMotor.write(0);
                break;
            default:
                break;
        }
    }
}


5. Kondisi [Kembali]

Motor servo akan bergerak sesuai masukkan tombol keypad yang mana tiap tombol keypad memiliki sudut rotasi tertentu.


    Download HTML
   
Download Program
   
Download Video Simulasi
    Download Datasheet Motor Servo
    
Download Datasheet Arduino Uno
    Download Datasheet Keypad 

 











Tidak ada komentar:

Posting Komentar

Sistem Otomatis Lampu Belajar dan Kipas Pendingin Berbasis Kehadiran dan Suara

[menuju akhir] [KEMBALI KE MENU SEBELUMNYA] DAFTAR ISI 1. Pendahuluan 2. Tujuan 3. Alat dan Bahan 4. Dasar Teori 5. Percob...