Welcome, Guest

Author Topic: How can connect a Passive Infra Red detector to the 4G kit for #IoT  (Read 1773 times)

medhi

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Good evening,
I am the owner of a HC-SR501 (Passive Infrared Detector) and I would like to connect it to the 4G kit for IoT.
How can I plug it ? How can I acces the PIR (Passive Infra Red) signal with the GPIO ?

@médhi

MBR

  • Sr. Member
  • ****
  • Posts: 256
  • Karma: +19/-0
Re: How can connect a Passive Infra Red detector to the 4G kit for #IoT
« Reply #1 on: October 15, 2015, 10:00:20 PM »
The HC-SR501 has only one 3.3V TTL output, which is simply turned high when the PIR sensor detects somethings. So all you need is to connect the sensor output to some GPIO pin configured for input and connect the remaining wires to 5V and GND pins. Aftert that, you can access the state of the pin via the SysFS interface by reading file value in the /sys/class/gpio/<name of GPIO pin>/ directory. If the pin supports triggering (i.e. it can generate an interrupt), which is indicated by the presence of file edge, you can use the select()/poll() to get the program know when the state of the pin chanches (see https://www.olimex.com/forum/index.php?topic=3026.msg12656 for details).
« Last Edit: October 16, 2015, 02:08:58 PM by MBR »

medhi

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Re: How can connect a Passive Infra Red detector to the 4G kit for #IoT
« Reply #2 on: October 17, 2015, 09:53:27 AM »
thanks a lot for your reply.
I am a total noob on Olimex board, I am more familiar with Raspberry Pi and Arduino.
How can I access the SysFS command ?
Sorry for being noobs, discovering a new product takes time.

MBR

  • Sr. Member
  • ****
  • Posts: 256
  • Karma: +19/-0
Re: How can connect a Passive Infra Red detector to the 4G kit for #IoT
« Reply #3 on: October 17, 2015, 09:45:16 PM »
There is no SysFS command, the SysFS is a virtual filesystem mounted under the directory /sys similar to ProcFS (which is mounted unter the /proc directory). The files and directories do not exist as real, block device (e.g. disk) backed files, but as virtual emtities, directly talking to various device drivers and other kernel subsystems, nevertheless you can use all common file operations on them (open, read/write, select/poll etc.). You can do that in the command line (using cat, echo and such) or from any programming languache which supports basic file operations.

For example, this is how I turn on a green LED on my A13 micro:

Code: [Select]
echo 12 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio12_pg9/direction
echo 1 > /sys/class/gpio/gpio12_pg9/value

The first command exports the GPIO, so the directory gpio12_pg9 appeares in the /sys/class/gpio/. The second command set the diretion to the output and the third sets the value to one, i.e. turns the GPIO on.