Sei sulla pagina 1di 11

RFID CAR START SYSTEM

ATMEGA128 + PN532 + PKH34

By: Rob Goodwin

REV 01 20130522

Table of Contents
I. Wiring Schematic
II. Wiring Schematic Pictorial
III. Wiring Schematic Complex (Fritzing)
IV. Perma Proto Board Layout
V. ATMEGA128 Arduino Code
VI. MiFare Chip Format
VII.Downloads

I. Wiring Schematic
Ignition Brown Connector (Male)

Ignition White Connector

XPRESSKIT

PKH34

12V+

RGB LED

LED

Ground

Ground
Ignition
Databus

12V+

Starter

Ignition Brown Connector (Female)

Switch Panel

ACC1

ACC2
IGN

Arduino

Starter

Ground

II. Wiring Schematic - Pictorial


Starter Switch | PKH34
OUTPUT

Reset
Dpin 0 (RX)
Dpin 1 (TX)
Dpin 2
Dpin 3
Dpin 4
VCC
GND
Crystal
Crystal
Dpin 5
Dpin 6
Dpin 7
Dpin 8

INPUT
12V+

PC6
PD0
PD1
PD2
PD3
PD4
VCC
GND
PB6
PB7
PD5
PD6
PD7
PD8

PC5
PC4
PC3
PC2
PC1
PC0
GND
AREF
AVCC
PB5
PB4
PB3
PB2
PB1

Ainput 5
Ainput 4
Ainput 3
Ainput 2
Ainput 1
Ainput 0
GND
Analog Ref
VCC
Dpin 13
Dpin 12
Dpin 11
Dpin 10
Dpin 9

III. Wiring Schematic Complex (Fritzing)

IV. PERMA PROTO BOARD LAYOUT

V. ATMEGA128 Arduino Code (Page 1)


/**************************************************************************/
/*!
Rob Goodwin
20130505
Authenticate MiFare Card RHG Format
Output - MOSFET - Relay

/********************/
/* SETUP
*/
/********************/
void setup(void) {
Serial.begin(115200);
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
nfc.SAMConfig();

*/
/**************************************************************************/

// RGB Setup
pinMode(RGB_red_pin, OUTPUT);
pinMode(RGB_blue_pin, OUTPUT);
pinMode(RGB_green_pin, OUTPUT);
digitalWrite(RGB_red_pin, HIGH);
digitalWrite(RGB_blue_pin, LOW);
digitalWrite(RGB_green_pin, HIGH);

#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>
#define IRQ (2)
#define RESET (3)
Adafruit_NFCShield_I2C nfc(IRQ, RESET);

// MOSFET setup
pinMode(MOSFET_pin1, OUTPUT);
digitalWrite(MOSFET_pin1, LOW);
pinMode(MOSFET_pin2, OUTPUT);
digitalWrite(MOSFET_pin2, LOW);

/********************/
/* INPUT PARAMETERS */
/********************/

// RGB LED Parameters


const int RGB_red_pin = 8;
const int RGB_green_pin = 9;
const int RGB_blue_pin = 10;
// MOSFET Parameters
const int MOSFET_pin1 = 11;
const int MOSFET_pin2 = 12;

}
/********************/
/* Main LOOP
*/
/********************/
void loop(void) {

unsigned long currentMillis = millis();


// Counter
int auth_condition = 0; // 0 no-auth 1 auth
long auth_millis = 0;
long auth_peroid = 3*60*1000; // unit milliseconds
// Sector 4 - 15 SECRET Key Info
uint8_t keya_4_15[6] = { 0x50, 0x43, 0x31, 0x32, 0x4E, 0x47 };

// auth_condition = 0 Code Block Below


if(auth_condition==0) {
// BUFFER | INITIALIZATION
uint8_t success;
// Flag to check if there was an error wPN532
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength;
// Length of the UID (4 or 7 bytes)
bool authenticated = false; // Flag to indicate if the sector is authenticated

// RGB Green
digitalWrite(RGB_red_pin, HIGH);
digitalWrite(RGB_blue_pin, HIGH);
digitalWrite(RGB_green_pin, LOW);
// MOSFET
digitalWrite(MOSFET_pin1, HIGH);
digitalWrite(MOSFET_pin2, HIGH);
} else {fail_check = 1;}

ATMEGA128 Arduino Code (Page 2)


// Data Initialize
uint8_t data_1[16];

// Array to store block data during reads

// Detect Card
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

}
} else {fail_check = 1;}
} else {fail_check = 1;}
} else {fail_check = 1;}
} else {fail_check = 1;}

// Fail Check Initialization


