Jacek Pieczaba
Published

Occupancy detector

Idea is to use the Analog Coprocessor Pioneer Kit which could be use for car interior occupancy detector to protect young passengers.

BeginnerFull instructions provided8 hours832
Occupancy detector

Things used in this project

Hardware components

PSoC Analog Coprocessor Pioneer Kit
Cypress PSoC Analog Coprocessor Pioneer Kit
This board contain all the necessary sensors to execute the idea
×1

Story

Read more

Schematics

Occupancy Detector

TopDesign

Code

Occupancy Detector

C/C++
Code for Occupancy Detector project
/******************************************************************************
* Project Name      : Occupancy Detector
* Version           : 1.0
* Device Used       : CY8C4A45LQI-L483
* Software Used     : PSoC Creator 4.0 update 1
* Compiler Used     : ARM GCC 4.9.3 
* Related Hardware  : CY8CKIT-048 PSoC Analog Coprocessor Pioneer Kit 
*******************************************************************************/


#include "project.h"
#include "math.h"

//
#define ADC_CHANNEL_VREF			    (0u)
#define ADC_CHANNEL_VTH				    (1u)
#define ADC_CHANNEL_PIR                 (2u)

#define PIR_WINDOW_HIGH_3FT         (1200)
#define PIR_WINDOW_LOW_3FT          (-1200)   

#define FILTER_COEFFICIENT_TEMPERATURE	(32u)

#define LED_ON						    (0u)
#define LED_OFF						    (1u)

// Variables to hold the the ADC readings 
int16 adcResultVREF, adcResultVTH, adcResultPIR;
    
//Filter input and output variables for Vref and Vth measurements 

int16 filterOutputVref=0;
int16 filterOutputVth=0;
int16 highThreshold = PIR_WINDOW_HIGH_3FT;		                           
int16 lowThreshold = PIR_WINDOW_LOW_3FT;
  
// Variables for temperature readings

int16 thermistorResistance, Temp_inside_car,temperature;
    
// Variables for main processing


int16 filterInput;
int32 filterOutput = 0;


int main(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */

    
    ADC_Start();
    
    RefBuffer_Start();
    PVref_Start();
    PVref_Enable();
    PIRAmplifierStage1_Start();
    PIRAmplifierStage2_Start();    
    
    
    for(;;)
    {
        
        ADC_StartConvert(); 
        ADC_IsEndConversion(ADC_WAIT_FOR_RESULT); 
        
        adcResultVREF = ADC_GetResult16(ADC_CHANNEL_VREF);
        adcResultVTH = ADC_GetResult16(ADC_CHANNEL_VTH);
        adcResultPIR = ADC_GetResult16(ADC_CHANNEL_PIR);
       
     
        
         //TEMPERATURE CALCULATIONS
        
        /* Low pass filter the measured ADC counts of Vref */            
        filterOutputVref = (adcResultVREF + (FILTER_COEFFICIENT_TEMPERATURE - 1) * filterOutputVref) / FILTER_COEFFICIENT_TEMPERATURE;
        /* Low pass filter the measured ADC counts of Vth */         
        filterOutputVth = (adcResultVTH + (FILTER_COEFFICIENT_TEMPERATURE - 1) * filterOutputVth) / FILTER_COEFFICIENT_TEMPERATURE;
        /* Calculate thermistor resistance */
        thermistorResistance = Thermistor_GetResistance(filterOutputVref, filterOutputVth);           
       
        /* Calculate temperature in degree Celsius using the Component API */
        temperature = Thermistor_GetTemperature(thermistorResistance);
        Temp_inside_car=temperature*0.01;  // Temperature mesured inside car
       
       

     if (Temp_inside_car >=30){
        
        if ((adcResultPIR > highThreshold) || (adcResultPIR < lowThreshold)) Pin_LED_Write(LED_ON);
       }
     if (Temp_inside_car <=23)      Pin_LED_Write(LED_OFF);   
      
    } 
}

/* [] END OF FILE */

Credits

Jacek Pieczaba

Jacek Pieczaba

6 projects • 7 followers
Hardware design engineer;Technology enthusiast;

Comments