Ngoprek bikin RFID, googling sana sini sempat mentok pusing hahahahaha.... excited...
Sedikit info:
arduino mega 2560 dengan 16x2 LCD dan RFID RS522 ditabah buzzer dan led.
dengon koneksi sbb:
Aduino dan RFID:
--------------------------------------------------
MFRC522 Arduino
Reader/PCD Mega
Signal Pin Pin
--------------------------------------------------
* RST/Reset RST 9
* SPI SS SDA(SS) 53
* SPI MOSI MOSI 51
* SPI MISO MISO 50
* SPI SCK SCK 52
Arduino dan LCD:
* LCD RS pin to digital pin 7
* LCD Enable pin to digital pin 8
* LCD D4 pin to digital pin 3
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 5
* LCD D7 pin to digital pin 6
* LCD R/W pin to ground
* LCD VSS pin to ground
Arduino dan buzzer + led
* Buzzer -- pin 2
* LED - resistor - pin 2
Koneksi arduino dan raspberry pi via serial dengan python
Python baca serial dari arduino kemudian insert to mysql dan to file txt.
PHP dan java baca txt untuk di tampilkan.
Berikut code nya untuk arduino:
--------------------------------------------------------------------------------------------------------------------------
#include <LiquidCrystal.h>
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 //
#define SS_PIN 53 //
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
LiquidCrystal lcd(7,8,3,4,5,6);
String val;
void setup() {
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
//ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details
//Serial.println(F("Scanning UID...."));
//establishContact();
lcd.begin(16,2);
}
void loop() {
lcd.clear();
lcd.setCursor(2,0);
lcd.print("Scanning for");
lcd.setCursor(6,1);
lcd.print("UID");
//read serial
if (Serial.available() >0)
{
val = Serial.readStringUntil('\n');
if (val != "unknown")
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Welcome: ");
lcd.setCursor(1,1);
lcd.print(val);
delay(2000);
}
else
{
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Unregister Card");
lcd.setCursor(1,1);
lcd.print("please report");
digitalWrite(2, HIGH);
delay(2000);
digitalWrite(2, LOW);
}
}
else //no input serial
{
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
MFRC522::MIFARE_Key key;
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
int val1=(mfrc522.uid.uidByte[0]);
int val2=(mfrc522.uid.uidByte[1]);
int val3=(mfrc522.uid.uidByte[2]);
int val4=(mfrc522.uid.uidByte[3]);
String valA=String(val1);
String valB=String(val2);
String valC=String(val3);
String valD=String(val4);
String uID=valA+valB+valC+valD;
//lcd.clear();
Serial.println(uID);
digitalWrite(2, HIGH);
delay(300);
// Halt PICC
mfrc522.PICC_HaltA();
digitalWrite(2, LOW);
// Stop encryption on PCD
mfrc522.PCD_StopCrypto1();
//lcd.setCursor(0,0);
//lcd.print("Last UID SCANNED:");
//lcd.setCursor(2,1);
//lcd.print(uID);
}
}
--------------------------------------------------------------------------------------------------------------------------
Sedangkan untuk python php saya dapat reference dari sini:
Silahkan di lihat, di modif dan dicoba hehehehehe
Dan berikut video hasilnya:
"No Offence No Heart Feelings"
Semoga Bermanfaat
2 comments:
itu rfid connect in ke phpnya gimana ya bingung
Di python nya mas..
Post a Comment