There are my first steps with RPi and i2c. I use expander pcf8574 and I would like to drive a relay to control LED and PIR sensor. When the state on sensor is HIGH, LED should be turn on. I wrote a script, which control LED, but I don't know how to read the state from PIR. I found function:

int wiringPiI2CRead (int fd)

but I can't use it properly to read a state (low or high) or it isnt correct function to read data from sensor. I know basics of programming so I need only one line like

int data = //function, which give a state from sensor

Below is a script. In python code it will be also right.

#include <wiringpi.h>
#include <wiringPiI2C.h>

int main (void)
  int fd; 
  fd = wiringPiI2CSetup(0x20);

 while (1) 
      if(......) > 0)) { //in this line I don't know how to read data
      wiringPiI2CWrite(fd,0x24);  //PIR Sensor ready, LED ON
      print('Motion Detected');
      wiringPiI2CWrite(fd,0x25);  //PIR Sensor ready, LED OFF
  return 0;
  • PIR sensor which is controlled by relay .... what does this actually mean? does the relay turn power on and off to the PIR sensor? – jsotola May 16 '18 at 1:40
  • You need to read the specs of the PCF8574, in particular how it is controlled with I2C. It's not our job to read the specs for you. – joan May 16 '18 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.