Arduino - Door Event Logger




Introduction: Arduino - Door Event Logger

Ok, so for my first instructable I thought to share something I've just made today.
It's a logger for anything really that consist's of something being on or off ( in the door case, open / closed ).
For this to be applied to a door, the push-button has to be replaced to something like an hall effect sensor ( which I don't have thus the button).

All'right, what i've used:
- Arduino UNO
- DS1307 Real Time Clock
- SD shield ( from this instructable: )
- 1 led
- 1 push-button
- 220 ohm resistor , 10k resistor and hook-up wire

Step 1: Connecting the Parts

SD card pins:
** MOSI  - pin D11 
** MISO  - pin D12
** SCK   - pin D13
** CS    - pin D4 
+ GND, 5v, 3.3v

RTC pins:
** SDA  - A4
** SCL  - A5
** GND - GND
** VCC  - 5V

Button + led pins:
** Led's - to 220ohm resistor to GND
** Led's + to D3
** Connect the button to 5V and D2  
** Connect 10k resistor from D2 to GND

Step 2: The Code

As for the sketch, download it below.
External library used: adafruit's ds1307 lib ( )

Now, to explain a few things:

* ok - it stop's the loop if the sd card was not initialized correctly
* first - it log's the first state, and then wait for the state to change before logging it again

* time() - get the time from RTC and convert it to a string
* SDwrite(int state) - write's on the SD card the time and a message depending on the state it receive's (1 or 0)
* call(int buttonState) - it's used to turn off/on the led and trigger the SDwrite() function

Feel free to contact me for any additional information.

That's it for my first instructable, I'm waiting for feedback.

Step 3: UPDATE: Replaced the Button With Hall Effect Sensor

As promised I've replaced the button with a proper sensor for this project: a hall effect sensor.
The sensor I bought is called A3144 (got it off ebay). It has the following pin-configuration: VCC - GND - OUT.

Now to connect it to arduino, just remove the button and do the following.
VCC  - to 5V
OUT -  D2
* the 10k resistor still remains connected between 5V and D2

The sketch need's a little editing, as the sensor is essentialy an normally open switch and it was previously configured for an normally closed switch.
There are 3 lines of code that need to be modified:
if (buttonState == LOW)  to   if (buttonState == HIGH)
if (state==LOW)                to   if (state==HIGH)
if (state==LOW)                to   if (state==HIGH)

In the picture the sensor is taped to the door frame and the magned is fixed with double-sided tape to the door.
** The hall effect sensor have polarity.

The next stage is to add a remote control switch receiver and transmitter to make the sensor wireless.

Be the First to Share


    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Big and Small Contest

      Big and Small Contest
    • For the Home Contest

      For the Home Contest



    Question 1 year ago on Step 2

    Hallo, can it run on Arduino Nano ? What to change in the program ? Regards Marcel De Vuyst


    1 year ago on Step 2

    If you change the line "const int chipSelect = 10; // for SDcard", you can use a Arduino Logger shield such as one from Deek-Robot. Saving time in wiring up a logger. You can get those boards really cheap from Amazon.


    3 years ago

    First of all i am not a expert person in arduino.Now i have tried to learn and under stand the program through this type web plat form.So i expecting favorable reply from this community. ai can't under stand this line.
    void SDwrite(int state)
    String message = "";
    if (state==LOW)
    {message = "OPEN";}
    {message = "CLOSED";}

    I can't under stand this function .How the "state" co related with "buttonPin" position.


    Question 3 years ago on Introduction

    I know this is an older post but would this solution basically work to detect & log when a manual cash drawer is opened and closed? I'd prefer the Arduino processor be centralized somewhere closeby, with its drawer sensors positioned at each drawer. I'm new to Arduino. Thanks. - Alan


    8 years ago on Introduction

    I'm a complete noob when it comes to arduino, so this really helped me out. Thanks! I made some modifications based on my particular use, such as omitting the LED, and changing some of the output text, but it works beautifully with the code provided. Essentially, I'm prototyping a data logger for use in my weld shop. When a weld fixture is loaded, it will actuate a spring pin that will hold down a button. When unloaded, the button will be released. This will give me the exact time that it takes for an assembly to be completed. The only other thing I'd like to do is have it log duration instead of a timestamp, but it's usable as-is so I'll igure out how to do it at some point. Once I get this off of the breadboard and solder up a working model, it should work great! Probably will make 10-15 more to cover the whole shop! Thanks again!