# MQTT garage door opener with Node-RED

**URL:** <https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162>\
**Category:** General\
**Created:** [22 September 2020 06:27 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162 "2020-09-22T06:27:59Z")\
**Posts on this page:** 20\
**Page:** 5

<div class="post-metadata">

**Author:** ![mandeepmails](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mandeepmails/32/6386_2.png) [@mandeepmails](https://discourse.nodered.org/u/mandeepmails)\
**Post date:** [26 September 2020 15:37 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/81 "2020-09-26T15:37:48Z")

</div>

Absolutely right, all correct.

---

<div class="post-metadata">

**Author:** ![mandeepmails](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mandeepmails/32/6386_2.png) [@mandeepmails](https://discourse.nodered.org/u/mandeepmails)\
**Post date:** [26 September 2020 15:50 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/82 "2020-09-26T15:50:14Z")

</div>

> [@Nodi.Rubrum](#):
>
> i) -\> MQTT messages -\>. MQTT Bro

the flow is to accept and respond to MQTT messages.  
i'm trying to keep it simple and under-control  
for example open and close are working.  
problem - but when i have both switches on... motor is stopped and depending on open/close on postion it directly starts....motor stop isn't a problem, but working in wrong direction is.  
hopefully you understand ?

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [26 September 2020 16:06 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/83 "2020-09-26T16:06:48Z")

</div>

I think part of the problem is that the feedback notification of the received message is creating a loop, that maybe why the motor keeps going once it starts.

Create flows that do one thing, and accept results. But don't feed the result back into the same flow. This is to just get the basic functions working, like ON and OFF, etc. Then we can decide how to handle direction control. For example, we might want to create a flow that ONLY lets the direction be set then the motor is OFF. But lets get the basic functions working first with no feed back actions just feed back reporting.

Push ON Button-\>MQTT send-\>Broker-\>MQTT receive-\>Motor On  
Push OFF Button-\>MQTT send-\>Broker-\>MQTT receive-\>Motor Off

The above ignore for now any feedback, just simple, easy actions.

Then create separate flows for getting the feedback

Motor ON-\>MQTT send-\>Broker-\>MQTT receive-\>Debug Message  
Motor OFF-\>MQTT send-\>Broker-\>MQTT receive-\>Debug Message

Notice these are 4 flows that are separate from each other. So there should be no chance of the feedback creating a loop. Get these 4 flows working, and the motor turning on and off as desired. Then once this is working, we can move to the next step(s).

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [27 September 2020 09:22 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/84 "2020-09-27T09:22:02Z")

</div>

It looks as if you are making great progress with the splendid help from @Nodi.Rubrum, so I won't interfere with the flows (as that would possibly confuse the situation).

However, to answer a couple of the questions you raised in this thread.  
You could send a jason string via MQTT to operate the two input pins (C and D) of the L289 H-Bridge.  
Something like...

```auto
msg.payload = {"gateID":"xxxx","cmd":"yyyy"};
return msg;

```

Where "xxxx" can be "south" or "east" and "yyyy" can be "stop", "open" or "close".

Then in your Arduino code you could simply decode these values and operate pins C and D (D8 and D7).  
 ![Screen Shot 09-27-20 at 09.59 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/d/4d12380a7325b02473a535e8b2b8f61023025fc7.jpeg)  
There's a brilliant library called \<ArduinoJson.h\> that makes doing this a breeze. Get version 6.

You could even make the Arduino sketch completely generic and use a 'config.h' to define the gate's location.

As @Nodi.Rubrum said you need to get the four flows working. If once you've done that you need advice with the 'backend', please let me know.

---

<div class="post-metadata">

**Author:** ![mandeepmails](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mandeepmails/32/6386_2.png) [@mandeepmails](https://discourse.nodered.org/u/mandeepmails)\
**Post date:** [27 September 2020 12:27 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/85 "2020-09-27T12:27:04Z")

</div>

Dave,

i totally agree that's the way most people are achieving this i guess. also everyone has their own method and setup functions/sensors/etc.

to avoid any mess i've setup a separate mqtt server and here's my flow.  
all i have on my nodemcu running tasmota firmware

 ![Screenshot 2020-09-27 at 4.25.07 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/399f7d8fb33d29d779181eef8705956132859800.png)

connections are as follows

 ![Untitled Sketch_bb_1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/b/fba8d99160753087e0bab7cf99e5de8cf733d895.png)

NodeMCU L298N(H-Bridge)  
D7 (BROWN-JUMPER) IN2  
D8 (RED-JUMPER) IN1  
GND (YELLOW-JUMPER) GND

From L298N(H-Bridge) 2 wires go out to the motor  
Motor(wires) wire(in middle) L298N(H-Bridge)  
RED black-wire OUT1  
BLUE red-wire OUT2

From 12V power-adapter 2 wires come out  
BLACK connects to GND on L298N(H-Bridge) middle  
RED connects to NC on L298N(H-Bridge) left

* * *

Question - Should i be connecting the L298N(H-Bridge) OUT3 and OUT4 **also** to the same motor ?

Here's my flow still the basic, reason i'm seeking to put the "Gate\<" in off position when i press "Gate\>" button reason, motor rotates in different direction

 ![WhatsApp Image 2020-09-27 at 5.23.46 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b6ed1b1bd9829938ea91b081f64d887b17222473.jpeg)

```auto
[{"id":"a14b09c4.ca5f18","type":"ui_switch","z":"10b29368.6f662d","name":"PUMP","label":"WATER PUMP","tooltip":"","group":"1609fe57.dc1592","order":1,"width":"4","height":"2","passthru":true,"decouple":"false","topic":"/home/Utanki","style":"","onvalue":"on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"off","offvalueType":"str","officon":"","offcolor":"","x":270,"y":80,"wires":[["f654a853.6e194"]],"icon":"font-awesome/fa-bolt","info":"# मोटर"},{"id":"1609fe57.dc1592","type":"ui_group","z":"","name":"PUMP","tab":"2a9f0caf.995024","order":1,"disp":true,"width":"8","collapse":false},{"id":"2a9f0caf.995024","type":"ui_tab","z":"","name":"Home","icon":"home","order":1,"disabled":false,"hidden":false}]

```

Believe me, when i comes to switch on and off the lights, i am okay with that. it's just the motor i'm dealing with for the first time. 😀 Motors are painful

---

<div class="post-metadata">

**Author:** ![mandeepmails](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mandeepmails/32/6386_2.png) [@mandeepmails](https://discourse.nodered.org/u/mandeepmails)\
**Post date:** [27 September 2020 12:35 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/86 "2020-09-27T12:35:37Z")

</div>

Not sure if this will be easy  
i was searching for the code and got this github project, which i really find exactly where i would like to get. but this uses platformIO

> **[GitHub - bradc87/GarageDoorSensor: Firmware for IOT Garage Door Sensor](https://github.com/bradc87/GarageDoorSensor)**
>
> Firmware for IOT Garage Door Sensor. Contribute to bradc87/GarageDoorSensor development by creating an account on GitHub.

also has provided the youtube guides that i've watched couple times

[![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/3/c3a1c3d620a2a02a773d5e43f24ba944951c5d92.jpeg "$15 MQTT Garage Door Opener (Part 1)") ](https://www.youtube.com/watch?v=6VdeXgcSuU4)

[![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/7/071a7f14403c1b74137196bfccb943a522445999.jpeg "MQTT Garage Door Opener Firmware Tour (Part 2)") ](https://www.youtube.com/watch?v=tHlIgSUW8cc)

but i get this error

 ![](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/ae8e41c5fced6843f2564780918b4753b7ff495a.png)

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [27 September 2020 16:14 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/87 "2020-09-27T16:14:06Z")

</div>

Although you don't show it on your drawing, I assume you have connected the GND of the H-Bridge to GND on the NodeMCU ???

The datasheet says the **maximum current load MUST NOT exceed 2 amps** , but you can increase this by connecting Ch-1 with Ch-4 and Ch-2 with Ch-3 and pairing-up the appropriate IN pins.  
I suggest you check the datasheet for full details.

I've not tried the L298N with an ESP8266 or a Raspberry Pi. These devices have 3v3 logic levels, whereas the H-Bridge uses 5v logic. It should work as the logic-high level from the microcontroller is higher than the lowest value for VinH for the H-Bridge. Someone on the forum may be able to confirm this for you.

Last point, I've not used Lua or Tasmota firmware with the NodeMCU, although I have uploaded an Arduino **test sketch** to one of my Wemos D1 Minis this afternoon and found the D8 and D7 outputs work fine.

---

<div class="post-metadata">

**Author:** ![mandeepmails](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mandeepmails/32/6386_2.png) [@mandeepmails](https://discourse.nodered.org/u/mandeepmails)\
**Post date:** [27 September 2020 16:31 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/88 "2020-09-27T16:31:05Z")

</div>

> [@dynamicdave](#):
>
> These devices have 3v3 logic levels, whereas the H-Bridge uses 5v logic

Totally Agreed, Dave. confirmed.

My 5 wemos D1 mini's are arriving on Tuesday, NodeMCU is good for 3.3V for 5V wemos D1 mini's are getting preferred.

i've got rid of tasmota-firmware from the NodeMCU and sorted out the issue with the platformIO config errors. Also have been able to rotate the motor just fine. working with node-red flow now to publish to the topics to open/close/stop etc.

Nodered remains the brain.. and i feel comfortable with it.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [27 September 2020 17:09 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/89 "2020-09-27T17:09:34Z")

</div>

I've just found an H-Bridge and lashed it up. It works fine. I had to use D7 and D6 (rather than D8 and D7) as D8 is used during boot-up and affects the motor. If it helps, here's my Node-RED test flow.

 ![Screen Shot 09-27-20 at 06.24 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/4/345475ce88089b13050b9893867338ec566bf2a6.jpeg)

```auto
[{"id":"e3cdd336.8c8e5","type":"mqtt in","z":"99e54d66.bb9098","name":"","topic":"esp/test/#","qos":"2","datatype":"auto","broker":"a4345f1b.854f48","x":160,"y":400,"wires":[["40f52a29.0c24cc"]]},{"id":"40f52a29.0c24cc","type":"debug","z":"99e54d66.bb9098","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":350,"y":400,"wires":[]},{"id":"abbb7b37.45e358","type":"mqtt out","z":"99e54d66.bb9098","name":"","topic":"esp/test","qos":"","retain":"","broker":"a4345f1b.854f48","x":620,"y":600,"wires":[]},{"id":"f1699e9.6a366e","type":"inject","z":"99e54d66.bb9098","name":"Trigger","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":130,"y":480,"wires":[["ff7b0c39.2ace"]]},{"id":"ff7b0c39.2ace","type":"function","z":"99e54d66.bb9098","name":"South gate, OPEN","func":"msg.payload = {\"gateID\":\"south\",\"cmd\":\"open\"};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":480,"wires":[["abbb7b37.45e358"]]},{"id":"e5d2aee1.bf358","type":"function","z":"99e54d66.bb9098","name":"South gate, CLOSE","func":"msg.payload = {\"gateID\":\"south\",\"cmd\":\"close\"};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":520,"wires":[["abbb7b37.45e358"]]},{"id":"6da00565.dd393c","type":"function","z":"99e54d66.bb9098","name":"South gate, STOP","func":"msg.payload = {\"gateID\":\"south\",\"cmd\":\"stop\"};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":560,"wires":[["abbb7b37.45e358"]]},{"id":"470fb7fc.fddf3","type":"inject","z":"99e54d66.bb9098","name":"Trigger","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":130,"y":520,"wires":[["e5d2aee1.bf358"]]},{"id":"41b4b16f.041ef8","type":"inject","z":"99e54d66.bb9098","name":"Trigger","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":130,"y":560,"wires":[["6da00565.dd393c"]]},{"id":"d6f7ef01.e2d2d8","type":"function","z":"99e54d66.bb9098","name":"East gate, Open","func":"msg.payload = {\"gateID\":\"east\",\"cmd\":\"open\"};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":640,"wires":[["abbb7b37.45e358"]]},{"id":"c61bdced.cb5a1","type":"inject","z":"99e54d66.bb9098","name":"Trigger","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":130,"y":640,"wires":[["d6f7ef01.e2d2d8"]]},{"id":"6b109259.04499c","type":"function","z":"99e54d66.bb9098","name":"East gate, Close","func":"msg.payload = {\"gateID\":\"east\",\"cmd\":\"close\"};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":680,"wires":[["abbb7b37.45e358"]]},{"id":"cde5fabd.46ec","type":"inject","z":"99e54d66.bb9098","name":"Trigger","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":130,"y":680,"wires":[["6b109259.04499c"]]},{"id":"c203ea2c.60ae","type":"function","z":"99e54d66.bb9098","name":"East gate, STOP","func":"msg.payload = {\"gateID\":\"east\",\"cmd\":\"stop\"};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":720,"wires":[["abbb7b37.45e358"]]},{"id":"99367551.a7838","type":"inject","z":"99e54d66.bb9098","name":"Trigger","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":130,"y":720,"wires":[["c203ea2c.60ae"]]},{"id":"19bb5945.c02df7","type":"comment","z":"99e54d66.bb9098","name":"Change IP address and topic to match your broker","info":"","x":760,"y":560,"wires":[]},{"id":"a4345f1b.854f48","type":"mqtt-broker","z":"","name":"RPi-146","broker":"192.168.1.146","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<div class="post-metadata">

**Author:** ![mandeepmails](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mandeepmails/32/6386_2.png) [@mandeepmails](https://discourse.nodered.org/u/mandeepmails)\
**Post date:** [27 September 2020 17:18 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/90 "2020-09-27T17:18:05Z")

</div>

Dave,

i think we're close 😀

i've connected a relay now with the nodemcu running the platformIO code  
And i'm using syslog server to monitor the logs  
PINS in use currently  
NodeMCU Relay  
VIN orange VCC  
GND white IN1  
D6 yellow IN2  
D2 black GND (when i remove this cable, status changes from close to open) shows on syslog and relay turns on and off

i think issue is with the flow still, if you can look at it once

 ![Screenshot 2020-09-27 at 10.06.52 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/38e6576ffc2259bbfd0204050c4c6be44c621830.png)

```auto
[{"id":"10b29368.6f662d","type":"tab","label":"Home","disabled":false,"info":""},{"id":"f654a853.6e194","type":"Sonoff device Enhanced","z":"10b29368.6f662d","mode":"0","broker":"da22485c.d50c","device":"Utanki","name":"Utanki","onValue":"ON","offValue":"OFF","toggleValue":"toggle","cmdPrefix":"cmnd","statPrefix":"stat","telePrefix":"tele","x":530,"y":80,"wires":[[]]},{"id":"a14b09c4.ca5f18","type":"ui_switch","z":"10b29368.6f662d","name":"PUMP","label":"WATER PUMP","tooltip":"","group":"1609fe57.dc1592","order":1,"width":"4","height":"2","passthru":true,"decouple":"false","topic":"/home/Utanki","style":"","onvalue":"on","onvalueType":"str","onicon":"","oncolor":"","offvalue":"off","offvalueType":"str","officon":"","offcolor":"","x":270,"y":80,"wires":[["f654a853.6e194"]],"icon":"font-awesome/fa-bolt","info":"# मोटर"},{"id":"f20926e6.a17c28","type":"mqtt out","z":"10b29368.6f662d","name":"","topic":"/controls/garagedoor","qos":"","retain":"","broker":"aed54839.77f6a8","x":510,"y":420,"wires":[]},{"id":"c4f05f26.6e549","type":"mqtt out","z":"10b29368.6f662d","name":"","topic":"/devices/remotepower","qos":"","retain":"","broker":"aed54839.77f6a8","x":510,"y":480,"wires":[]},{"id":"e7d8579a.ef54b","type":"inject","z":"10b29368.6f662d","name":"1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":380,"wires":[["f20926e6.a17c28","11ef002b.7cb64"]]},{"id":"7d3e4c41.a55f64","type":"mqtt in","z":"10b29368.6f662d","name":"","topic":"sensors/doors/garage","qos":"2","datatype":"auto","broker":"aed54839.77f6a8","x":200,"y":260,"wires":[["11ef002b.7cb64"]]},{"id":"9f650321.23a9c","type":"inject","z":"10b29368.6f662d","name":"0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":420,"wires":[["f20926e6.a17c28","11ef002b.7cb64"]]},{"id":"c0822233.367b08","type":"inject","z":"10b29368.6f662d","name":"0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":210,"y":460,"wires":[["c4f05f26.6e549","11ef002b.7cb64"]]},{"id":"11ef002b.7cb64","type":"debug","z":"10b29368.6f662d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":300,"wires":[]},{"id":"da22485c.d50c","type":"mqtt-broker","z":"","name":"pi","broker":"192.168.1.11","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"1609fe57.dc1592","type":"ui_group","z":"","name":"PUMP","tab":"2a9f0caf.995024","order":1,"disp":true,"width":"8","collapse":false},{"id":"aed54839.77f6a8","type":"mqtt-broker","z":"","name":"192.168.1.11","broker":"192.168.1.11","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"2a9f0caf.995024","type":"ui_tab","z":"","name":"Home","icon":"home","order":1,"disabled":false,"hidden":false}]

```

[main-cpp.txt](https://discourse.nodered.org/uploads/short-url/7jpuS1tIjsZDHpDA9gB4cJYnUZd.txt) (6.2 KB)

---

<div class="post-metadata">

**Author:** ![mandeepmails](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mandeepmails/32/6386_2.png) [@mandeepmails](https://discourse.nodered.org/u/mandeepmails)\
**Post date:** [27 September 2020 17:38 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/91 "2020-09-27T17:38:19Z")

</div>

share the connections picture, if possible

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [27 September 2020 19:33 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/92 "2020-09-27T19:33:34Z")

</div>

Here are my Arduino files to handle receiving a MQTT message from Node-RED and driving the L298N H-Bridge which is connected to pins D7 and D6 on the Wemos. I've used the blue builtin LED to indicate when the motor is turning. All the user definitions are in config.h

[main-cpp.txt](https://discourse.nodered.org/uploads/short-url/prvsIIW3gQtwJbjwwV4X8uXMrzs.txt) (3.8 KB) \<\<\< This file is suitable for 'platformIO'

[mqtt\_sub\_pub.txt](https://discourse.nodered.org/uploads/short-url/1VdVTMqrx8AG7col0elM5aqjeox.txt) (3.9 KB) \<\<\<\<\<\< Change the filename to _mqtt\_sub\_pub.ino_

[config.txt](https://discourse.nodered.org/uploads/short-url/A3e1NPYev9KVrHHdguulvILRThs.txt) (851 Bytes) \<\<\<\<\<\< Change the filename to _config.h_

I've used the Arduino IDE to write, compile and upload the code.  
You will need to install the ArduinoJson library version-6 \<\<\< Make sure it's version-6  
This is needed to deserialize the Json string and extract the values for gateID and cmd.

PS:  
Do you know the voltage and current requirements of the actual motor you will be using to operate the gate, as the L298N is only intended for low current and low voltage operation? (e.g. robots, toy model trains)

PPS:  
Just noticed you're using PlatformIO. I must read-up on that as it looks really interesting and productive.

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [27 September 2020 21:21 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/93 "2020-09-27T21:21:02Z")

</div>

There is one more issue with motors.... noise. I have on every motor I have used, soldered a capacitor across the motor leads (+ and -) which seems odd until you realize it GREATLY removes electromagnetic noise, which can lead to all kinds issues. Wires and input and outputs randomly fail, etc. So if you get some strange behavior, this might be part of the issue. I had a simple motor project where I also had a input sensor, and the input sensor was sending junk results, but it only happened when the motor was on. That was the clue.

Here is an excellent discussion on the issue and how to resolve it, if it is happening...

> **[Pololu - 9. Dealing with Motor Noise](https://www.pololu.com/docs/0J15/9)**
>
> Detailed information about the 3pi Robot, Orangutan SV-328/168 and LV-168, and Baby Orangutan B motor drivers, including truth tables and sample code.

---

<div class="post-metadata">

**Author:** ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)\
**Post date:** [27 September 2020 21:25 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/94 "2020-09-27T21:25:56Z")

</div>

All the NodeMCU or ESP stuff I have done, I have done in straight C, since I have long history with C and C# in .NET. But the more I see of the ESP Home and other canned firmware images, the more I am thinking I need to spend some serious time with same.

---

<div class="post-metadata">

**Author:** ![mandeepmails](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mandeepmails/32/6386_2.png) [@mandeepmails](https://discourse.nodered.org/u/mandeepmails)\
**Post date:** [28 September 2020 08:21 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/95 "2020-09-28T08:21:27Z")

</div>

funny thing about me that professionally i'm a Network and Voip Engineer have more than a dozen cisco certifications and design contact centers, architecting the infrstatructure etc but i never did software and programming stuff ever.

For contact center web/call/chat i did do some flows very much similar to nodered that encouraged me to use basic stuff.

all this i'm doing is about my passion and learning curve. success of this DIY project should give me comfort and satisfaction i feel. Arduino uno as a device had no wifi plus i don't personally like battery operated remotes to open the gate especially when WIFI has become a very basic. with ESP8266 i guess it's endless with all your background skills you can use.

in my case again neither i have programming skills nor the electronics but with platformIO the way it can tell the minor issues with code and libraries so helpful, in no time anyone can pick this up and do what they want.

i am fascinated with the ideas like automatic-blinds, water-tank-alarms and sliding gates, totally under control

---

<div class="post-metadata">

**Author:** ![mandeepmails](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mandeepmails/32/6386_2.png) [@mandeepmails](https://discourse.nodered.org/u/mandeepmails)\
**Post date:** [28 September 2020 08:23 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/96 "2020-09-28T08:23:07Z")

</div>

how about sharing connections basic pic or a rough drawing will be cool

---

<div class="post-metadata">

**Author:** ![mandeepmails](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mandeepmails/32/6386_2.png) [@mandeepmails](https://discourse.nodered.org/u/mandeepmails)\
**Post date:** [28 September 2020 08:46 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/97 "2020-09-28T08:46:18Z")

</div>

Dave,

About the motor i'm trying to stick to car power-window motor or wiper-motor.  
Agreed no one uses the L298N H-Bridge but i was just trying to get this easily.

with relays i've seen people again got their own logics, for example some are able to do this open/close/stop gate with single relay, some use 2 in case they put sensors and want to break it down into easy pieces and some even use 3...best approach i like the guy is using just a basic-sonoff. 😄

---

<div class="post-metadata">

**Author:** ![mandeepmails](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mandeepmails/32/6386_2.png) [@mandeepmails](https://discourse.nodered.org/u/mandeepmails)\
**Post date:** [28 September 2020 09:14 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/98 "2020-09-28T09:14:50Z")

</div>

please tell me if this is correct, what i'm missing

 ![sorting-connections](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/1/b1f6845757a92005f731d9499367d9632e5dd01f.png)

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [28 September 2020 10:25 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/99 "2020-09-28T10:25:55Z")

</div>

You have the grey and yellow wires incorrectly wired on Relay 2. They need to be swapped over.  
As you have them wired at the moment the motor will only turn in one direction.  
I'm off out so don't have the time to draw a diagram for you. I'll do it when I return this evening.

---

<div class="post-metadata">

**Author:** ![mandeepmails](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mandeepmails/32/6386_2.png) [@mandeepmails](https://discourse.nodered.org/u/mandeepmails)\
**Post date:** [28 September 2020 12:38 UTC](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162/100 "2020-09-28T12:38:40Z")

</div>

Thanks Dave,

it appears that didn't work either, i tried swapping relay 2 A and C  
grey into C currently  
yellow into A currently  
i think that's what you suggested but something's still wrong

[Previous page](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162.md?page=4)

[Next page](https://discourse.nodered.org/t/mqtt-garage-door-opener-with-node-red/33162.md?page=6)
