Ingo Lohs
Published © GPL3+

Mailbox Signaling with Particle Photon

Another mailbox signaling project with a Particle Photon and a reed switch.

BeginnerFull instructions provided1 hour1,072
Mailbox Signaling with Particle Photon

Things used in this project

Hardware components

Photon
Particle Photon
×1
Particle Power Shield
×1
Jumper wires (generic)
Jumper wires (generic)
2 pices
×1
double-sided adhesive tape
×1
Breadboard (generic)
Breadboard (generic)
×1
3.7 V LiPo Battery
×1

Software apps and online services

Maker service
IFTTT Maker service

Story

Read more

Code

myBriefkasten

C/C++
v1.0 from 25.08.2018
// Reed-Switch with Particle Photon - works with v0.8.0-rc.8 without Libaries
// Ingo Lohs, v1.0 v. 25.08.2018
// Projekt, um einen Briefeinwurf vom Postzusteller zu signalisieren
// Signalisierung erfolgt via IFTTT an Empfänger bei Trigger des Events
// Öffnungs-Überwachung erfolgt rund um die Uhr 7x24h

const int REED_PIN_IN = D2; // Pin connected to reed switch
const int REED_PIN_OUT = D4; // Pin connected to reed switch
const int LED_PIN = D7; // LED pin - active-high
bool firstfire = true;

unsigned long lastmillis = 0; // time for interation the loop

void setup() 
{
  Serial.begin(9600);
  Particle.publish("myBriefkasten","Setup",100,PRIVATE);
  pinMode(REED_PIN_IN, INPUT_PULLUP);
  pinMode(REED_PIN_OUT, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  
  // Now flash the D7 LED on and off 
  digitalWrite(LED_PIN,HIGH); // Start der Kallibrierung mit D7 on
  Particle.publish("myBriefkasten","now online",100,PRIVATE);
  digitalWrite(LED_PIN,LOW); // Start der Kallibrierung mit D7 off
}


void loop() 
{
    if ((millis() - lastmillis) > 2000) {
        lastmillis = millis();
        readData();
    }
}


void readData() {

    int proximity = digitalRead(REED_PIN_IN); // Read the state of the switch
    
        if ((proximity == HIGH) and (firstfire == true)) // If the pin reads HIGH, the switch is open // the pin reads LOW, the switch is closed
        {
        Serial.println(">> Alarm >> Switch open");  
        digitalWrite(LED_PIN, HIGH); // Turn the LED on
        Particle.publish("myBriefkasten", "Briefkasten-Deckel ist geöffnet worden", PRIVATE);
        firstfire = false;
        }
        else if ((proximity == HIGH) and (firstfire == false)) // If the pin reads HIGH, the switch is open.
        {
        Serial.println("Switch is open a while");
        digitalWrite(LED_PIN, HIGH); // Turn the LED on
        firstfire = false;
        
        digitalWrite(LED_PIN, HIGH); // Turn the LED on
        delay(1000);
        digitalWrite(LED_PIN, LOW); // Turn the LED off
        delay(1000);
        }
        else if ((proximity == LOW) and (firstfire == true))
        {
        Serial.println(">> all is fine: Switch closed");
        digitalWrite(LED_PIN, LOW); // Turn the LED off
        firstfire = true;
        }
        else if ((proximity == LOW) and (firstfire == false))
        {
        Serial.println(">> all is fine: Switch closed");
        digitalWrite(LED_PIN, LOW); // Turn the LED off
        firstfire = true;
        }
        else
        {
        Serial.println("Switch ERROR Reading Value");
        digitalWrite(LED_PIN, LOW); // Turn the LED off
        }
}

Credits

Ingo Lohs

Ingo Lohs

182 projects • 194 followers
I am well over 50 years and come from the middle of Germany.

Comments