Amanda ElsayedChloe Mundie
Published

Shining Bright in the Mailbox

How many times have you wondered if "You've Got Mail;" now with only two photons, you will know right a way.

IntermediateFull instructions provided3 hours742
Shining Bright in the Mailbox

Things used in this project

Hardware components

Photon
Particle Photon
×2
Photo resistor
Photo resistor
×1
Resistor 2.21k ohm
Resistor 2.21k ohm
We actually used a 3.3k ohm resistor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
EZSound Module
Make sure you order the push button activated one
×1
Breadboard (generic)
Breadboard (generic)
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
This is to build the codes for your photons
Maker service
IFTTT Maker service
This is to track data and to receive notifications
Particle Console
This is a dashboard to track any updates

Story

Read more

Schematics

Photosensor Photon

This schematic is for the photon that is sensing the light. It includes a 3.3k Ohm resistor, a photo-resistor, and a photon.

Speaker Photon

This schematic is for the photon with the recordable speaker.

Code

Light Sensed/Not Sensed (Publish)

C/C++
If light is sensed then the mailbox is open and if it is not sensed it is closed
//Initialing variables
int lightValue;// variable of the light value the light sensor senses
int lastPub;// conition that limits how many times the factor loops 
int mailtriggers;// counter of number of times the mailbox is opened
char publishString[40];// published array for storing the counter

void setup() {
    pinMode(A0, INPUT); // Light Sensor is connected to A0 on the photon
    Serial.begin(9600);
    //stating variables
    Particle.variable("lightValue", lightValue);
    Particle.variable("mailtriggers", mailtriggers);
}

void loop() {
    lightValue = analogRead(A0); //analongread the light value which is connected to A0
    // print line variables
    Serial.println(lightValue);
    Serial.println(mailtriggers);
    delay(100); //delay before going into the is statement 

    if((lightValue > 100) and (lastPub != 1)){ //this statement is to publish that the mailbox is opened if the light value is over a 100 and if lastpub is not equal to 1
        Particle.publish("LightSensed", "Someone opened the mailbox", PUBLIC);//publishing that the mailbox is open
        lastPub = 1; //turns lastpub to 1 so it does not go through the condition again and go to next one
        mailtriggers++;//counter for the number of times the mailbox was opened
        sprintf(publishString,"%d",mailtriggers); //publish the counter with a string so it can display a number
        Particle.publish("mailtriggers", publishString, PUBLIC);//publish the counter
        delay(1000);// delays the code from reading the light sensor for a second
    }
    else if((lightValue <= 50) and (lastPub != 2)){//this statement is to publish that the mailbox is closed if the light value is equal to or under 50 and if lastpub is not equal to 2
        Particle.publish("LightNotSensed", "Mailbox Closed", PUBLIC);//publishing that the mail box is closed
        lastPub = 2;//turns lastpub to 2 so it does not go trhough this condition again and go to next one
        delay(1000);// delays the code from reading the light sensor for a second
     }
    
    }

LED and Speaker On/Off (Subscribe)

C/C++
This photon reads the events published from the other photon to depict whether it should turn the LED on or off, and the speaker on or off. When the photon senses the other photon publishing the event name "LightSensed" the LED will turn on and the speaker will turn on. The opposite happens when the other photon publishes "LightNotSensed" and both components turn off.
int led=D7; //Defined a variable for the led on the particle photon
//D7 turns on when Tinker or function sends signal to turn on HIGH
int voice=D5; //Defined another variable for pin that connected to speaker
//other pin was GND on photon
void setup() {
    
    digitalWrite(led, HIGH);//initial state condition on HIGH command 
    pinMode(led, OUTPUT);//definition condition for output led 
    pinMode(voice, OUTPUT);//definition condition for output speaker

    
    Particle.subscribe("LightSensed", turtle, "350044000c47343438323536");//subscribe to other photon to read the published function reading for LightSensed call out under event name
    Particle.subscribe("LightNotSensed", turtleoff, "350044000c47343438323536");//subscribe to other photon to read the published function reading for LightNotSensed call out under event name
}

void turtle(const char *event, const char *data){
    
    digitalWrite(led, HIGH);//output for led to read HIGH when LightSensed is read on other photon to turn on
    digitalWrite(voice, LOW);//output for speaker to read LOW when LightSensed is read on other photon to turn on
}

void turtleoff(const char *event, const char *data){
    
    digitalWrite(led, LOW);//output for led to read LOW when LightNotSensed is read on other photon to turn off
    digitalWrite(voice, HIGH);//output for speaker to read HIGH when LightNotSensed is read on other photon to not turn on again
}
    
void loop() {
   
}

Credits

Amanda Elsayed

Amanda Elsayed

1 project • 1 follower
Chloe Mundie

Chloe Mundie

1 project • 1 follower

Comments

Add projectSign up / Login