-
-
Save WolfwithSword/3ef562568fa5cd25388f02cf23dbc97d to your computer and use it in GitHub Desktop.
attiny85 UART Fingerprint Sensor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SoftwareSerial.h"; | |
const int Rx = 3; | |
const int Tx = 4; | |
const int rst_rnd = 2; | |
const int temp = 0; | |
SoftwareSerial mySerial(Rx, Tx); | |
const byte txBuf[] = {0xF5, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xF5}; | |
byte reply[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; | |
void setup() { | |
pinMode(1,OUTPUT); | |
pinMode(5,OUTPUT); | |
digitalWrite(1,LOW); | |
digitalWrite(5,LOW); | |
pinMode(Rx, INPUT); | |
pinMode(Tx, OUTPUT); | |
pinMode(temp, OUTPUT); | |
mySerial.begin(19200); | |
while(!mySerial) { | |
; | |
} | |
} | |
void loop() { | |
while(mySerial.available()>0)mySerial.read(); | |
delay(1000); | |
while(mySerial.available()>0)mySerial.read(); | |
mySerial.write(txBuf, 8); | |
for (int i=0; i<8; i++) { | |
reply[i] = 0x00; | |
} | |
delay(1000); | |
while(mySerial.available()<8){}; | |
int i=0; | |
byte x; | |
while(mySerial.available()>0){ | |
x = mySerial.read(); | |
reply[i] = x; | |
i++; | |
} | |
if(reply[0]==0xF5 && reply[4]== 0x03 && reply[7]==0xF5){ | |
while(mySerial.available()>0)mySerial.read(); | |
digitalWrite(temp, HIGH); | |
delay(2000); | |
digitalWrite(temp, LOW); | |
delay(1000); | |
} | |
else{ | |
while(mySerial.available()>0)mySerial.read(); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment