Interaction Lab Final: RTC Logging W/ IR Rangefinder (Katherine Li and Millie Wong)- Prof. Mikesell

Millie’s grandmother has Alzheimer’s and a symptom of it is paranoia; her grandmother worries that people may break in and steal things from her apartment while she is sleeping. The origin of the idea for this project came from wanting to design something that was practical, and would detect, track and log times of people passing by the sensor, and it would be a structure that wouldn’t require wifi (for her complex isn’t set up with wifi).  

For our project we wanted to create a stand alone object with a simple security system, something that would represent a guard dog. This simple object would be battery powered, connected to an Arduino with a real time clock (RTC), a rangefinder (RF) and an RFID (this is the type of chip that is in our ID cards that would be used to activate/deactivate the object). We wanted to create an object that would look inconspicuous, the rangefinder and the RFID reader would be hidden inside the object.

The device will be activated by the RFID sensor. When the sensor is on, an LED light will come as feedback. This would then begin the process of logging the time and date onto the microSD card connected to the Seeeduino whenever there is motion in front of the sensor. The data that is logged on the microSD card is recorded on an Excel sheet, and can be accessed when inserted into a laptop.

To say we faced many struggles for this project would be an understatement. There arose issues with the IR Rangefinder, the RFID Sensor, the Seeeduino RTC and the 3D Printing process.  

Challenges

We faced many, many challenges with this project. Firstly, the rangefinder wasn’t consistent with the readings. The values that were read differed greatly. Millie solved this by using smoothing. This meant taking the average of all the readings to allow for a more consistent number. In the end, the value was set so that for any reading over 90, the LED would light up. A second and main issue was getting the Seeeduino to work. It was very frustrating the night before the project was due, just sitting down with Professor Mikesell, trying to get the wonky board going. In the end, even after going through 3 boards, we ended up scrapping the idea of using the Seeeduino. A recurring problem we encountered before seeking Professor Mikesell’s help was that the code would not upload into the board and constantly return this error: “avrdude stk500_getsync(): not in sync resp=0x30”.

The 3D Printing was also an issue. We originally wanted to print a wireframe design using Meshmixer, so that the design of the dog could be hollow. Unfortunately the design printed out too many supporting structures that would make it too difficult to actually have a standing dog. This was followed by incorrectly printing the size of the box, and the location of the holes.

In the end, the Seeeduino Stalker was scrapped. The final project we presented ended up being the IR sensor attached to the laptop and using serial communication to print the computer’s date and time in Processing. Millie delayed the readings so that even though five commands could send from Arduino, Processing would only read one in that time. Each reading’s coordinates had about “15” added to “x” to have the date and time show up on a new line and not on top of each other.

 

Code

Arduino

RFID

// link between the computer and the SoftSerial Shield

//at 9600 bps 8-N-1

//Computer is connected to Hardware UART

//SoftSerial Shield is connected to the Software UART:D2&D3

#include <SoftwareSerial.h>

SoftwareSerial SoftSerial(2, 3);

unsigned char buffer[64]; // buffer array for data receive over serial port

int count=0; // counter for buffer array

void setup()

{

SoftSerial.begin(9600); // the SoftSerial baud rate

Serial.begin(9600); // the Serial port of Arduino baud rate.

}

void loop()

{

if (SoftSerial.available()) // if date is coming from software serial port ==> data is coming from SoftSerial shield

{

while(SoftSerial.available()) // reading data into char array

{

buffer[count++]=SoftSerial.read(); // writing data into array

if(count == 64)break;

}

Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port

clearBufferArray(); // call clearBufferArray function to clear the stored data from the array

count = 0; // set counter of while loop to zero

}

if (Serial.available()) // if data is available on hardware serial port ==> data is coming from PC or notebook

SoftSerial.write(Serial.read()); // write it to the SoftSerial shield

}

void clearBufferArray() // function to clear buffer array

{

for (int i=0; i<count;i++)

{

buffer[i]=NULL;

} // clear all index of array with command NULL

}

