Archive

Archive for April, 2011

Review: Microchip Multimedia Expansion Board (for PIC32)

April 26th, 2011 No comments

Evaluation Type: Evaluation Boards
Application you used the part in: Evaluation of PIC32 USB Starter Kit II
Was everything in the box required?: Yes
What were the biggest problems encountered?: It requires some time to find the sufficient examples, and unfortunately most of the examples are pre-compiled HEX-files, so it is impossible to change something in the demos.
Though it is possible to find the same demos in the Microchip Application Library, it’s difficult to get theese working together with the Multimedia Expansion Board.

Scoring
Product Performed to Expectations: 10
Specifications were sufficient to design with: 8
Demo Software was of good quality: 8
Demo was easy to use: 7
Support materials were available: 8
The price to performance ratio was good: 9
TotalScore: 50

Prelude
In this review I will be demonstrating and reviewing the PIC32 Multimedia Expansion board. This is a expansion product from Microchip, which extends the capabilities of their PIC32 Starter Kits. In the end you will find my conclusion, whether you should buy this board or not.
In the following review, the Multimedia Expansion board will be called MEB board.
Read more…

Categories: Development boards, PIC, Reviews Tags:

Arduino RFID Door Lock

April 2nd, 2011 92 comments

Arduino RFID Door Lock

Once again me and one of my class mates have finished a project in school using the Arduino.
This time it’s an RFID Door Lock made with a real door and a real lock. The lock is turned using a standard 6V servo.

The project was about luxury, and we thought it might be luxurious if the door could be unlock automatically, fx when you come home from shopping, carrying a bag in each hand. This was the beginning of this project.

In the video below you can see a short demonstration of the system.



We thought you might be interested in the code, and to see how we implemented the “Master-system”, so the code can be found beneath. Remember that you should download the Servo library, and the Parallax RFID reader should be connected to the Serial RX pin (Pin 0).

//Start
#include <eeprom.h>
#include <servo.h>

//Initialiser
Servo servoLock;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

#define RFID_Enabled_Pin 2  // sets RFID enable pin to pin 2
#define servoPin 3 // sets the servo's pin to pin 3
#define LockedPos 10
#define UnlockedPos 110

byte buffer[100]; //used to store the incoming bytes from the RFID
byte RFID_Master[10] = {'1', '7', '0', '0', '7', 'D', 'B', '2', '4', 'F'}; //the secound RFID fob (key) to look for
byte RFID_Slave1[10], RFID_Slave2[10], RFID_Slave3[10]; //the first RFID fob (key) to look for
byte i; //used to keep track of which bit to write to
byte i2; //used to erase the RFID fob (key) number from the buffer

boolean DoorLocked; //true if door is locked

byte checkPosition; //used to check if the incomming number is true or false
boolean RFID_Master_Correct; //true if it's the right RFID fob (key), false if not
boolean RFID_Slave1_Correct, RFID_Slave2_Correct, RFID_Slave3_Correct; //true if it's the right RFID fob (key), false if not
boolean RFID_SaveNextRead;

