Arduino Cat Detector SD Card Logger




Posted in TechnologyArduino

Introduction: Arduino Cat Detector SD Card Logger

About: Evil Mad Scientist, Atari Punk Console Maker, Avante Garde Contemporary Artist, Air Metal Musician

I used:

an Arduino Uno
a Parallax PIR Motion Sensor
a Seeed Studio SD Card Shield

Arduino, shield, sd card, logging shield, storage, logger

Check out This instructable on PIRs in case you didn't know what it is:

Step 1: Connect Your PIR Sensor

Hook up the PIR Sensor

Ground pin to Ground
VCC pin to 5V
OUT to A5

To better help you understand how to hook it up:
Arduino PinPIR Sensor Pin

Also hook up and LED to pin 9 on the arduino

You might need to use a breadboard to hook it up right.
I've included a Frizing file to illustrate the device hookups.

Step 2: Test Your PIR Sensor

Now enter this code into your Arduino

void setup() {
  pinMode(9, OUTPUT);
  pinMode(A5, INPUT);

void loop() {
  if (analogRead(A5) < 1){
    digitalWrite(9, LOW);
    Serial.println("No cats");
  if (analogRead(A5) > 0){
    digitalWrite(9, HIGH);
    Serial.println("Cat detected");

After you hooked up the Motion Sensor and the LED and uploaded your code to the Arduino, wave your hand in front of the sensor. If the LED lights up then you did it right. Sit still for a few seconds and the LED will go off.
You can also open the Arduino Serial Monitor to see whats going on.

Step 3: Connect You SD Card Sheild

Now that your Motion Sensor is working you want to log the times is senses motion.
So plug your new SD Card Shield into your Arduino and proceed to hookup the Motion Sensor and LED using the riser pins on the Shield.

All connections should be in the same place like on the Frizting file it shows.

Step 4: Log Your Cats

Now that its all hooked up, upload this code to your arduino:

NOTE: Your going to have to install the updated SDFat Library in order for this to work you can find it at:

/* This code was stolen and modified from the examples
provided along with thte sd fat library found at
* Append Example
* This sketch shows how to use open for append.
* The sketch will append 100 line each time it opens the file.
* The sketch will open and close the file 100 times.
#include <SdFat.h>

// filename for this example
char name[] = "CATS.LOG";

// SD chip select pin
const uint8_t chipSelect = SS;

// file system object
SdFat sd;

// create Serial stream
ArduinoOutStream cout(Serial);

// store error strings in flash to save RAM
#define error(s) sd.errorHalt_P(PSTR(s))
void setup() {
  pinMode(9, OUTPUT);
  pinMode(A5, INPUT);
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();

void loop() {
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
  ofstream sdout(name, ios::out | ios::app);
  if (!sdout) error("open failed");

  if (analogRead(A5) < 1){
    digitalWrite(9, LOW);
    Serial.println("No cats");
  if (analogRead(A5) > 0){
    digitalWrite(9, HIGH);
    int minutes = millis()/1000/60;
    int seconds = millis()/1000;
    int milliseconds = millis();
    //to make it easier to read the time stamps divide number of
    //milisecons by seconds by minuts.
    Serial.print("Cat detected ");
    Serial.print(" minutes ");
    Serial.println(" seconds after arduino boot.");  
    sdout << "Cat detected " << millis()/1000/60 << " minutes " << millis()/1000 << " seconds after arduino boot." << endl;
  if (!sdout) error("append data failed");

Now let it run for a while. Turn off you Arduino and remove the SD card. You can now plug the SD card into your computer and read the log file your arduino created.

In my final connections I used an additional prototyping shield with a mini breadboard so I could place the whole thing in a small space.



    • Make it Move Contest

      Make it Move Contest
    • Woodworking Contest

      Woodworking Contest
    • Microcontroller Contest

      Microcontroller Contest

    We have a be nice policy.
    Please be positive and constructive.




    Why is the PIR sensor attached to an analog pin? It is, after all, a digital sensor, i.e. either on (motion) or off (no motion).

    Could You Please Make Arduino Uno + PIR Sensor + RTC 3231 + SD Card Module Security DataLogger.

    Thanks In Advance


    Used this but altered cat to intruder so would know when someone had been in a room,with a sd card shield was much more easy,Made for a good low level security logger.

    Can you please do tghe same thing with an hcsro4 sensor atleast the code

    Nice! Just a tip: You may, on Step 3, change the title to "Connect your SD card shield. It had some typos. But apart from that, nice work and keep on being an awesome Arduino techie!

    Cool! I need to dig out some of my scrap PIR-modules and see whether one of them works for this. Already wondering where to put such a contraption...

    After completing this project, I thought to myself this could lead to some sort of interactive automated cat toy.