Shahn ButtKevin MientaYovani Macias
Published © GPL3+

Bearded Dragon Monitor

A device that records the activity of a bearded dragon in its cage.

IntermediateFull instructions provided10 hours579
Bearded Dragon Monitor

Things used in this project

Hardware components

Photon
Particle Photon
×1
Breadboard (generic)
Breadboard (generic)
×1
LED (generic)
LED (generic)
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Photo resistor
Photo resistor
×1

Story

Read more

Custom parts and enclosures

Sensor Enclosure

Illustrator file that contains the outline of the Sensor Enclosure.

Schematics

Bearded Dragon Sensor Schematic

Code

Bearded Dragon Sensor Code

Arduino
This code was used with the Particle.io platform and sent to a photon micro-controller.
#include <Adafruit_DHT.h>

#include <SparkFunPhant.h>

int pir = D3;
int valpir = 0;
int led1 = D7;
int light = A1;
int vallight = 0;

#define DHTPIN D4           
#define DHTTYPE DHT22      

DHT dht(DHTPIN, DHTTYPE);

double hum;                 
double temp;               

double value1 = 0; 
double value2 = 0; 

const char server[] = "data.sparkfun.com"; // Phant destination server
const char publicKey[] = "zDMZd0EaNohzEE5WZYvq"; // Phant public key - HAS TO BE CHANGED
const char privateKey[] = "YyYgE6q42xuExxnWlDBe"; // 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
double checkHum = dht.getHumidity();
double checkTemp = dht.getTempFarenheit();

void setup() {

    Serial.begin(9600);
    pinMode(pir,INPUT_PULLUP);
    pinMode(led1,OUTPUT);

    pinMode(DHTPIN, INPUT);
    
    Particle.variable("hum", hum);
    Particle.variable("temp", temp);

    pinMode(light,INPUT);

}

void loop() {

    valpir = digitalRead(pir);
    int motioncount;
    motioncount = valpir;
    digitalWrite(led1,valpir);
    Serial.println("Movement = " + String(motioncount));

    if (motioncount == 1) {
    postToPhant();
    delay(30);
    motioncount = 0;
    delay(1000);
    
    vallight = analogRead(light);
    Serial.println("Light =" + String(vallight));

    if (checkHum > 0 && checkHum < 100)
    hum = checkHum;
        
    if (checkTemp > 32 && checkTemp < 100)
    temp = checkTemp;
    
    value1++;
    value2++;
    }
   
}

    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("humidity", checkHum);
    phant.add("motion", valpir);
    phant.add("temp", checkTemp);
    phant.add("light",vallight);
        	
    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

Shahn Butt
-1 projects • 0 followers
Contact
Kevin Mienta
-1 projects • 0 followers
Contact
Yovani Macias
-1 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.