Sam Fogarty
Published © GPL3+

Sam F-Cant Lose My Keys Anymore

Using a pressure sensor and a Bluetooth connection, my photon 2 will send me an email depending on if my keys depress the sensor.

BeginnerShowcase (no instructions)8 hours126
Sam F-Cant Lose My Keys Anymore

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×1
Thin Film Pressure Sensor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
LED (generic)
LED (generic)
×1

Software apps and online services

Mailgun
nRF Connect SDK
Nordic Semiconductor nRF Connect SDK

Story

Read more

Schematics

shiny_crift_NTji1EdYoQ.png

Code

My code

C/C++
#include "Particle.h"
SYSTEM_MODE(AUTOMATIC);
SerialLogHandler logHandler(LOG_LEVEL_INFO);
//pre method calls
void connectedCallback(const BlePeerDevice& peer, void* context);
void disconnectedCallback(const BlePeerDevice& peer, void* context);
int led=7;
int sensor=A5;
//initializes variable to check if bluetooth is connected
boolean check= false;
int i=0;
int f=0;

BleUuid serviceUuid("afe7acc5-33a9-478f-bbe1-8944aa08e884");
//id when connecting
void setup() {
    //starts with light off
    pinMode(led,OUTPUT);
    digitalWrite(led,LOW);
  //activates BLE
    BLE.on();
  
//when connected/disconnected it does this(calls method)
	BLE.onConnected(connectedCallback, NULL);
	BLE.onDisconnected(disconnectedCallback, NULL);
//this code advertises the particle so it shows up on bluetooth apps
    BleAdvertisingData advertData;
    advertData.appendServiceUUID(serviceUuid);
    BLE.advertise(&advertData);
}

// loop() runs over and over again, as quickly as it can execute.
void loop() {
    while(check==true){
        //when sensor detects pessure
        if(analogRead(sensor)>100&&i<1){
            digitalWrite(led,HIGH);
            delay(200);
            digitalWrite(led,LOW);
            //sends email
             Particle.publish("keys_in");
            i++;
    
         }
        else if(analogRead(sensor)<100&&f<1){
            digitalWrite(led,LOW);
            //sends email
            Particle.publish("keys_out");
            f++;
    
        }
    
    }
}
//method creation
void connectedCallback(const BlePeerDevice& peer, void* context) {
	Log.info("connected");
	check=true;
}
//method creation
void disconnectedCallback(const BlePeerDevice& peer, void* context) {
	Log.info("disconnected");
	check=false;
}

Credits

Sam Fogarty
1 project • 0 followers

Comments