B TeamCarlo BaboDionysios Satikidis
Published

TYP - Track Your Parkinglot

TYP is an IoT-application based on the implementation of a Particle Photon that detects whether a certain parking lot is free or not.

IntermediateWork in progress1,197
TYP - Track Your Parkinglot

Things used in this project

Hardware components

Photo resistor
Photo resistor
×1
SparkFun 9DoF Sensor Stick
SparkFun 9DoF Sensor Stick
×1
Photon
Particle Photon
×1
Android device
Android device
×1

Software apps and online services

Assistant SDK
Google Assistant SDK
IFTTT - Android Device
IFTTT - Google Assistant
IFTTT - Particle

Story

Read more

Code

Parking

C/C++
/*
 *  This file is a sample application, based
 *  on the IoT Prototyping Framework (IoTPF)

    This application and IoTPF is free software: you can redistribute it     and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    IoTPF is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU v3 General Public License for more details.

    Released under GNU v3

    You should have received a copy of the GNU General Public License
    along with IoTPF.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 /**
    Internet of Things Prototyping Framework IoTPF  
    @Version 1.0
    @author Dionysios Satikidis
    
    TYP 2017/2018
    @version 1.0
    @author Kevin Thomas and Carlo Babo
*/


#include "IOT-ECOSYS_SEN09088_Lig.h"
#include <SparkFunLSM9DS1.h>



#define LSM9DS1_M	0x1E // Would be 0x1C if SDO_M is LOW
#define LSM9DS1_AG	0x6B // Would be 0x6A if SDO_AG is LOW



#define BUTTON_PIN D6
#define LED_PIN D7



//Create Magnetic Field Sensor / LDR Object
LSM9DS1 imu;

IoTEcoSys_SEN09088_Lig lig(1);
///

bool debug = true;
int lightDiff;
int magnetDiff;
int parkinglot = 0;
int led3 = D3;



void setup() {
    
   //Function that is called through IFTTT
   
    Particle.function("ok",okgoogle);
//////////



    //Heartbeat and Status LED's
    pinMode(LED_PIN, OUTPUT);
    pinMode(led3, OUTPUT);
   
   
   
    
    // Before initializing the IMU, there are a few settings
    // we may need to adjust. Use the settings struct to set
    // the device's communication mode and addresses:
    imu.settings.device.commInterface = IMU_MODE_I2C;
    imu.settings.device.mAddress = LSM9DS1_M;
    imu.settings.device.agAddress = LSM9DS1_AG;

    // Try to initialise and warn if we couldn't detect the chip
    if (!imu.begin())
    {
        if(debug){
            Particle.publish("[Debug] Oops ... unable to initialize the LSM9DS0. Check your wiring!", 0);        
        }
        while (1);
    }
    if(debug){
        Particle.publish("[Debug] LSM9DS1 ready", 1);        
    }
  
    if(debug){
        Particle.publish("[Debug] Setup done...", 1);        
    }


    lig.init();



    imu.readMag();
   
   
   //Save Light/Magnet Values on Start
   
   
    lightDiff = lig.getLigVal();
   
    magnetDiff = imu.mx + imu.my + imu.mz;

    
   
}

void loop() {
 
    // Heartbeat
    digitalWrite(LED_PIN, HIGH);
    imu.readMag();
    
    
    
    typedef enum STATE{START, FREE, TAKEN} STATE_TYPE;
    
    STATE_TYPE actState = START;
    STATE_TYPE nextState = START;
    


    switch(actState) {
        case START: 
            if (Particle.connected()) {
                nextState = FREE;
            }
            else {
                nextState = START;
            }
            break;
            
        case FREE: 
        
   
           if((lightDiff - lig.getLigVal()) > 200 && ((magnetDiff - (imu.mx + imu.my + imu.mz)) > 1000 || (magnetDiff - (imu.mx + imu.my + imu.mz)) < -1000)){
               
                digitalWrite(led3, HIGH);
                lightDiff = lig.getLigVal();
                magnetDiff = imu.mx + imu.my + imu.mz;
                parkinglot = 1;
              
                 nextState =TAKEN;
           }
           
 
        break;
        
        
        
        case TAKEN:
        
             if ((lig.getLigVal() - lightDiff ) > 200  &&  ((magnetDiff - (imu.mx + imu.my + imu.mz)) > 1000 || (magnetDiff - (imu.mx + imu.my + imu.mz)) < -1000)){
                
               lightDiff = lig.getLigVal();
               magnetDiff = imu.mx + imu.my + imu.mz;
               digitalWrite(led3,LOW);
               parkinglot = 0;
               
               
               nextState =FREE;
           }
        
      
        break;
        
        default:
            nextState=START;
    }
    
    actState = nextState;

  
    // Heartbeat
     digitalWrite(LED_PIN, LOW);

    // Tick of the application. 2000 = 2 Sec
    delay(2000);
  
  

  
}


// Function called through IFTTT , publishes the event

int okgoogle(String something) {
    
    if(parkinglot == 0){
       Particle.publish("Prüfen!", "frei",30);     
    }

    else{
        Particle.publish("Prüfen!", "belegt",30);     
        
    }

    return parkinglot;
}

Credits

Carlo Babo and Kevin Thomas

Posted by C6b3a6c229e4bba62bb882bf041ff1e0 B Team
Thanks to Dionysios Satikidis.

Comments

Add projectSign up / Login