Hardware Reference
In-Depth Information
is implemented in Listing 13-4. The Arduino polls the distance sensor every
50ms (and writes a 1 to the “active” column every time movement is detected).
If movement is not being detected, it only writes a 0 to the “active” column once
every second (as opposed to every 50ms).
Listing 13-4 shows the completed software for the entrance logger, given the
improvements just described.
Listing 13-4: Entrance Logger Software—entrance_logger.ino
//Logs Room Entrance Activity
#include <SD.h> //For talking to SD Card
#include <Wire.h> //For RTC
#include "RTClib.h" //For RTC
//Define pins
//SD Card is on Standard SPI Pins
//RTC is on Standard I2C Pins
const int CS_PIN =10; //SS for SD Shield
const int SD_POW_PIN =8; //Power for SD Shield
const int RTC_POW_PIN =A3; //Used as digital output
const int RTC_GND_PIN =A2; //Used as digital output
const int IR_PIN =0; //Analog input 0
//Define an RTC object
RTC_DS1307 RTC;
//Initialize strings
String year, month, day, hour, minute, second, time, date;
//Initialize distance variables
int raw = 0;
int raw_prev = 0;
boolean active = false;
int update_time = 0;
void setup()
{
Serial.begin(9600);
Serial.println(F("Initializing Card"));
//CS pin, and pwr/gnd pins are outputs
pinMode(CS_PIN, OUTPUT);
pinMode(SD_POW_PIN, OUTPUT);
pinMode(RTC_POW_PIN, OUTPUT);
pinMode(RTC_GND_PIN, OUTPUT);
//Setup power and ground pins for both modules
digitalWrite(SD_POW_PIN, HIGH);
Search WWH ::




Custom Search