# I need help to control a servo from a node-red dashboard with esp-32

**URL:** <https://discourse.nodered.org/t/i-need-help-to-control-a-servo-from-a-node-red-dashboard-with-esp-32/74711>\
**Category:** Dashboard\
**Created:** [4 February 2023 20:32 UTC](https://discourse.nodered.org/t/i-need-help-to-control-a-servo-from-a-node-red-dashboard-with-esp-32/74711 "2023-02-04T20:32:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Surfb](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@Surfb](https://discourse.nodered.org/u/Surfb)\
**Post date:** [4 February 2023 20:32 UTC](https://discourse.nodered.org/t/i-need-help-to-control-a-servo-from-a-node-red-dashboard-with-esp-32/74711/1 "2023-02-04T20:32:16Z")

</div>

I'm trying to control a servo from a node-red but I can't, I hope you can help me, thanks

---

<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:** [4 February 2023 21:23 UTC](https://discourse.nodered.org/t/i-need-help-to-control-a-servo-from-a-node-red-dashboard-with-esp-32/74711/2 "2023-02-04T21:23:05Z")

</div>

You will have to give us a lot more information. What hardware is node-red running on and how have you connected the servo? Also what type of servo is it?

---

<div class="post-metadata">

**Author:** ![Surfb](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@Surfb](https://discourse.nodered.org/u/Surfb)\
**Post date:** [4 February 2023 23:02 UTC](https://discourse.nodered.org/t/i-need-help-to-control-a-servo-from-a-node-red-dashboard-with-esp-32/74711/3 "2023-02-04T23:02:40Z")

</div>

node-red is installed in aws the servo is connected to an esp-32 board and is a sg-90 servo

---

<div class="post-metadata">

**Author:** ![Surfb](https://avatars.discourse-cdn.com/v4/letter/s/4af34b/32.png) [@Surfb](https://discourse.nodered.org/u/Surfb)\
**Post date:** [4 February 2023 23:06 UTC](https://discourse.nodered.org/t/i-need-help-to-control-a-servo-from-a-node-red-dashboard-with-esp-32/74711/4 "2023-02-04T23:06:29Z")

</div>

I want to use mqtt communication with a broker to communicate from esp to node-red

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [4 February 2023 23:29 UTC](https://discourse.nodered.org/t/i-need-help-to-control-a-servo-from-a-node-red-dashboard-with-esp-32/74711/5 "2023-02-04T23:29:20Z")

</div>

That should be possible. You need to add code to the Esp-32 program to subscribe to mqtt topics. You should be able to find instructions for doing that on the internet.

You will also have to set up your NR flow to publish information that the esp-32 will use to deal with the servo.

---

<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:** [5 February 2023 11:42 UTC](https://discourse.nodered.org/t/i-need-help-to-control-a-servo-from-a-node-red-dashboard-with-esp-32/74711/6 "2023-02-05T11:42:50Z")

</div>

I haven't used the ESP-32, just the ESP8266 in the form of the Wemos D1 Mini flashed with ESPeasy.  
Here's an example of a very simple flow sending position commands to a servo motor via MQTT.  
 ![servo_flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/9/c98ac6ada28cd9aa79fef7d4c29869c0fb5ae615.png)

```auto
[{"id":"6c871500.1021ec","type":"tab","label":"Servo motor","disabled":false,"info":"","env":[]},{"id":"ba80606d.5a80e","type":"inject","z":"6c871500.1021ec","name":"Move to zero degrees","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"servo,2,13,0","payloadType":"str","x":280,"y":200,"wires":[["209dbef2.233582"]]},{"id":"209dbef2.233582","type":"mqtt out","z":"6c871500.1021ec","name":"","topic":"node36/cmd","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"5ef29389.24415c","x":510,"y":200,"wires":[]},{"id":"a2fd2b39.2124b8","type":"inject","z":"6c871500.1021ec","name":"Move to 45 degrees","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"servo,2,13,45","payloadType":"str","x":270,"y":260,"wires":[["209dbef2.233582"]]},{"id":"68cf7cd2.366714","type":"inject","z":"6c871500.1021ec","name":"Move to 90 degrees","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"servo,2,13,90","payloadType":"str","x":270,"y":320,"wires":[["209dbef2.233582"]]},{"id":"4920b85ea56eb602","type":"comment","z":"6c871500.1021ec","name":"Need to set your node ID and broker IP address","info":"","x":500,"y":160,"wires":[]},{"id":"5ef29389.24415c","type":"mqtt-broker","name":"","broker":"192.168.1.138","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

```

You will need to set the node ID for your device as well as the IP address of your broker.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [7 March 2023 11:43 UTC](https://discourse.nodered.org/t/i-need-help-to-control-a-servo-from-a-node-red-dashboard-with-esp-32/74711/7 "2023-03-07T11:43:42Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