IR

//smoothing var

const int numReadings = 10; // the number of samples to keep track of

int readings[numReadings]; // the readings from the analog input

int readIndex = 0; // the index of the current reading

int total = 0; // the running total

int average = 0; // the average

//other variables

int IRpin = 1; //Ser the pin to analog 1

int LEDred = 9; // Set the pin to digital I/O 9

int val = 0; //Variable to store values from sensor

void setup() {

Serial.begin(9600); //initializae serial communications

pinMode(IRpin, INPUT); // set pins as OUTPUT

pinMode(LEDred, OUTPUT);

//initialize all readings to 0:

for (int thisReading = 0; thisReading < numReadings; thisReading++) {

readings[thisReading] = 0;

}

}

void loop () {

//SMOOTHING:

total = total – readings[readIndex];

readings[readIndex] = analogRead(IRpin);

total = total + readings[readIndex];

readIndex = readIndex + 1;

if (readIndex >= numReadings) {

readIndex = 0;

}

// calculate the average:

average = total / numReadings;

Serial.println(average);

delay(80);

//LED ACTIVIATION:

if (average > 90) {

digitalWrite(LEDred, HIGH);

}

else {

digitalWrite(LEDred, LOW);

}

}

Final Code

char command;

//smoothing var

const int numReadings = 10; // the number of samples to keep track of

int readings[numReadings]; // the readings from the analog input

int readIndex = 0; // the index of the current reading

int total = 0; // the running total

int average = 0; // the average

//other variables

int IRpin = 1; //Ser the pin to analog 1

int LEDred = 9; // Set the pin to digital I/O 9

int val = 0; //Variable to store values from sensor

//change state

int buttonState = 0; // current state of the button

int lastButtonState = 0; // previous state of the button

// the setup function runs once when you press reset or power the board

void setup() {

Serial.begin(9600);

// initialize digital pin 13 as an output.

pinMode(IRpin, INPUT); // set pins as OUTPUT

pinMode(LEDred, OUTPUT);

//initialize all readings to 0:

for (int thisReading = 0; thisReading < numReadings; thisReading++) {

readings[thisReading] = 0;

}

}

// the loop function runs over and over again forever

void loop() {

while (Serial.available()) {

val = Serial.read();

}

buttonState = digitalRead(LEDred);

lastButtonState = buttonState;

//SMOOTHING:

total = total – readings[readIndex];

readings[readIndex] = analogRead(IRpin);

total = total + readings[readIndex];

readIndex = readIndex + 1;

if (readIndex >= numReadings) {

readIndex = 0;

}

// calculate the average:

average = total / numReadings;

Serial.println(average);

delay(80);

//LED ACTIVIATION:

if (average > 90 && lastButtonState == LOW) {

digitalWrite(LEDred, HIGH);

command = ‘L’;

Serial.write(0);

Serial.print(“ON”);

}

if (average < 90) {

digitalWrite(LEDred, LOW);

}

}

Processing

import processing.serial.*;

PFont font;

Serial myPort;

int val; // Data received from the serial port

int x = 10;

void setup() {

printArray(Serial.list());

String portName = Serial.list()[1];

myPort = new Serial(this, “/dev/cu.usbmodem1421”, 9600);

size(500, 300);

background(0);

createFont(“Georgia”, 8);

}

void draw() {

if ( myPort.available() > 0) { // If data is available,

val = myPort.read(); // read it and store it in val

}

if (val == 0) {

println(“Date:”, month(), “/”, day(), “/”, year(), “Time:”, hour(), “:”, minute(), “:”, second());

text(“Date:” + month()+”/”+day()+”/”+year()+” Time:”+hour()+”:”+minute()+”:”+second(), 150, 10+x);

x = x + 15;

}

}

 

13228032_10209398518989404_699584283_n 13219839_10209398518949403_793422065_n 13228067_10209398518669396_1207348677_n 13235910_10209398518269386_33801803_n 13220019_10209398518469391_212396310_n

Leave a Reply