How can connect a Passive Infra Red detector to the 4G kit for #IoT

Started by medhi, October 15, 2015, 07:23:47 PM

Previous topic - Next topic


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 ?



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 for details).


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.


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:

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.