LA2 P4




1. Foto Hardware dan Diagram Blok [Kembali]




  

2. Prosedur Percobaan  [Kembali]

  • Rangkai semua komponen 
  • Buat program di aplikasi arduino IDE
  • Setelah selesai masukkan program ke arduino 
  • Jalankan program pada simulasi dan cobakan dengan modul




Rangkaian terdiri dari inputan berupa keypad dan keluaran berupa putaran motor servo, yang keduanya dihubungkan oleh arduino. Keypad terdiri dari 9 tombol (1-9) yang mana, masing-masing tombol akan menghasilkan gerakan yang berbeda pada motor servo, tergantung dari program arduino yang dibuat. Dan perlu diketahui bahwa sudut putaran pada motor servo hanya dapat mencapai 180 derajat.

4. Flowchart dan Listing Program [Kembali]

Flowchart:


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 tombol keypad yang ditekan.


Tidak ada komentar:

Posting Komentar

M4

[KEMBALI KE MENU SEBELUMNYA] DAFTAR ISI 1. Pendahuluan 2. Tujuan 3. Alat dan Bahan 4. Dasar Teori Percobaan a. ...