PCF8574 IO Expander rule help

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

PCF8574 IO Expander rule help

#1 Post by asuz » 27 Apr 2021, 17:01

Hi to all,
I have a PCF8574 IO Expander that connected to Nodemcu. An IR Infrared Obstacle Avoidance Sensor Module (at picture) and a relay module is connected to the PCF8574 IO Expander. I want the relay to turn on once I show my hand to the sensor. I want the relay to stay on until I show my hand once again. Then when I show my hand to the sensor once more, I want the relay to turn off again, and keep it going like this. What should my rule be like?
Attachments
module.jpg
module.jpg (26.3 KiB) Viewed 4107 times
ESP_Easy.png
ESP_Easy.png (19.21 KiB) Viewed 4107 times

User avatar
Ath
Normal user
Posts: 3415
Joined: 10 Jun 2018, 12:06
Location: NL

Re: PCF8574 IO Expander rule help

#2 Post by Ath » 27 Apr 2021, 17:40

It could be as simple as this:

Code: Select all

on sensor#State=0 do // Sensor activated
  pcfgpio,2,=![relay#State] // Flip relay
endon
(relay assumed to be on pin 2 of the PCF8574)
- When the sensor turns on switch the relay to the inverse state

NB: You ill have to set a quite short on-time for the sensor, as you can only switch the relay once the sensor is back to 1 (off) again.
NB2: If the sensor is active-high, change the 'on sensor#State= do' to 'on sensor#State=1 do'
/Ton (PayPal.me)

asuz
Normal user
Posts: 175
Joined: 31 Oct 2018, 18:22

Re: PCF8574 IO Expander rule help

#3 Post by asuz » 27 Apr 2021, 20:26

Ath wrote: 27 Apr 2021, 17:40

Code: Select all

on sensor#State=0 do // Sensor activated
  pcfgpio,2,=![relay#State] // Flip relay
endon
Thank you very much, it works :)

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests