Alex HoneycuttNick St. Clair
Published

Mail Alarm

A quick and easy way to be reminded and to track the delivery time of your mail every day.

BeginnerWork in progress4 hours575

Things used in this project

Hardware components

Photon
Particle Photon
×2
Buzzer
Buzzer
×1
5 mm LED: Green
5 mm LED: Green
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×2
Male/Male Jumper Wires
×6
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×2

Story

Read more

Schematics

Pressure Sensor Schematic

The pressure sensor is connected to pin A1 and then connected to the ground pin.

Buzzer and LED Schematic

The Buzzer and LED are connected to pins D3 and D7 respectively. They are both then connected to the ground pin.

Code

Buzzer and LED Code (Photon 2)

C/C++
This code is made for the Photon that is attached to the Buzzer and LED light. It works by waiting for the signal to be sent from the Photon that is connected to the pressure sensor. Once it receives the code it sends a HIGH output signal to the buzzer for a set amount of time, one second in our case. This amount of time can be changed. After that second it shuts off the buzzer and sends a HIGH signal to the LED light. This remains on for a certain time interval, our video shows it set for 10 seconds but it can be longer. Once the mail is picked up, the first Photon will send a signal to shut off the LED and/or buzzer and the Photon will send a LOW output to both.
//Photon 2 will wait for Photon 1 to trigger and will then sound a buzzer for 2 seconds. Then the buzzer will turn off and a green LED will 
//turn on to notify the user that mail has arrived if the user does not hear the buzzer.

//Defining variables.
int LED = D7;
int Buzzer = D3;

//Define any pins that will be used to the following code.
void setup() 
{
    //Defining outputs.
    pinMode(D3,OUTPUT);
    pinMode(D7,OUTPUT);
    
    //Subscribing to Photon 1 and waiting for the "yes" data.
    Particle.subscribe("MAIL1892", Mail, "420053000f513532343635");
    
}

//After the 2 Photon recives the data "yes" from the first Photon, the buzzer is turned on for 2 seconds, then the green LED is turned on.
void Mail(const char *event, const char *data)
{
    if (strcmp(data, "yes")==0){
    //Sends voltage to the buzzer.
    digitalWrite(D3,HIGH);
    
    //Delays the code so the buzzer can run for 2 seconds (2000 milliseconds).
    delay(1000);
    
    //Turns off the buzzer.
    digitalWrite(D3,LOW);
    
    //Sends voltage to the LED
    digitalWrite(D7,HIGH);
    
    //Publish an event to the cloud so the data can be recorded and shared.
    Particle.publish("GotMail1234", "MAIL");
    
    
    }
    //Turns off power to the buzzer and LED
    else if (strcmp(data, "no")==0){
       digitalWrite(D7,LOW);
       
        
    }
}

Pressure Sensor Code (Photon 1)

C/C++
This code uses a square pressure sensor that is connected to one of the analog pins. The code uses a preset threshold to know when a package or piece of mail is set onto it. After the threshold is exceeded, the Photon sends a signal to the second Photon that is connected to the LED and buzzer. It loops this code on a time interval, we used 10 seconds in our video but it can be longer or shorter. Once the package and/or mail are picked up the signal will go back below the threshold. After that it will send a signal to the second Photon and it will shut off the LED and/or buzzer. It also sends information to a Real Time Graphics or Display and tracks the time the mail is placed in the mailbox and also the time that it is picked up.
//Photon 1 will send voltage through the 3.3V pin through a force pressure sensor. If mail is placed on the sensor, this will 
//cause a change in the voltage read at the A1 pin. If mail is placed on the sensor the value read at A1 is over 4000, the Photon 
//will then send an event to the cloud and the second Photon will subscribe to that event. If the mail is taken the value at A1 
//will be less than 4000, the Photn will then send another event to the could and the second Photon will also subscribe to that event.

//Defining variables.
int LED = D7;
int Pressure = A1;
int Valuesensor = 0;

//Define any pins that will be used in the following code.
void setup() 
{
    //Defining inputs and outputs.
    pinMode(LED,OUTPUT);
    pinMode(Pressure,INPUT);
}

//The loop will collect data from the A1 pin. This data will then output a particle publish if the set 
//parameter is triggered.
void loop() 
{
    //Sets inital value equal to the data from the A1 pin.
    Valuesensor = analogRead(A1); 
    
    //Setting the parameter of the analog pin to be greater than or equal to 4000, 4095 being the highest value.
    if (analogRead(A1) >= 4000){
       
        //Publish an event if the above parameter is triggered. With a unquie name "MAIL1892" and the value of "yes".
        Particle.publish("MAIL1892", "yes");
    
        //If the above parameter is triggered, the D7 pin with be set to high. Meaning the led on the D7 pin will
        //light up. This is to check that the above if statement is working, and to help troubleshoot any other issues.
        digitalWrite (LED,HIGH);
        
        //
        delay(10000);
    }
    if (analogRead(A1) < 4000)
    {
        
        
        //
        digitalWrite(LED,LOW);
        
        //Publish an event if the above parameter is triggered. With a unquie name "MAIL1892" and the value of "yes".
        Particle.publish("MAIL1892", "no");
    }
    
}

Credits

Alex Honeycutt

Alex Honeycutt

1 project • 0 followers
Nick St. Clair

Nick St. Clair

1 project • 0 followers

Comments