Introduction: Cat-Tracking Catdoor

With this special cat-tracking-catdoor you will know exactly if your cat is home or not.

On a 3D printed and lasercutted panel you will see exactly which cats are in, and which cats are not.

We are going to check the cats when they walk through the catdoor, using RFID. We could do this using the chip your cat is chipped with, but since my cats are not chipped, this instructable will only contain RFID tags on a collar.

I have added a small example of how the reader works, too. You can see it in the video.

Moscow:

Must have:

- The catdoor will detect a cat coming through.

- If the cat is coming into the house, the panel will be updated.

- If the cat is going outside the house, the panel will be updated.

- The panel will tell the user which cats are inside the house.

- The panel will tell the user which cats are outside the house.

- The panel will be 3D printed.

- The names of the cats owned will be lasercutted into the panel.

Should have:

- The RFID reader will have a range of 5 cm.

Could have:

- The panel will count the amount of cats
inside house.

- The cat door will be 3D printed.

Will not have:

- The catdoor will have a timer, so after a certain time the cats cannot go through the door.

Step 1: Get the Right Stuff

For this project you will need the following:

  • An Arduino
  • A RFID chip reader (RFID-RC522)
  • RFID tags
  • Leds
  • (long) Arduino wires
  • A 3D printer you can use OR a catdoor that you already have at home
  • A laser cutter you can use
  • A cat
  • A wooden panel that is 100x100x5 mm.
  • A wire to create your own jumpers
  • Someone who can solder the wires

Step 2: Set Up Your Arduino

Set the pin layout like the table above.

You will also need to download a library for the RFID reader.
You can download it here.(I've also put it in this step).

To add the library to your project, go to Sketch > Include Library > Add .Zip Library and select the library.

In the script added to the next step you can find more documentation on the library.

Step 3: Understanding RFID Chips

RFID tags like the one above contain 16 sectors, with each sector containing 4 blocks and every block containing 16 bits.

The RFID reader can read every bit of the tag, and recognize the tag by these bits.

In the table above you can find an example of a default (factory settings = empty) tag.

Every block has a block that is used for managing the other blocks. This is called the sector trailer.
As shown above, the sector trailer consists of two keys (A and B), both 6 bits and 4 access bits. The access bits are used to access the right block, and the keys are used to authenticate (you could see this as logging in) to the sector.

On default, both the keys are 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF or in decimal 255 255 255 255 255 255.

To read or write a block, we must first authenticate into the sector.

You should NOT write user data to the sector trailer, but to the other blocks in the sector.

For example, you can write block 4, 5 and 6 of sector 2.

(If you want to, you can change the authentication keys, but make sure you remember what the key is, because you can not directly read the keys on the card.)

If you would like more information on this, please visit this website.

Step 4: Writing Your Tags

To check which cat is going through the catdoor, we need to write a special code or identifier on the cats tag.

We are going to do this by writing the cats name in decimals to the 4th block of the tag.

You can convert your cats name using this website. For example my cat "K a t i e " will become "75 97 116 105 101".

Make sure you put spaces between the characters, so you convert each character.

String cardKatie = "Katie"; //The name of the first cat
int pinKatie = 3; //The led pin for the first cat
char cardDitty[] = "Ditty"; //The name of the second cat 
int pinDitty = 4; // The led pin for the second cat
char cardMinoes[] = "Minoes"; //The name of the third cat 
int pinMinoes = 5; // The led pin for the third cat
char cardRovik[] = "Rovik"; //The name of the fourth cat 
int pinRovik = 6; //The led pin for the fourth cat

As you can see, I have four cats, Katie, Ditty, Minoes and Rovik.
You can edit these variables to the names of your own cat(s). Make sure you also change the pin that will output to the led that belongs to that cat.

You can write the tag using the method

writeCard(name) 

(You need to make sure the method is called in your loop() method, because the program will do nothing otherwise.)

The name parameter should be the the cats name, for example cardKatie, that contains the String "Katie".

The method will convert the chars to decimals and write them on the 4th block of the tag.

If you want to, you can change the block to another block by changing this variable:

byte block = 4; //We will use the 4th block to write the cats name to.

(But is has to be a block that is a non-sector trailer block.)

(If your cats name is longer than 16 characters, you might need to do multiple writes on different blocks, but who has a name that long?)

If you cats name is shorter than 16 characters (which it should be, its just a cat), the remaining bytes will 0.

To write a name to your tag, just run the method with the name, and write it once to the tag.

You can use the script that is included in this script.

If you want more information about the RFID reader, check this PDF.

Step 5: Reading Your Tag

After you have written your tag, we can start reading it!

To read the tag, we are going to authenticate (log in) to the sector, and read the values on the right (in our case, and if you didn't the 4th) block.

You can read a card using this method:

readNameInCardBlock()

This method will read the tag, parse the name on the tag to a String and compare it using the following method:

void  compareCardNumberAndWritePin(String cardString){ //Method for signaling which cat is inside.<br>
        if(cardString.equals(cardKatie)){
          byte status = digitalRead(pinKatie);
          digitalWrite(pinKatie, !status);
        }else if(cardString.equals(cardDitty)){
          byte status = digitalRead(pinDitty);
          digitalWrite(pinDitty, !status);
        }else if(cardString.equals(cardMinoes)){
          byte status = digitalRead(pinMinoes);
          digitalWrite(pinMinoes, !status);
        }else if(cardString.equals(cardRovik)){
          byte status = digitalRead(pinRovik);
          digitalWrite(pinRovik, !status);
        }else{
          Serial.println("Card not known: ");
          Serial.print(cardString);
        }
  }

As you can see, the variables for my that cats are used in here, too.

(You need to make sure the method is called in your loop() method, because the program will do nothing otherwise.)

In order for the code to work, you must change the card en pin variables to your own variables.

If you didn't do it already, you should also edit the pins in the setup() method.

When everything is changed, you should see a led going on (or off) when you swipe your tag over the RFID reader.

Step 6: Print Your Stuff

Because this is a 3D project, we are going to print the cat door and the user interface.

The designs are added to the step.

The Cat_door_design.stl contains the catdoor*, and the ui_interface contains the 3D part of the User Interface.
You should print these.

You can edit the ui_laser_design_2.svg so your own cat names will be used, and laser cut it out.

* If you have trouble printing the catdoor, like me, just use one you already have at home.

Step 7: Create Your Own Wires

Because the distance between the UI and the catdoor is a little longer than the jumpers wires you are using (by a meter), we are going to make our own wires.

For this, we are going to use the wire.
You need to cut 7 wires that are the length you need.

After that you can solder them to your RFID reader, and connect them to your Arduino.
(You might not want to solder the wires to your Arduino, so you should just put them in the Arduino, or make the Arduino-end of the wire using this instructable.)

Step 8: Putting It All Together

User Interace:

When you have printed and lacercutted the UI, you can easily put it together.

Just put the lacercut part in the 3D printed part.

Catdoor:

Put the cat-door-3D-printed parts together.

You can put the RFID reader in the special hole for it in the cat-door-flap.

OR

Attach your RFID reader to the catdoor you already have. Make sure it is waterproof, since your cats wont care if it is raining outside or not, and the RFID reader can't deal with water.