Andrea VegaAnthony BeltranJordan Nunez
Published © GPL3+

Lane of Things Group 511

In this project, we created an enclosure which held an infrared proximity sensor to record each time that Cheech went near his water.

IntermediateShowcase (no instructions)597
Lane of Things Group 511

Things used in this project

Hardware components

Jumper wires (generic)
Jumper wires (generic)
×1
Proximity Sensor
Proximity Sensor
×1

Software apps and online services

Google Sheets
Google Sheets
Particle.io
Fritzing
SparkFun phant.io

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

Fritzing Diagram

Enclosure Illustrator File

Schematics

PCB components

Fritzing (Without Camera)

Hollow Enclosure (front)

This is where we will hold stuff! The large opening on the front face is where the infrared sensor will poke out, and at the top the camera will poke out.

front

inside

Code

Particle Build - Infrared Code

Arduino
// This #include statement was automatically added by the Particle IDE.
#include <SparkFunPhant.h>

double distance;
int distancePin = 0;
int spyCameraPin = 2;
const char server[] = "data.sparkfun.com"; // Phant destination server
const char publicKey[] = "g67zG4gA17CaEWQq1qNx"; // Phant public key - HAS TO BE CHANGED
const char privateKey[] = "qzRKeWVZgRSlnwa4D4xR"; // Phant private key  - HAS TO BE CHANGED

Phant phant(server, publicKey, privateKey);


void setup()
{
    Serial.begin(9600);
    pinMode(spyCameraPin, OUTPUT);

}

void loop()
{    
    distance = analogRead(distancePin);
    Serial.println(distance);
    if(distance > 1100)
    {
        postToPhant();
        digitalWrite(spyCameraPin, HIGH);
        delay(1000);
        digitalWrite(spyCameraPin, LOW);
        delay(5000);
    }
}



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("distance", distance);
        	
    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

Andrea Vega
1 project • 0 followers
Contact
Anthony Beltran
1 project • 0 followers
Contact
Jordan Nunez
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.