Stefani LightDavid Macvaugh
Published © GPL3+

Mailbox Notification System

Ever wanted a way to see if you have mail without having to walk to go see? Well we have the thing for you!

IntermediateFull instructions provided5 hours2,151
Mailbox Notification System

Things used in this project

Story

Read more

Schematics

Mailbox Photon Schematic

Reset Photon Schematic

Code

Code for Mailbox Photon

Arduino
Photon Inside the mailbox code
int led2 = D7; 
int photoresistor = A1;

void setup() {
  pinMode(led2, OUTPUT);
  pinMode(photoresistor, OUTPUT);
}

void loop() {
      if (analogRead(photoresistor) < 500) {                //If the photoresistor reads a value less than 500
        Particle.publish("Mailbox","there is light");       //Publish event "Mailbox", with data "there is light"
        
        String value = String(analogRead(photoresistor));           //read the photoresistor again and set value to equal this number
        Particle.publish("Graph",value);digitalWrite(led2, LOW);    //publish event "Graph", with data "photoresistor value"
        
        digitalWrite(led2, HIGH);           //turn blue LED on
        delay(1000);                        //wait 1 second
        digitalWrite(led2, LOW);            //turn blue LED off
        delay(100000);                      //wait 100 seconds before trying to read the photoresistor again
        }
}

Code for Particle reset system

Arduino
int Button = D0;                      // button is connected to D0
int LED = D1;                         // LED is connected to D1
int FORCEON = D5;           // forces on the green LED
int SignalIN = D6;          // toggel signal for powering FORCEON

void setup()
{
  pinMode(LED, OUTPUT);                 // sets pin as output
  pinMode(Button, INPUT_PULLDOWN);      // sets pin as input
  pinMode(FORCEON, INPUT_PULLDOWN);     // checks to see if the toggel is HIGH
  pinMode(SignalIN, OUTPUT);        // is the toggel by the mailbox PhotonBo
  pinMode(D7, OUTPUT);              // is the standby light for program DEBUG
  Particle.subscribe("Mailbox", GreenOn);       // looks to see a published event "Mailbox" has happened
}                                               // and if it has then will run function GreenOn


void GreenOn(const char *event, const char *data)   // this section is focused on 
{                                                   // seeing if the mailbox ParticleBo 
    if (strcmp(data,"there is light")==0) {         // has published "there is light"
     digitalWrite(SignalIN, HIGH);                  // and if so will turn SignalIN to HIGH
    }
}

void loop()
{
  
    digitalWrite(SignalIN, LOW);          // DEFAULT is that the system will 
                                        // not have the green mail light blinking
  
  //FROM HERE ON STUCK LOOP
    while(1==1){
        digitalWrite(D7, HIGH);     // sets the BlueLED on
        delay(200);                 // waits for 200mS
        digitalWrite(D7, LOW);      // sets the BlueLED off
        delay(200);                 // waits for 200mS
        
        // blink the LED as long as the button is pressed
        while(digitalRead(FORCEON) == HIGH) {
            if(digitalRead(Button) == HIGH){                        // if the button is pressed
                Particle.publish("Mailbox","I got the Mail");       //Publish event "Mailbox", with data "I got the Mail"
                digitalWrite(SignalIN, LOW);                        // will turn SignalIn to low
                delay(500);                                         // which will then stop the next itteration of the FORCEON loop
            }                                                       // next itteration of the FORCEON loop
            
            else if(digitalRead(FORCEON) == HIGH) {
                digitalWrite(LED, HIGH);          // sets the GreenLED on
                delay(200);                       // waits for 200mS
                digitalWrite(LED, LOW);           // sets the GreenLED off
                delay(200);                       // waits for 200mS
            }
            
        }
    }
}

Credits

Stefani Light

Stefani Light

1 project • 0 followers
David Macvaugh

David Macvaugh

1 project • 0 followers

Comments