Andrew Plencner
Published

Hall Sensor Based Mail Detector

This device tracks two different doors using Hall effect sensors, I used it to track when mail is in my mailbox.

IntermediateFull instructions provided1
Hall Sensor Based Mail Detector

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×1
Hall Effect Sensor
Hall Effect Sensor
×2
LED (generic)
LED (generic)
×1

Story

Read more

Schematics

Full Diagram

Code

Source Code

C/C++
#include "Particle.h"
SYSTEM_MODE(AUTOMATIC);
SerialLogHandler logHandler(LOG_LEVEL_INFO);

//Declaring which pin the sensors are attached to.
int LED = 1;
int HALL1 = 14;
int HALL2 = 13;
bool on = false;
//

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(HALL1, INPUT);
  pinMode(HALL2, INPUT);
  digitalWrite(LED, LOW);
  Serial.begin(9600);
  delay(1000);
}

void loop() {
    
    //The following code is for troubleshooting with the serial monitor. 
    Serial.print("Hall1: ");
    //Serial.print(analogRead(HALL1));
    //Hall sensors really only use digitalRead, so these are commented out. 
    //Serial.print(" D: ");
    Serial.print(digitalRead(HALL1));
    Serial.print(" Hall 2: ");
    //Serial.print(analogRead(HALL2));
    //Serial.print(" D: ");
    Serial.print(digitalRead(HALL2));
    Serial.println(" ");
    delay(500);
      
    //Tells LED to turn on or off depending on the boolean 'on'.
    if(on == true){
      digitalWrite(LED, HIGH);
    }
    else{
      digitalWrite(LED, LOW);
    }
    //

    /*This turns the light on when the mailbox's outside door opens (when mail is dropped in), and back off when the inside door opens (mail is taken out). Note that in this design a hall sensor reading 'LOW' means it detects a magnet nearby, ie. the door is closed*/ 
    if((digitalRead(HALL1) == HIGH)){
      on = true;
    }
    if((digitalRead(HALL2) == HIGH)){
      on = false;
    }
    //
}

Credits

Andrew Plencner
1 project • 0 followers

Comments