int fail_check = 0;
// Card Found
if (success)
{
// Check Card UID
if (uid[0] == 11)
{
if (uid[1] == 150)
{
if (uid[2] == 114)
{
if (uid[3] == 127)
{
// Check Card Length
if (uidLength == 4)
{

// Failure Check
if (fail_check == 1)
{
// Signal Failure
digitalWrite(RGB_red_pin, LOW);
digitalWrite(RGB_blue_pin, HIGH);
digitalWrite(RGB_green_pin, HIGH);
delay(500);
digitalWrite(RGB_red_pin, HIGH);
digitalWrite(RGB_blue_pin, LOW);
digitalWrite(RGB_green_pin, HIGH);
delay(2000);
}
}
}
// auth_condition = 1 Code Block Below
else {
if (millis() - auth_millis > auth_peroid) {
// Change auth_condition = 0
auth_condition = 0;
// RGB Green
digitalWrite(RGB_red_pin, HIGH);
digitalWrite(RGB_blue_pin, LOW);
digitalWrite(RGB_green_pin, HIGH);
// MOSFET
digitalWrite(MOSFET_pin1, LOW);
digitalWrite(MOSFET_pin2, LOW);
}
}

// Authenticate 15 Sector | 60 Block


success = nfc.mifareclassic_AuthenticateBlock (uid, uidLength, 60, 0,
keya_4_15);
// Check Authentification
if (success)
{
// Change auth_condition = 1
auth_condition = 1;
// Update auth_mil
auth_millis = millis();
}

VI. MiFare Chip Format (Page 1)


MiFare | ISO14443A

Key Chain FOB (active)


UID Value: 0x0B 0x96 0x72 0x7F
DEC 11 150 114 127
Key Chain FOB (reserve)
UID Value: 0x6B 0x0A 0x87 0xBD
DEC 107 10 135 189
// Sector 0 MAD1 Key Info
uint8_t keya_0[6] = { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 };
uint8_t keyb_0[6] = { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 };
// Sector 1 - 3 Key Info
uint8_t keya_123[6] = { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 };
uint8_t keyb_123[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
// Sector 4 - 15 Key Info
uint8_t keya_15[6] = { 0x50, 0x43, 0x31, 0x32, 0x4E, 0x47 };
uint8_t keyb_15[6] = { 0x58, 0x7B, 0x75, 0x4C, 0x3A, 0x3D };

SECTOR 3
00 00 03 12 D1 01 0E 55 01 72 68 67 6F 6F 64 77
69 6E 2E 63 6F 6D FE 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 7F 07 88 40 00 00 00 00 00 00

......U.rhgoodw
in.com.........
................
.......@......

SECTOR 4
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 7F 07 88 69 00 00 00 00 00 00

................
................
................
.......i......

SECTOR 5
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 7F 07 88 69 00 00 00 00 00 00

................
................
................
.......i......

SECTOR 6
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 7F 07 88 69 00 00 00 00 00 00

................
................
................
.......i......

SECTOR 7
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 7F 07 88 69 00 00 00 00 00 00

................
................
................
.......i......

SECTOR 8
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 7F 07 88 69 00 00 00 00 00 00

................
................
................
.......i......

SECTOR 9
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 7F 07 88 69 00 00 00 00 00 00

................
................
................
.......i......

DATA STORAGE (See Below)


SECTOR 0
0B 96 72 7F 90 08 04 00 62 63 64 65 66 67 68 69 .r
...bcdefghi
14 01 03 E1 03 E1 03 E1 03 E1 03 E1 03 E1 03 E1 .........
03 E1 03 E1 03 E1 03 E1 03 E1 03 E1 03 E1 03 E1 ........
00 00 00 00 00 00 78 77 88 C1 00 00 00 00 00 00 ......xw......

SECTOR 1
00 00 03 10 D1 01 0C 55 00 52 6F 62 20 47 6F 6F
64 77 69 6E FE 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 7F 07 88 40 00 00 00 00 00 00
SECTOR 2
00 00 03 18 D1 01 14 55 06 72 68 67 6F 6F 64 77
69 6E 40 67 6D 61 69 6C 2E 63 6F 6D FE 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 7F 07 88 40 00 00 00 00 00 00

......U.Rob Goo
dwin...........
................
.......@......

......U.rhgoodw
in@gmail.com...
................
.......@......

MiFare Chip Format (Page 2)


SECTOR 10
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 7F 07 88 69 00 00 00 00 00 00

................
................
................
.......i......

SECTOR 11
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 7F 07 88 69 00 00 00 00 00 00

................
................
................
.......i......

SECTOR 12
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 7F 07 88 69 00 00 00 00 00 00

................
................
................
.......i......

SECTOR 13
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 7F 07 88 69 00 00 00 00 00 00

................
................
................
.......i......

SECTOR 14
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 7F 07 88 69 00 00 00 00 00 00

................
................
................
.......i......

SECTOR 15
41 6C 77 61 79 73 2D 4C 65 61 72 6E 69 6E 67 00 Always-Learning.
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
00 00 00 00 00 00 7F 07 88 69 00 00 00 00 00 00 .......i......

VII. Downloads

MiFare Format

Pictures and Video

PN532

RFID CAR START

Source Code

Potrebbero piacerti anche