Kendali Motor Stepper Menggunakan Fingerprint Arduino
Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang menggunakan sensor fingerprint untuk mengendalikan motor stepper. alat ini menggunakan driver TB6600 dan arduino. untuk fingerprint yang digunakan menggunakan modul DY-50 untuk lebih jelasnya berikut adalah komponen dan kodingnya.
a. Komponen yang dipakai
b. Program Arduino IDE
#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#define dirPin 2
#define stepPin 3
int getFingerprintIDez();
int parkir1;
int parkir2;
int parkir3;
int parkir4;
int parkir5;
int parkir6;
int nilaifp;
int a,b,c,d;
int cw, ccw;
int stepsPerRevolution;
SoftwareSerial mySerial(10,11);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
void setup()
{
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
pinMode(A4,INPUT);
pinMode(A5,INPUT);
pinMode(A6,INPUT);
Serial.begin(9600);
Serial.println("fingertest");
// set the data rate for the sensor serial port
finger.begin(57600);
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor :(");
while (1);
}
Serial.println("Waiting for valid finger...");
}
void loop() // run over and over again
{
getFingerprintIDez();
delay(50); //don't ned to run this at full speed.
}
uint8_t getFingerprintID() {
uint8_t p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK success!
p = finger.image2Tz();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK converted!
p = finger.fingerFastSearch();
if (p == FINGERPRINT_OK) {
Serial.println("Found a print match!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_NOTFOUND) {
Serial.println("Did not find a match");
return p;
} else {
Serial.println("Unknown error");
return p;
}
// found a match!
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
}
// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
// found a match!
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
bacasensor();
if(finger.fingerID == 0){
nilaifp = 1;
stepsPerRevolution = 0;
}
if(finger.fingerID == 1){
nilaifp = 2;
stepsPerRevolution = 600;
gerakccw();
delay(3000);
stepsPerRevolution = 600;
gerakcw();
}
if(finger.fingerID == 2){
nilaifp = 3;
stepsPerRevolution = 1200;
gerakccw();
delay(3000);
stepsPerRevolution = 1200;
gerakcw();
}
if(finger.fingerID == 3){
nilaifp = 4;
stepsPerRevolution =1800;
gerakcw();
delay(3000);
stepsPerRevolution = 1800;
gerakccw();
}
if(finger.fingerID == 4){
nilaifp = 5;
stepsPerRevolution = 1200;
gerakcw();
delay(3000);
stepsPerRevolution = 1200;
gerakccw();
}
if(finger.fingerID == 5){
nilaifp = 6;
stepsPerRevolution = 600;
gerakcw();
delay(3000);
stepsPerRevolution = 600;
gerakccw();
}
return finger.fingerID;
}
void gerakcw(){
digitalWrite(dirPin, LOW); // CW
for (int i = 0; i < stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000); // ganti delay untuk mempercepat motor
digitalWrite(stepPin, LOW);
delayMicroseconds(1000); // ganti delay untuk mempercepat motor
}
}
void gerakccw(){
digitalWrite(dirPin, HIGH); // CCW
for (int i = 0; i < stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000); // ganti delay untuk mempercepat motor
digitalWrite(stepPin, LOW);
delayMicroseconds(1000); // ganti delay untuk mempercepat motor
}
}
void bacasensor(){
//jika terdeteksi ada yg parkir nilainya 0
//kosong nilainya 1
parkir1 = digitalRead(A1);
parkir2 = digitalRead(A2);
parkir3 = digitalRead(A3);
parkir4 = digitalRead(A4);
parkir5 = digitalRead(A5);
parkir6 = digitalRead(A6);
Serial.print("Parkir: ");
Serial.print(parkir1);
Serial.print(parkir2);
Serial.print(parkir3);
Serial.print(parkir4);
Serial.print(parkir5);
Serial.println(parkir6);
}
c. VIDEO HASILNYA
No comments:
Post a Comment