pir2 2.1.0.0
Main Page

PIR 2 click

PRVIH_PAR_RECENICA_SA_PRODUCT_PAGE_DA_ISPRATE_CELINU

[click Product page](CLICK_PRODUCT_PAGE_LINK)


Click library

  • Author : Stefan Ilic
  • Date : Dec 2023.
  • Type : ADC/I2C type

Software Support

We provide a library for the PIR 2 Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

This library contains API for PIR 2 Click driver.

Standard key functions :

  • pir2_cfg_setup Config Object Initialization function.
    void pir2_cfg_setup ( pir2_cfg_t *cfg );
    void pir2_cfg_setup(pir2_cfg_t *cfg)
    PIR 2 configuration object setup function.
    PIR 2 Click configuration object.
    Definition: pir2.h:136
  • pir2_init Initialization function.
    err_t pir2_init ( pir2_t *ctx, pir2_cfg_t *cfg );
    err_t pir2_init(pir2_t *ctx, pir2_cfg_t *cfg)
    PIR 2 initialization function.
    PIR 2 Click context object.
    Definition: pir2.h:121

Example key functions :

  • pir2_read_raw_adc This function reads raw ADC value.
    err_t pir2_read_raw_adc ( pir2_t *ctx, uint16_t *raw_adc );
    err_t pir2_read_raw_adc(pir2_t *ctx, uint16_t *raw_adc)
    PIR 2 read raw ADC value function.
  • pir2_read_voltage This function reads raw ADC value and converts it to proportional voltage level.
    err_t pir2_read_voltage ( pir2_t *ctx, float *voltage );
    err_t pir2_read_voltage(pir2_t *ctx, float *voltage)
    PIR 2 read voltage level function.
  • pir2_set_vref This function sets the voltage reference for PIR 2 click driver.
    err_t pir2_set_vref ( pir2_t *ctx, float vref );
    err_t pir2_set_vref(pir2_t *ctx, float vref)
    PIR 2 set vref function.

Example Description

This example demonstrates the use of PIR 2 Click boards.

The demo application is composed of two sections :

Application Init

Initializes the driver and selects the driver interface.

void application_init ( void )
{
log_cfg_t log_cfg;
pir2_cfg_t pir2_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
pir2_cfg_setup( &pir2_cfg );
PIR2_MAP_MIKROBUS( pir2_cfg, MIKROBUS_1 );
err_t init_flag = pir2_init( &pir2, &pir2_cfg );
if ( ( ADC_ERROR == init_flag ) || ( I2C_MASTER_ERROR == init_flag ) )
{
log_error( &logger, " Communication init." );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
#define PIR2_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition: pir2.h:97
void pir2_drv_interface_sel(pir2_cfg_t *cfg, pir2_drv_t drv_sel)
PIR 2 driver interface setup function.
void application_init(void)
Definition: main.c:29
@ PIR2_DRV_SEL_I2C
Definition: pir2.h:112

Application Task

It checks if the sensor has detected movement and displays message on the USB UART.

void application_task ( void )
{
float voltage = 0;
pir2_read_voltage ( &pir2, &voltage );
if ( voltage > PIR2_VOLTAGE_TRESHOLD )
{
log_printf( &logger, " Motion detected \r\n" );
Delay_ms( 1000 );
}
}
void application_task(void)
Definition: main.c:62
#define PIR2_VOLTAGE_TRESHOLD
Definition: main.c:27

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.PIR2

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.