Justin WattsAustin TeeterJesse Peeler
Published © GPL3+

MEGR 3171: Barometric Door Sensor

Introducing a unique way to quantify the change in pressure within a room when a closed door opens.

BeginnerFull instructions provided51
MEGR 3171: Barometric Door Sensor

Things used in this project

Hardware components

M38 Magnetic Reed Switch
×1
Adafruit BMP 280 Barometric Pressure and Altitude Sensor
×1
Male/Male Jumper Wires
×4
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×2
Argon
Particle Argon
×3
Digital Temperature Sensor
×1

Software apps and online services

Google Sheets
Google Sheets
Google Docs
ThingSpeak API
ThingSpeak API
Microsoft Word (Schematics and Circuit Diagrams)

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Reed Switch Schematic

Pressure Sensor Schematic

Digital Temperature Sensor Schematic

Flow Chart

This flow chart serves to illustrate all the communications that are taking place between the Particle argons during operation.

Code

Digital Temperature Sensor

C/C++
int led = D7; // define the LED pin
int digitalPin = D2; // KY-028 digital interface
int analogPin = A0; // KY-028 analog interface
int digitalVal; // digital readings
int analogVal; //analog readings

void setup()
{
  pinMode(led, OUTPUT);
  pinMode(digitalPin, INPUT);
  //pinMode(analogPin, OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  // Read the digital interface
  digitalVal = digitalRead(digitalPin); 
  if(digitalVal == HIGH) // if temperature threshold reached
  {
    digitalWrite(led, HIGH); 
  }
  else
  {
    digitalWrite(led, LOW); 
  }

  // Read the analog interface
  analogVal = analogRead(analogPin); 
  Serial.println(analogVal); // print analog value to serial

  delay(100);
}

Magnetic Reed Switch

C/C++
const int REED_PIN = D2; // Pin connected to reed switch
const int LED_PIN = D7; // LED pin - active-high
    int mailtriggers=0;
    volatile bool mailsend = FALSE;
void enablemailsend(void){
    mailsend=TRUE;
}

void setup() 
{
  Serial.begin(9600);
  pinMode(REED_PIN, INPUT_PULLUP);
  pinMode(LED_PIN, OUTPUT);
  attachInterrupt(REED_PIN, enablemailsend, FALLING);
    Particle.variable("mailtrig", mailtriggers);
      int proximity = digitalRead(REED_PIN);
}
void mailnotification(void) 
{
    bool success = Particle.publish("Door_Open", Time.format(Time.now(), "%I:%M%p"), 60, PUBLIC, WITH_ACK);
    delay(1000);
    if (success == TRUE) {
        mailtriggers++;
        mailsend = FALSE; //if sent, then turn off the send flag, otherwise let it try again.
        }
}
void loop() 
{
    int proximity = digitalRead(REED_PIN);
 // Read the state of the switch
  if (proximity == LOW) // If the pin reads low, the switch is closed.
  {
    Serial.println("Switch closed");
    digitalWrite(LED_PIN, HIGH);
  mailnotification();
  }
  else
  {
    digitalWrite(LED_PIN, LOW); 
      /// Turn the LED off
  }
}

BMP 280 Barometric Pressure and Altitude Sensor

C/C++
#include <ThingSpeak.h>
#include "Particle.h"
#include <Adafruit_BMP280.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>

#define BMP_SCK  (13)
#define BMP_MISO (12)
#define BMP_MOSI (11)
#define BMP_CS   (10)

Adafruit_BMP280 bmp; // I2C

Timer timer(10000, checkenvironment);
Timer timer2(11000, updateThingspeak);
Timer timer3(10000, serialdebug);

int caladdress = 0;
double bmp280temp = 0;
double bmp280baro = 0;
double bmp280altitude = 0;
float analog1 = 0;
float analog2 = 0;
float analog3 = 0;
float analog4 = 0;
float analog5 = 0;
int count = 0;


unsigned long myChannelNumber = 1579199;
const char * myWriteAPIKey= "LUAMLONZITTUJ8OW";


void setup() {
Serial.begin(2304);
  Serial.println(F("BMP280 test"));
  if (!bmp.begin(0x77)) {  //0x77 is the i2c address of the sensor
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
  else {
      Serial.println("Sensor Located");}
      
  Particle.publish("DEBUG", "starting...");

  if (bmp.begin(0x77)) {  //0x76 is the i2c address of the sensor
    Particle.publish("DEBUG", "starting the environment timer...");
    timer.start(); //initialize timer
    timer2.start();//initialize timer2
    timer3.start(); }
     else {
    Particle.publish("WARN", "Could not find a valid BMP280 sensor, check wiring!");
  }

  Particle.publish("DEBUG", "started!");
 
Particle.connect();
Particle.variable("bmp280temp", bmp280temp);
  Particle.variable("bmp280bar", bmp280baro);
  Particle.variable("bmp280alt", bmp280altitude);
  //Particle.subscribe("Door_Open", serialdebug);
}
      
  void loop() {
    digitalWrite(D7, !digitalRead(D7)); //blink D7
        if (Particle.connected() == false) {  //if not connected, delay, 5000ms before attempting reconnect.  without delay was causing gps to fail.
            Serial.println("CONnecting to wifi");
		    Particle.connect();
		    delay(50000);
        } else {
            Serial.println("DISCoNNECTING WIFI");
            WiFi.off();
            delay(100000);
    }  
}
  void serialdebug() {
    Serial.print(F("Temperature = "));
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");

    Serial.print(F("Pressure = "));
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");

    Serial.print(F("Approx altitude = "));
    Serial.print(bmp.readAltitude(1018)); /* Adjusted to local forecast! */
    Serial.println(" m");
}
void checkenvironment() {
 bmp280temp = bmp.readTemperature();
   bmp280baro = bmp.readPressure();
   bmp280altitude = bmp.readAltitude(1018);
   
    Particle.publish("environment/temperature2", String(bmp280temp));
    Particle.publish("environment/pressure2", String(bmp280baro));
    Particle.publish("environment/altitude2", String(bmp280altitude));
    
   // Serial.println("stats checked");
    delay(2000);
}
    
 
bool updateThingspeak() {
    count++;
    delay(2000);
bool success = Particle.publish("thingSpeakWrite_", +
     "{ \"1\": \"" + String(bmp280temp) + "\"," +
     "\"2\": \"" + String(bmp280baro) + "\"," +
   "\"3\": \"" + String(bmp280altitude) + "\"," +
   "\"4\": \"" + String(analog5) + "\"," +
       "\"5\": \"" + String(analog4) + "\"," +
       "\"6\": \"" + String(analog1) + "\"," +
       "\"7\": \"" + String(analog2) + "\"," +
       "\"8\": \"" + String(analog3) + "\"," +   
  "\"k\": \"" + myWriteAPIKey + "\" }", 60, PRIVATE);
    return success;
}

Credits

Justin Watts

Justin Watts

0 projects • 0 followers
Austin Teeter

Austin Teeter

0 projects • 0 followers
Jesse Peeler

Jesse Peeler

0 projects • 0 followers

Comments

Add projectSign up / Login