Today we will use the Sensuino shield to read the output from PIR sensor (HC – SR501) and to save the time stamp to log file on SD card each time the PIR detects the motion. Although the Arduino can count the time itself we will use the external RTC (DS1307) module because there is a battery embedded in it. This means it will remember the time even after unplugging the Arduino from a power source so there is no need to set the time again. It is generally a good idea to use RTC when it comes to datalogging.
At first, we will need to attach both modules to the Sensuino. This could be done by soldering them to the end of RJ cable or with the use of our universal RJ adapter. After attachment the PIR sensor should be properly set up (for further information please visit henrysbench).
If we are done with the physical part of the job, we will need to upload the code. Because the SD writing, LCD displaying and RTC module communication are all significant memory consuming processes we employ alternative libraries for LCD and SD tasks into this project. SD card logging will be handled by SdFat library and for LCD we include just the very basic functions directly into the code (in separate file LCD.h).
Now, if we have the modules attached and the code uploaded we are ready for our trial run. There should be some welcome massage on the LCD screen after plugging the power cable, and we will have to wait 30s to give the PIR sensor enough time to set up. After this intermission we get into the main loop which alternately displays ‘o’ and ‘O’ symbol in the middle of the LCD just to let us know that the program is running. In case there is a signal from the PIR sensor an interruption routine will start. The interruption routine turns on the flag and the “if condition” in the main loop and will handle the job which means writing the timestamp on the SD card (if plugged otherwise it will display error message on LCD) and displaying ‘X’ symbol on the screen.
Files to download
Arduino sketch: pirLog.zip
Fritzing project: pirLog.fzz
Arduino library: SdFat