# Logic in circuits when using GPIO

**URL:** https://discourse.nodered.org/t/logic-in-circuits-when-using-gpio/6184
**Category:** General
**Created:** [28 December 2018 08:51 UTC](https://discourse.nodered.org/t/logic-in-circuits-when-using-gpio/6184 "2018-12-28T08:51:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![debouttek](https://avatars.discourse-cdn.com/v4/letter/d/848f3c/32.png) [@debouttek](https://discourse.nodered.org/u/debouttek)
#### Post date: [28 December 2018 08:51 UTC](https://discourse.nodered.org/t/logic-in-circuits-when-using-gpio/6184/1 "2018-12-28T08:51:34Z")

</div>

Hi  
A question from a noob. In Node-Red I have 3 circuits for controlling a pump. Position 1, 2, 3 and stop. I do this via a relay card with 8 relays that are controlled by push buttons in the dashboard and connected via GPIO. That works, but I want to bring some more logic into this.  
If the pump is in position 1 it can only be switched off with the stop button. Then you can choose to turn circuit 2 on and this can also be switched off again with the stop button. etc.  
You must therefore always press the stop button to select a different position.  
Can someone help me?

 ![pump](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/694f0fd717c74ece6699ed2e468703572805e77f.png)

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [28 December 2018 14:51 UTC](https://discourse.nodered.org/t/logic-in-circuits-when-using-gpio/6184/2 "2018-12-28T14:51:21Z")

</div>

> [@debouttek](#):
>
> If the pump is in position 1 it can only be switched off with the stop button. Then you can choose to turn circuit 2 on and this can also be switched off again with the stop button. etc.

One way would be to use a `state machine`, see:

1. [https://github.com/cflurin/node-red-contrib-dsm](https://github.com/cflurin/node-red-contrib-dsm)
2. [https://github.com/cflurin/node-red-contrib-dsm/wiki](https://github.com/cflurin/node-red-contrib-dsm/wiki)

---

<div class="post-metadata">

### Author: ![debouttek](https://avatars.discourse-cdn.com/v4/letter/d/848f3c/32.png) [@debouttek](https://discourse.nodered.org/u/debouttek)
#### Post date: [30 December 2018 17:19 UTC](https://discourse.nodered.org/t/logic-in-circuits-when-using-gpio/6184/3 "2018-12-30T17:19:06Z")

</div>

Thanks but dsm is not what I looked for.  
I did it with triggers
