Jacob JorgensenTatiana LazoHoward SierraSteward
Published © GPL3+

Group 516 - Project 3 (Bathroom Pass Sensor)

We are going to be examining the frequency of bathroom pass usage for specific classrooms in the school.

IntermediateShowcase (no instructions)12 hours586
Group 516 - Project 3 (Bathroom Pass Sensor)

Things used in this project

Hardware components

Photon
Particle Photon
×1
Photo resistor
Photo resistor
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
Resistor 330 ohm
Resistor 330 ohm
×2
Resistor 10k ohm
Resistor 10k ohm
×2
Jumper wires (generic)
Jumper wires (generic)
×1
perf board
×1

Software apps and online services

particle

Hand tools and fabrication machines

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

Story

Read more

Custom parts and enclosures

SVG File

This is the .ai (SVG) file used to make the enclosure, it will be held together by #4 1/2in screws

Schematics

Fritzing Diagram

This is the schematic to the mote on a breadboard.

Code

PROJECT3PHANT

Arduino
This is the code that will push the data from the photon to the Phant database. Inside there is a conditional that checks whether the light sensor is receiving any light, if it is it will push all the data by the second to give an accurate message about the bathroom pass usage, and if it isn't pressed the code will push all of the values (except the light sensor - because the pass is back) every 3 minutes to give a reading about the temperature and humidity.
// This #include statement was automatically added by the Particle IDE.
#include <LiquidCrystal.h>

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

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

#define DHTPIN 6    // what pin we're connected to
#define DHTTYPE DHT22		// DHT 22 (AM2302)

DHT dht(DHTPIN, DHTTYPE);
double hum;
int supercount = 0;
double temp;
int phantom = 0;
double light;
double checkhum;
double checktemp;
int count = 0;
const int sensorPin = 0;
int lightLevel, high = 0, low = 1023;
LiquidCrystal lcd(0,1,2,3,4,5);
int ledPin = 0;

const char server[] = "https://data.sparkfun.com/streams/DJKN0mJwKqhLRM0aXXVA"; // Phant destination server
const char publicKey[] = "DJKN0mJwKqhLRM0aXXVA"; // Phant public key - HAS TO BE CHANGED
const char privateKey[] = "P4zKD94GzpTRJqW6ddGa"; // Phant private key  - HAS TO BE CHANGED
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(DHTPIN, INPUT);
    Particle.variable("hum", hum);
    Particle.variable("temp", temp);
    lcd.begin(16, 2);
    lcd.clear();
    //pinMode(ledPin, OUTPUT);
}

void loop() {
    lightLevel = analogRead(sensorPin);
    lightLevel = map(lightLevel, 0, 1023, 0, 255);
    lightLevel = constrain(lightLevel, 0, 255);
    checkhum = dht.getHumidity();
    checktemp = dht.getTempFarenheit();
    if(checktemp > 32 && checktemp < 100 && checkhum > 0 && checkhum < 100)
    {
        hum = checkhum;
        temp = checktemp;
    }
    light = lightLevel;
    lcd.setCursor(0,1);
    if(light > 50)
    {
        count = count + 1;
        lcd.clear();
        lcd.print("The pass has been out for ");
        lcd.print(count);
        lcd.print(" seconds.");
        phantom = 0;
        postToPhant();
    }
    else {
        lcd.clear();
        lcd.print("This is the bathroom pass for room .");
        count = 0;
        if((supercount % 300) == 0)
        {
            phantom = 1;
            postToPhant();
        }
    }

    supercount = supercount + 1;
    delay(1000);
}

int postToPhant()
{    
    
    if(phantom == 0)
    {
        phant.add("lightlevel", light);
        phant.add("counter", count);
        phant.add("classroom", "Don't worry");
        phant.add("temp", temp);
        phant.add("humidity", hum);
    }
    else
    {
        phant.add("counter", count);
        phant.add("classroom", "Don't worry");
        phant.add("temp", temp);
        phant.add("humidity", hum);
    }
        	
    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

Jacob Jorgensen

Jacob Jorgensen

1 project • 0 followers
Senior at Lane Tech College Prep
Tatiana Lazo

Tatiana Lazo

1 project • 0 followers
Howard SierraSteward

Howard SierraSteward

1 project • 0 followers

Comments

Add projectSign up / Login