# AND gate inputs

**URL:** <https://discourse.nodered.org/t/and-gate-inputs/4197>\
**Category:** General\
**Created:** [22 October 2018 19:54 UTC](https://discourse.nodered.org/t/and-gate-inputs/4197 "2018-10-22T19:54:23Z")\
**Posts on this page:** 10\
**Page:** 2

<div class="post-metadata">

**Author:** ![mustafa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mustafa/32/538_2.png) [@mustafa](https://discourse.nodered.org/u/mustafa)\
**Post date:** [30 October 2018 21:38 UTC](https://discourse.nodered.org/t/and-gate-inputs/4197/21 "2018-10-30T21:38:57Z")

</div>

I did it and the LED directly get ON regardless the AND gate condition

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 October 2018 21:54 UTC](https://discourse.nodered.org/t/and-gate-inputs/4197/22 "2018-10-30T21:54:56Z")

</div>

So does the debug node showing what is going to the GPIO node show true and false correctly?

---

<div class="post-metadata">

**Author:** ![mustafa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mustafa/32/538_2.png) [@mustafa](https://discourse.nodered.org/u/mustafa)\
**Post date:** [30 October 2018 22:02 UTC](https://discourse.nodered.org/t/and-gate-inputs/4197/23 "2018-10-30T22:02:18Z")

</div>

when the distance more than 10 No debug readings and when the distance less 10 the debug start read True only as attached

 ![b1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3efb835e7ee68063c84edea15b4b0d580e22a8e6.jpeg)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [30 October 2018 22:16 UTC](https://discourse.nodered.org/t/and-gate-inputs/4197/24 "2018-10-30T22:16:32Z")

</div>

Did you remember to deploy after you changed the And gate to not restrict to true only?  
Post the flow from the And gate to the led.

---

<div class="post-metadata">

**Author:** ![mustafa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mustafa/32/538_2.png) [@mustafa](https://discourse.nodered.org/u/mustafa)\
**Post date:** [30 October 2018 22:34 UTC](https://discourse.nodered.org/t/and-gate-inputs/4197/25 "2018-10-30T22:34:26Z")

</div>

Yes I did

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [31 October 2018 07:04 UTC](https://discourse.nodered.org/t/and-gate-inputs/4197/26 "2018-10-31T07:04:14Z")

</div>

So are you going to post the flow as I asked?

---

<div class="post-metadata">

**Author:** ![mustafa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mustafa/32/538_2.png) [@mustafa](https://discourse.nodered.org/u/mustafa)\
**Post date:** [31 October 2018 20:26 UTC](https://discourse.nodered.org/t/and-gate-inputs/4197/27 "2018-10-31T20:26:01Z")

</div>

Please see below  
`[{"id":"f19d4784.c85608","type":"rpi-srf","z":"e0495c23.28b4a","name":"Sensor","topic":"Calculate Percentage","pulse":"0.5","pins":"37,38","x":96,"y":580,"wires":[["c80400de.c2aa9"]]},{"id":"c80400de.c2aa9","type":"function","z":"e0495c23.28b4a","name":"Calculate Percentage","func":"var distance = parseInt(msg.payload);\nvar EmptyDist = 100 -distance;\nmsg.payload = parseInt((EmptyDist/100)*100);\n//msg.payload =(100- parseInt((temp/125)*100));\nreturn msg;\n","outputs":1,"noerr":0,"x":297,"y":580,"wires":[["62c1b530.7dc05c","77478fd2.edbd2"]]},{"id":"979e0d81.a137","type":"debug","z":"e0495c23.28b4a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":630,"y":686,"wires":[]},{"id":"62c1b530.7dc05c","type":"ui_gauge","z":"e0495c23.28b4a","name":"","group":"2cad78f1.953508","order":0,"width":"6","height":"7","gtype":"gage","title":"Tank Filled","label":"Percentage","format":"{{value}}","min":0,"max":"100","colors":["#b52100","#e6e600","#42ca38"],"seg1":"","seg2":"","x":647,"y":585,"wires":[]},{"id":"77478fd2.edbd2","type":"and-gate","z":"e0495c23.28b4a","name":"","rules":[{"t":"lt","v":"10","vt":"num","propertyType":"msg","property":"payload","topic":"Calculate Percentage"},{"t":"eq","v":"10","vt":"num","propertyType":"msg","property":"payload","topic":"less"}],"outputTopic":"","gateType":"and","emitOnlyIfTrue":true,"x":361,"y":692,"wires":[["124b17d.1266ee8"]]},{"id":"d651022c.fdd8","type":"inject","z":"e0495c23.28b4a","name":"","topic":"less","payload":"10","payloadType":"num","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":109,"y":726,"wires":[["77478fd2.edbd2"]]},{"id":"124b17d.1266ee8","type":"change","z":"e0495c23.28b4a","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":582,"y":822,"wires":[["979e0d81.a137","e7572495.a25e78"]]},{"id":"e7572495.a25e78","type":"rpi-gpio out","z":"e0495c23.28b4a","name":"","pin":"40","set":true,"level":"0","freq":"","out":"out","x":655,"y":919,"wires":[]},{"id":"2cad78f1.953508","type":"ui_group","z":"","name":"Mustafa","tab":"9f2b0241.7a073","disp":true,"width":"6","collapse":false},{"id":"9f2b0241.7a073","type":"ui_tab","z":"","name":"Home","icon":"my dash","order":2}]`

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [31 October 2018 20:52 UTC](https://discourse.nodered.org/t/and-gate-inputs/4197/28 "2018-10-31T20:52:06Z")

</div>

I asked earlier if you remembered to re-deploy after de-selecting True Restriction in the and gate. I should have asked you to check that you had actually de-selected it. It is still selected in the flow therefore the and gate only ever sends true and never false. De-select True Restriction and I expect it will work much better.  
In addition you have the Change node set to Change msg.payload to true, so even if you had got the and gate right the change node would always change it to true. I cannot understand how you ever thought this might work.  
Look back through the thread and you will see that I suggested you should set it to Move msg.bool To msg.payload and @ukmoose said to do that or an alternative he suggested that would also work, but you have done neither of those.  
So to summarise configure the and gate and change node like this

 ![Screenshot-2018-10-31-20%3A39%3A10](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/be35ddc96218f80527ca63ddbd78fdf27bd28c88.png)

![Screenshot-2018-10-31-20%3A43%3A59](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/63a4c31ff2e048d5f25c7210882a5afcaa10de82.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [31 October 2018 21:15 UTC](https://discourse.nodered.org/t/and-gate-inputs/4197/29 "2018-10-31T21:15:04Z")

</div>

I have just been looking at your flow again. Is all this just to switch the led dependent on whether the value is \< 10? If so then you can just do this

![Screenshot-2018-10-31-21%3A13%3A58](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/eeee3c3d694ce93f9df3cad2a55c29e1365db1fd.png)

```auto
[{"id":"e9d87f6e.d1ad28","type":"change","z":"6dc690a3.1abc88","name":"msg.payload < 10?","rules":[{"t":"set","p":"payload","pt":"msg","to":"msg.payload<10","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":332.5,"y":213,"wires":[["72d8122b.1deae4","27ea98b3.1a14b"]]},{"id":"72d8122b.1deae4","type":"debug","z":"6dc690a3.1abc88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":583.5,"y":278,"wires":[]},{"id":"e11c367c.0afda","type":"function","z":"6dc690a3.1abc88","name":"Calculate Percentage","func":"var distance = parseInt(msg.payload);\nvar EmptyDist = 100 -distance;\nmsg.payload = parseInt((EmptyDist/100)*100);\n//msg.payload =(100- parseInt((temp/125)*100));\nreturn msg;\n","outputs":1,"noerr":0,"x":187,"y":102,"wires":[["8a3ad145.a1948","e9d87f6e.d1ad28"]]},{"id":"8a3ad145.a1948","type":"ui_gauge","z":"6dc690a3.1abc88","name":"","group":"4aeb8be6.5a6c0c","order":0,"width":"6","height":"7","gtype":"gage","title":"Tank Filled","label":"Percentage","format":"{{value}}","min":0,"max":"100","colors":["#b52100","#e6e600","#42ca38"],"seg1":"","seg2":"","x":525,"y":101,"wires":[]},{"id":"27ea98b3.1a14b","type":"rpi-gpio out","z":"6dc690a3.1abc88","name":"","pin":"40","set":true,"level":"0","freq":"","out":"out","x":556,"y":211,"wires":[]},{"id":"4aeb8be6.5a6c0c","type":"ui_group","z":"","name":"Mustafa","tab":"60600a40.f8c2f4","disp":true,"width":"6","collapse":false},{"id":"60600a40.f8c2f4","type":"ui_tab","z":"","name":"Home","icon":"my dash","order":2}]

```

---

<div class="post-metadata">

**Author:** ![mustafa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mustafa/32/538_2.png) [@mustafa](https://discourse.nodered.org/u/mustafa)\
**Post date:** [31 October 2018 21:52 UTC](https://discourse.nodered.org/t/and-gate-inputs/4197/30 "2018-10-31T21:52:54Z")

</div>

Thank you Colin  
it is work perfectly now with modifying the change node.  
sorry for my misunderstanding to your comments and to ukmoose since i'm very new with node red it is just my second experiments with it and i had learn a lot from this case .  
i will try also with your last post  
thank you again and to all other colleagues

[Previous page](https://discourse.nodered.org/t/and-gate-inputs/4197.md?page=1)
