claude garrett
Published

Unobtrusive Home Security

The basic things I worry about when I am away from home are: (1) is someone there and (2) is someone snooping? The Infineon DPS310 can help!

AdvancedFull instructions provided2 hours1,346
Unobtrusive Home Security

Things used in this project

Hardware components

DPS310
Infineon DPS310
×1
Resistor 10k ohm
Resistor 10k ohm
×6

Software apps and online services

Visual Studio 2015
Microsoft Visual Studio 2015

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic and Wiring Diagram

Code

Create Measurement Table

SQL
SQL script
USE [DPS310]
GO

/****** Object:  Table [dbo].[Measurement]    Script Date: 9/30/2017 11:05:19 AM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Measurement](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[Temperature] [int] NULL,
	[Pressure] [int] NULL,
	[Time] [datetime] NULL,
	[DeviceId] [int] NULL,
	[PressureHigh] [int] NULL,
	[PressureLow] [int] NULL,
 CONSTRAINT [PK_Measurement] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

Sketch to read DPS310 sensor and send to server

Arduino
Run this on the LinkIt Duo to send sensor data
#include <ifx_dps310.h>
#include <Bridge.h>
#include <HttpClient.h>

void setup()
{
  Bridge.begin();
  SerialUSB.begin(9600);
  while (!SerialUSB); // wait for a serial connection
  //Serial.begin(9600);
  //while (!Serial);
  Wire.begin();


  //Call begin to initialize ifxDps310
  //The parameter 0x76 is the bus address. The default address is 0x77 and does not need to be given.
  ifxDps310.begin(Wire, 0x76);
  //Use the commented line below instead of the one above to use the default I2C address.
  //if you are using the Pressure 3 click Board, you need 0x76
  //ifxDps310.begin(&Wire);
  
  // IMPORTANT NOTE
  //If you face the issue that the DPS310 indicates a temperature around 60 C although it should be around 20 C (room temperature), you might have got an IC with a fuse bit problem
  //Call the following function directly after begin() to resolve this issue (needs only be called once after startup)
  ifxDps310.correctTemp();

  SerialUSB.println("Init complete!");
}


void loop()
{
  // Initialize the client library
  HttpClient client;
  int inPin10 = 10;
  int inPin11 = 11;
  int inPin12 = 12;
  int deviceId;
  
  pinMode(inPin10, INPUT);
  pinMode(inPin11, INPUT);
  pinMode(inPin12, INPUT);

  deviceId = digitalRead(inPin10) + digitalRead(inPin11)*2 + digitalRead(inPin12)*4;
  
  long int temperature;
  long int pressure;
  long int pressureHigh=0;
  long int pressureLow=1000000000;
  long int pressureEma;
  int oversampling = 7;
  int ret;
  SerialUSB.println();

  //lets the Dps310 perform a Single temperature measurement with the last (or standard) configuration
  //The result will be written to the paramerter temperature
  //ret = ifxDps310.measureTempOnce(temperature);
  //the commented line below does exactly the same as the one above, but you can also config the precision
  //oversampling can be a value from 0 to 7
  //the Dps 310 will perform 2^oversampling internal temperature measurements and combine them to one result with higher precision
  //measurements with higher precision take more time, consult datasheet for more information
  ret = ifxDps310.measureTempOnce(temperature, oversampling);

  if (ret != 0)
  {
    //Something went wrong.
    //Look at the library code for more information about return codes
    SerialUSB.print("FAIL! ret = ");
    SerialUSB.println(ret);
  }
  else
  {
//    SerialUSB.print("Temperature: ");
//    SerialUSB.print(temperature);
//    SerialUSB.println(" degrees of Celsius");
  }

  //Pressure measurement behaves like temperature measurement
  //ret = ifxDps310.measurePressureOnce(pressure);
  ret = ifxDps310.measurePressureOnce(pressure, oversampling);
  if (ret != 0)
  {
    //Something went wrong.
    //Look at the library code for more information about return codes
    SerialUSB.print("FAIL! ret = ");
    SerialUSB.println(ret);
  }
  else
  {


  //Monitor loop ===========================================================================================================================
  pressureEma = pressure;
  for (int i=0;i<4400;i++) //~15 seconds
  {

  ret = ifxDps310.measurePressureOnce(pressure, 0); //As fast as possible for sensing doors - no oversampling
  if (ret != 0)
  {
    //Something went wrong.
    //Look at the library code for more information about return codes
    SerialUSB.print("FAIL! ret = ");
    SerialUSB.println(ret);
  }
  else
  {
    if (pressure > pressureHigh)
    {
      pressureHigh = pressure;
    }
    if (pressure < pressureLow)
    {
      pressureLow = pressure;
    }
  }

    pressureEma = (pressure + pressureEma * 19)/20; //calculate moving average of pressure
    SerialUSB.print("EMA:");
    SerialUSB.print(pressureEma);
    SerialUSB.print(" DevId:");
    SerialUSB.print(deviceId);
    SerialUSB.print(" Pa:");
    SerialUSB.print(pressure);
    SerialUSB.print(" PaL:");
    SerialUSB.print(pressureLow);
    SerialUSB.print(" PaH:");
    SerialUSB.println(pressureHigh);
  }
  if ((pressure > pressureEma + 15)||(pressure < pressureEma - 15))
  {
    SerialUSB.println("Door Event");
    //Send a Door Event to the server to send an email
    String s = "http://192.168.1.78:5000/api/email/";
    s += deviceId;   
    client.get(s);

    delay(10000); //Pause because there could be multiple events that trigger a door event
    pressureEma = pressure; //Sync up pressure EMA
  }
  
  }//End of Monitor loop
  
  //Send the temperature and pressure to the server
  String s = "http://192.168.1.78:5000/api/values/dps310?temperature=";
  s += temperature;
  s += "&pressure=";
  s += pressure;
  s +="&deviceId=";
  s += deviceId;
  s += "&pressureHigh=";
  s += pressureHigh;
  s += "&pressureLow=";
  s += pressureLow; 
  client.get(s);

}

DPS API

C#
API to update database and send email alerts
No preview (download only).

MeasureAndSendDPS310-HighLow2.zip

Arduino
Arduino code to measure and send DPS 310 data
No preview (download only).

DPSCharts - ClickMap.zip

C#
MVC .NET Charting code for DPS310 data
No preview (download only).

Credits

claude garrett

claude garrett

11 projects • 10 followers

Comments