Vince WilkinsonKayla HolmesChristian Francis
Published

LofT Monitoring Counseling Office Visits

By using PIR Proximity Sensors, we detected the amount of activity in the counseling office in order to help others plan their visits.

IntermediateFull instructions provided10 hours516
LofT Monitoring Counseling Office Visits

Things used in this project

Hardware components

Photon
Particle Photon
×1
Breadboard (generic)
Breadboard (generic)
×1
Proximity Sensor
Proximity Sensor
×2
Infrared Sensor Jumper Wire - 3-Pin JST
×2

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Custom parts and enclosures

Enclosure Plan

Schematics

Fritzing Diagram of Sensors

This was the wiring we used for our sensors.

Code

Office Activity

Processing
This code detects whether someone is entering or exiting the counselors office in order to get a better idea of the best time to go there.
// This #include statement was automatically added by the Particle IDE.
#include <SparkFunPhant.h>

String action;
int marker = 1400;
int person_count = 0;
bool blocked = false;
bool unblocked = true;
double value1 = 0;
double value2 = 0; 

const char server[] = "data.sparkfun.com"; // Phant destination server
const char publicKey[] = "q5Y5lndQWnS60x65drnr";
const char privateKey[] = "BV4V5RpX9RtNWXNxB808";
Phant phant(server, publicKey, privateKey); // Create a Phant object

const int POST_RATE = 3000; // Time between posts, in ms.
unsigned long lastPost = 0; // global variable to keep track of last post time

void setup()
{
    Serial.begin(9600);
    pinMode(A0, INPUT);
    pinMode(A1, INPUT);
}

void loop()
{
    action;
    marker;
    person_count;
    blocked;
    unblocked;
    int sensor_reading_1 = analogRead(A0);
    int sensor_reading_2 = analogRead(A1);

    if(sensor_reading_1 > marker or sensor_reading_2 > marker)
    {
        blocked = true;
        unblocked = false;
        if(sensor_reading_1 < marker and sensor_reading_2 > marker)
        {
            action = "Entering";
            Serial.println(action);
            person_count++;
            Serial.println("Total people passed: " + (String)person_count);
            postToPhant();
            delay(2000);
        }
        if(sensor_reading_1 > marker and sensor_reading_2 < marker)
        {
            action = "Leaving";
            Serial.println(action);
            person_count++;
            Serial.println("Total people passed: " + (String)person_count);
            postToPhant();
            delay(2000);
        }
    }
    else
    {
        blocked = false;
        unblocked = true;
    }
    value1++;
    value2++;
    delay(20);
}

int postToPhant()
{    
    // Use phant.add(<field>, <value>) to add data to each field.
    // Phant requires you to update each and every field before posting,
    // make sure all fields defined in the stream are added here.
    phant.add("movement", action);
    phant.add("total_person_count", person_count);
        	
    TCPClient client;
    char response[512];
    int i = 0;
    int retVal = 0;
    
    if (client.connect(server, 80)) // Connect to the server
    {
		// Post message to indicate connect success
        Serial.println("Posting!"); 
		
		// phant.post() will return a string formatted as an HTTP POST.
		// It'll include all of the field/data values we added before.
		// Use client.print() to send that string to the server.
        client.print(phant.post());
        delay(1000);
		// Now we'll do some simple checking to see what (if any) response
		// the server gives us.
        while (client.available())
        {
            char c = client.read();
            Serial.print(c);	// Print the response for debugging help.
            if (i < 512)
                response[i++] = c; // Add character to response string
        }
		// Search the response string for "200 OK", if that's found the post
		// succeeded.
        if (strstr(response, "200 OK"))
        {
            Serial.println("Post success!");
            retVal = 1;
        }
        else if (strstr(response, "400 Bad Request"))
        {	// "400 Bad Request" means the Phant POST was formatted incorrectly.
			// This most commonly ocurrs because a field is either missing,
			// duplicated, or misspelled.
            Serial.println("Bad request");
            retVal = -1;
        }
        else
        {
			// Otherwise we got a response we weren't looking for.
            retVal = -2;
        }
    }
    else
    {	// If the connection failed, print a message:
        Serial.println("connection failed");
        retVal = -3;
    }
    client.stop();	// Close the connection to server.
    return retVal;	// Return error (or success) code.
}

Credits

Vince Wilkinson
-1 projects • 0 followers
This is for our project and future things
Kayla Holmes
1 project • 0 followers
Christian Francis
1 project • 0 followers

Comments