void setup() {
  pinMode(13, OUTPUT); //enables the diode on the arduino
  pinMode(RFID_Enabled_Pin, OUTPUT); //sets the RFID pin to output
  RFID_Enable(false); //used to set the status of the RFID reader
  EEPROM_Read_Slaves();
//Lock
  PreLock(); //locks the arduino on startup
  RFID_Enable(true); //used to set the status of the RFID reader
  Serial.begin(2400);  //sets baudrate
  i = 1; //sets the varible to 1, and thereby skip the start byte (0x0A)
}
//Go To
//Loop
void loop() { //the main loop
// Serial data
  if (Serial.available()) { //check if the RFID reader sends anything
    if (buffer[0] != 0x0A) { //check if it the start bit is 0x0A
      buffer[0] = Serial.read(); //write bit to buffer
    } else {
//Recieve
      buffer[i] = Serial.read(); //write next bit to buffer
      if (buffer[i] == 0x0D) {   //if end bit is send, disable the RFID reader temporary
        Serial.print("RFID Tag scanned: ");
        RFID_Enable(false);
        RFID_Master_Correct = true;
        RFID_Slave1_Correct = true;
        RFID_Slave2_Correct = true;
        RFID_Slave3_Correct = true;
//RFID ID
        // We have read all bytes - we are now going to check them
        for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
          Serial.print(buffer[checkPosition+1], BYTE);
          if (buffer[checkPosition+1] == RFID_Slave1[checkPosition] && RFID_Slave1_Correct == true) {   // compares the written bits to "RFID1"
            RFID_Slave1_Correct = true; //Slave1 RFID tag is detected
          } else {
            RFID_Slave1_Correct = false; //Slave1 RFID tag is not detected
          }
          if (buffer[checkPosition+1] == RFID_Slave2[checkPosition] && RFID_Slave2_Correct == true) {   // compares the written bits to "RFID1"
            RFID_Slave2_Correct = true; //Slave2 RFID tag is detected
          } else {
            RFID_Slave2_Correct = false; //Slave2 RFID tag is not detected
          }
          if (buffer[checkPosition+1] == RFID_Slave3[checkPosition] && RFID_Slave3_Correct == true) {   // compares the written bits to "RFID1"
            RFID_Slave3_Correct = true; //Slave3 RFID tag is detected
          } else {
            RFID_Slave3_Correct = false; //Slave3 RFID tag is detected
          }
          if (buffer[checkPosition+1] == RFID_Master[checkPosition] && RFID_Master_Correct == true) {   // compares the written bits to "RFID1"
            RFID_Master_Correct = true; //Master RFID tag is detected
          } else {
            RFID_Master_Correct = false; //Master RFID tag is detected
          }
        }
        Serial.println("");
        if (RFID_SaveNextRead == false && (RFID_Slave1_Correct == true || RFID_Slave2_Correct == true || RFID_Slave3_Correct == true) && RFID_Master_Correct == false) { //see if the right RFID fob (key) is detected
          if (RFID_Slave1_Correct == true) { Serial.println("Slave1 Card Scanned"); }
          if (RFID_Slave2_Correct == true) { Serial.println("Slave2 Card Scanned"); }
          if (RFID_Slave3_Correct == true) { Serial.println("Slave3 Card Scanned"); }
//Door
          if (DoorLocked == true) { //see if door is locked or not
//Unlock
            Serial.print("Unlocking..."); //if the door is locked then unlocked it
            Unlock(5); //unlock with 5ms delay
            Serial.println(" Unlocked!");
          } else {
//Lock
            Serial.print("Locking..."); //if the door is unlocked then lock it
            Lock(5); //lock with 5ms delay
            Serial.println(" Locked!");
          }
//Vent
          delay(1000); // Wait for you to remove the RFID fob (key)
        } else if (RFID_Master_Correct == true && RFID_SaveNextRead == false) { // If the Master Card is scanned when not in programming mode
          Serial.println("Master Card Scanned - Programming mode Enabled");
          delay(1000);
          RFID_SaveNextRead = true;  // Enable programming mode
        } else if (RFID_Master_Correct == false && RFID_SaveNextRead == true) { // If another card is scanned when in programming mode
          // Save the Card
          if (RFID_Slave1[0] == 0) { // Is the Slave1 Card slot empty?
            for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
              RFID_Slave1[checkPosition] = buffer[checkPosition+1]; // Save the scanned card as Slave1
            }
            Serial.println("RFID Card saved in: Slave1");
            delay(1000);
          } else if (RFID_Slave2[0] == 0) { // Is the Slave2 Card slot empty?
            for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
              RFID_Slave2[checkPosition] = buffer[checkPosition+1]; // Save the scanned card as Slave2
            }
            Serial.println("RFID Card saved in: Slave2");
            delay(1000);
          } else if (RFID_Slave3[0] == 0) { // Is the Slave3 Card slot empty?
            for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
              RFID_Slave3[checkPosition] = buffer[checkPosition+1]; // Save the scanned card as Slave3
            }
            Serial.println("RFID Card saved in: Slave3");
            delay(1000);
          } else {
            Serial.println("No free Card slots");
            RFID_Enable(true); //turns on the RFID reader
            delay(1000);
            RFID_Enable(false); //turns off the RFID reader
            delay(1000);
          }
          EEPROM_Save_Slaves();
          RFID_SaveNextRead = false;
        } else if (RFID_Master_Correct == true && RFID_SaveNextRead == true) { // If the Master Card is scanned when in programming mode
          Serial.println("Master Card Scanned again - Removing all saved Cards");
          delay(1000);
          // Remove all Slave Cards
          for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
            RFID_Slave1[checkPosition] = 0;
          }
          for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
            RFID_Slave2[checkPosition] = 0;
          }
          for (checkPosition = 0; checkPosition < 10; checkPosition++) { //Read bit fra 0-9
            RFID_Slave3[checkPosition] = 0;
          }
          EEPROM_Save_Slaves();
          RFID_SaveNextRead = false;
        }

        RFID_Enable(true); //turns on the RFID reader
        EmptySerialBuffer(); //erase the buffer
        Serial.println("");
      }
      i++; //used in the beginning to write to each bit in the buffer
    }
  }
