The Lawank merupakan salah satu aplikasi dari Mekatronika yang kami buat. Kami membuat the lawank ini terinspirasi dari Pintu otomatis yang biasa kita jumpai di Mal-mal. Cara kerja dari alat ini yaitu ketika kita mendekatkan tangan kita ke depan pintu, maka secara otomatis sensor pir yang terpasang akan membuat servo menarik pintu dari dalam. Sehingga pintu secara otomatis akan membuka selama waktu yang ditentukan. Alat-alat yang kami buat dari tugas ini yaitu :
- Arduino Nano
- Sensor Pir
- Servo
- Kabel Jumper
Berikut ini merupakan program yang kami buat untuk ditanamkan ke Arduino nanonya :
#include<Servo.h>
Servo myservo; // create servo object to control a servo
int val = 0;
int inputPin = 4;
int pos = 0; // variable to store the servo position
void setup() {
pinMode (inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
myservo.attach(8); // attaches the servo on pin 9 to the servo object
for(pos = 0; pos <180; pos += 1) // goes from 0 degrees to 180 degress
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
void loop() {
val = digitalRead(inputPin); // membaca nilai masukan
if (val == HIGH) { // memeriksa apakah input adalah TINGGI
for (pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
myservo.write (pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
delay(1000);
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
// in steeps of 1 degree
myservo.write(180); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}}
#include<Servo.h>
Servo myservo; // create servo object to control a servo
int val = 0;
int inputPin = 4;
int pos = 0; // variable to store the servo position
void setup() {
pinMode (inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
myservo.attach(8); // attaches the servo on pin 9 to the servo object
for(pos = 0; pos <180; pos += 1) // goes from 0 degrees to 180 degress
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
void loop() {
val = digitalRead(inputPin); // membaca nilai masukan
if (val == HIGH) { // memeriksa apakah input adalah TINGGI
for (pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
myservo.write (pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
delay(1000);
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
// in steeps of 1 degree
myservo.write(180); // tell servo to go to position in variable 'pos'
delay(5); // waits 15ms for the servo to reach the position
}}
Berikut ini adalah dokumentasi dari tugas Mekatronika The Lawank Siji ini :