Grantland AdamsShyam Patel
Published

Mailbox Motion Sensor

Want to know when someone opens your mail door? Well look no further, this device will do that for you.

IntermediateFull instructions provided10 hours348
Mailbox Motion Sensor

Things used in this project

Hardware components

Argon
Particle Argon
×2
Breadboard (generic)
Breadboard (generic)
×2
LED (generic)
LED (generic)
×1
Photo resistor
Photo resistor
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Google Sheets
Google Sheets
https://docs.google.com/spreadsheets/d/1IZL3vHtXl_j3U2KqzGMNd5W0jBk_XYso5zuUJixk5go/edit?usp=sharing
Maker service
IFTTT Maker service
https://ifttt.com/applets/106588073d
Google Youtube
https://youtu.be/xGSVWpLg1Zc

Hand tools and fabrication machines

Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Schematics

Sensor Reciever.jpg

Mailbox Sensor.jpg

Mailbox Sensor

Sensor Reciever

Code

Mailbox Sensor Code

C/C++
int led = D6;
int boardLed = D7;
int photosensor = A0;

int intactValue;
int brokenValue;
int beamThreshold;

bool beamBroken = false;

void myHandler(const char *event, const char *data); 


void setup() {
    pinMode(led,OUTPUT);
    pinMode(boardLed,OUTPUT);

    Particle.subscribe("rogerroger", myHandler);
    
    digitalWrite(boardLed,HIGH);
    delay(2000);

    digitalWrite(boardLed,LOW);
    digitalWrite(led,HIGH);
    delay(500);

    int off_1 = analogRead(photosensor);
    delay(200);
    int off_2 = analogRead(photosensor);
    delay(1000);
    
    digitalWrite(boardLed,HIGH);
    delay(100);
    digitalWrite(boardLed,LOW);
    delay(100);
    digitalWrite(boardLed,HIGH);
    delay(100);
    digitalWrite(boardLed,LOW);
    delay(100);

    digitalWrite(boardLed,HIGH);
    delay(2000);

    digitalWrite(boardLed,LOW);

    int on_1 = analogRead(photosensor);
    delay(200);
    int on_2 = analogRead(photosensor);
    delay(300);

    digitalWrite(boardLed,HIGH);
    delay(100);
    digitalWrite(boardLed,LOW);
    delay(100);
    digitalWrite(boardLed,HIGH);
    delay(100);
    digitalWrite(boardLed,LOW);
    delay(100);
    digitalWrite(boardLed,HIGH);
    delay(100);
    digitalWrite(boardLed,LOW);

    intactValue = (on_1+on_2)/2;
    brokenValue = (off_1+off_2)/2;
    beamThreshold = (intactValue+brokenValue)/2;

}


void loop() {
    if (analogRead(photosensor)>beamThreshold) {
        if (beamBroken==true) {
            Particle.publish("mailboxopen", "intact", PUBLIC);
            
            beamBroken=false;
        }
    }

    else {
        if (beamBroken==false) {
            // Same deal as before...
            Particle.publish("mailboxopen", "broken", PUBLIC);
            beamBroken=true;
        }
    }
}


void myHandler(const char *event, const char *data)
{


    if (strcmp(data,"intact")==0) {
        digitalWrite(boardLed,HIGH);
    }
    else if (strcmp(data,"broken")==0) {
        digitalWrite(boardLed,LOW);
    }
    else {
    }
}

Mailbox-sensor-receiver

C/C++
int led = D6;
int boardLed = D7;
int photosensor = A0;
int power = A5;

int intactValue;
int brokenValue;
int beamThreshold;

bool beamBroken = false;

void myHandler(const char *event, const char *data); 

void setup() {
	pinMode(led,OUTPUT); 
	pinMode(boardLed,OUTPUT); 
	pinMode(power,OUTPUT); 


	Particle.subscribe("maildooropen", myHandler);


void loop() {
	if (analogRead(photosensor)>beamThreshold) {
		if (beamBroken==true) {
			Particle.publish("rogerroger", "intact", PUBLIC);
			beamBroken=false;
		}
	}

	else {
		if (beamBroken==false) {
			Particle.publish("rogerroger", "broken", PUBLIC);
			beamBroken=true;
		}
	}
}


void myHandler(const char *event, const char *data)
{
	
	if (strcmp(data,"intact")==0) {
		digitalWrite(boardLed,HIGH);
	}
	else if (strcmp(data,"broken")==0) {
		digitalWrite(boardLed,LOW);
	}
	else {
		
		
	}
}

Credits

Grantland Adams

Grantland Adams

1 project • 1 follower
Shyam Patel

Shyam Patel

1 project • 1 follower

Comments

Add projectSign up / Login