//Go to
}


void EmptySerialBuffer() { //replaces all bits in the buffer with zeros
  while (Serial.available()) { Serial.read(); }
  for (i2 = 0; i2 <= i; i2++) {
    buffer[i2] = 0;
  }
  i = 0;
}

void PreLock() {
  servoLock.attach(servoPin);  // attaches the servo on pin 3 to the servo object
  servoLock.write(LockedPos);              // tell servo to go to position in variable 'LockedPos'
  delay(250);                       // waits 1s for the servo to reach the position
  servoLock.detach();   //detaches the servo, so it's not using power
  DoorLocked = true;    //the door is locked
}

void Unlock(byte speedDelay) {
  int pos;
  servoLock.attach(servoPin);  // attaches the servo on pin 3 to the servo object
  for(pos = LockedPos; pos < UnlockedPos; pos += 1)  // goes from 10 degrees to 110 degrees
  {                                  // in steps of 1 degree
    servoLock.write(pos);              // tell servo to go to position in variable 'pos'
    delay(speedDelay);                       // waits 5ms for the servo to reach the position
  }
  servoLock.detach();   //detaches the servo, so it's not using power
  DoorLocked = false;   //the door is unlocked
}

void Lock(byte speedDelay) {
  int pos;
  servoLock.attach(servoPin);  // attaches the servo on pin 3 to the servo object
  for(pos = UnlockedPos; pos > LockedPos; pos -= 1)  // goes from 110 degrees to 10 degrees
  {                                  // in steps of 1 degree
    servoLock.write(pos);              // tell servo to go to position in variable 'pos'
    delay(speedDelay);                       // waits 5ms for the servo to reach the position
  }
  servoLock.detach();   //detaches the servo, so it's not using power
  DoorLocked = true;    //the door is locked
}

void RFID_Enable(boolean enabled) {
  if (enabled == true) {
    digitalWrite(RFID_Enabled_Pin, LOW); //enables the RDIF reader and turns on the diode on the arduino
    digitalWrite(13, HIGH);
  } else {                               //disables the RDIF reader and turns off the diode on the arduino
    digitalWrite(RFID_Enabled_Pin, HIGH);
    digitalWrite(13, LOW);
  }
}


void EEPROM_Read_Slaves() {
  byte EPROMaddr;
  for (EPROMaddr = 0; EPROMaddr < 10; EPROMaddr++) { //Read bit fra 0-9
    RFID_Slave1[EPROMaddr] = EEPROM.read(EPROMaddr);
  }
  for (EPROMaddr = 10; EPROMaddr < 20; EPROMaddr++) { //Read bit fra 0-9
    RFID_Slave2[EPROMaddr-10] = EEPROM.read(EPROMaddr);
  }
  for (EPROMaddr = 20; EPROMaddr < 30; EPROMaddr++) { //Read bit fra 0-9
    RFID_Slave3[EPROMaddr-20] = EEPROM.read(EPROMaddr);
  }
}

void EEPROM_Save_Slaves() {
  byte EPROMaddr;
  for (EPROMaddr = 0; EPROMaddr < 10; EPROMaddr++) { //Read bit fra 0-9
    EEPROM.write(EPROMaddr, RFID_Slave1[EPROMaddr]);
  }
  for (EPROMaddr = 10; EPROMaddr < 20; EPROMaddr++) { //Read bit fra 0-9
    EEPROM.write(EPROMaddr, RFID_Slave2[EPROMaddr-10]);
  }
  for (EPROMaddr = 20; EPROMaddr < 30; EPROMaddr++) { //Read bit fra 0-9
    EEPROM.write(EPROMaddr, RFID_Slave3[EPROMaddr-20]);
  }
}

Update:
The newest version of the code is now available at Github: https://github.com/TKJElectronics/ArduinoRFIDDoorLock.

Categories: Arduino Tags: