# Servo Motor with fixed angle

**URL:** <https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678>\
**Category:** General\
**Created:** [5 March 2020 21:02 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678 "2020-03-05T21:02:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![usmanEmder](https://avatars.discourse-cdn.com/v4/letter/u/977dab/32.png) [@usmanEmder](https://discourse.nodered.org/u/usmanEmder)\
**Post date:** [5 March 2020 21:02 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/1 "2020-03-05T21:02:49Z")

</div>

Hi. I am making a smart home prototype where I connected the door with Servo-motor and I wanna rotate the motor on one fix position (95°) then it can open my door. Now I switch from the dashboard and connect it with GPIO out (PWM) with frequency 100 Hz and it is rotating 180°. I think I need to add on function node between them but I am not sure what I need to write in it. Anyone can suggest to me.  
Regards,

---

<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:** [5 March 2020 21:23 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/2 "2020-03-05T21:23:28Z")

</div>

It is not really clear what you want. You say you only want the motor positioned at one position (95°) but that doesn't make sense. What exactly are you trying to do with the servo?

---

<div class="post-metadata">

**Author:** ![usmanEmder](https://avatars.discourse-cdn.com/v4/letter/u/977dab/32.png) [@usmanEmder](https://discourse.nodered.org/u/usmanEmder)\
**Post date:** [5 March 2020 21:32 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/3 "2020-03-05T21:32:48Z")

</div>

Well, first of all, thanks for your response.  
I connected motor with door and I need to open and the door while at 95° of my door will completely open then I wanna delay for 5 seconds and then the door will close at 0°. Actually, I am using RFID Module and I wanna connect it with the motor. So, after scanning the card the motor will open the door.

---

<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:** [5 March 2020 21:46 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/4 "2020-03-05T21:46:55Z")

</div>

OK, how far have you got? Are you able to control the position by sending the gpio node values between 0 and 100 as described in the description?

---

<div class="post-metadata">

**Author:** ![usmanEmder](https://avatars.discourse-cdn.com/v4/letter/u/977dab/32.png) [@usmanEmder](https://discourse.nodered.org/u/usmanEmder)\
**Post date:** [5 March 2020 21:51 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/5 "2020-03-05T21:51:23Z")

</div>

Yes, you mean to say the frequency?

---

<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:** [5 March 2020 22:07 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/6 "2020-03-05T22:07:04Z")

</div>

In the information tab it tells you what it expects in msg.payload. In particular it says  
"PWM mode - expects an input value of a number 0 - 100. It can be floating point."  
So you send the node a message with a value between 0 and 100 and that should send the servo to the appropriate position. To test either connect some inject nodes to it or wire it to a dashboard slider set to generate 0 to 100 and see what happens.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [5 March 2020 22:17 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/7 "2020-03-05T22:17:54Z")

</div>

Slight aside - the pi-gpiod node [https://flows.nodered.org/node/node-red-node-pi-gpiod](https://flows.nodered.org/node/node-red-node-pi-gpiod) - provides much better timing accuracy for servo positioning (for normal RC model servos), but does need some more setting up.

---

<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:** [5 March 2020 22:23 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/8 "2020-03-05T22:23:50Z")

</div>

One other thing to keep in mind, a servo motor can usually only turn 90 degrees in either direction for a total of 180 degree movement. Therefore you will probably have to set it up so home as -45 and open as 50 to get your 95 degree swing.

---

<div class="post-metadata">

**Author:** ![usmanEmder](https://avatars.discourse-cdn.com/v4/letter/u/977dab/32.png) [@usmanEmder](https://discourse.nodered.org/u/usmanEmder)\
**Post date:** [25 March 2020 11:32 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/9 "2020-03-25T11:32:04Z")

</div>

Thanks for your reply, I didn`t get your point how I can set the home and where I need to set 50 degree

---

<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:** [25 March 2020 11:45 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/10 "2020-03-25T11:45:16Z")

</div>

First find the range of numbers that gives you the angles you need.  
Next what signal or input are you using to decide what position you want it set to?

---

<div class="post-metadata">

**Author:** ![usmanEmder](https://avatars.discourse-cdn.com/v4/letter/u/977dab/32.png) [@usmanEmder](https://discourse.nodered.org/u/usmanEmder)\
**Post date:** [25 March 2020 11:52 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/11 "2020-03-25T11:52:01Z")

</div>

I am using range and GPIO out nodes but it is not work:

```auto
[{"id":"8777601e.137e5","type":"range","z":"675ddecd.d7a01","minin":"0","maxin":"100","minout":"100","maxout":"0","action":"scale","round":false,"property":"payload","name":"","x":380,"y":300,"wires":[["d11fc2.f6d1204"]]},{"id":"d11fc2.f6d1204","type":"rpi-gpio out","z":"675ddecd.d7a01","name":"","pin":"40","set":"","level":"0","freq":"100","out":"pwm","x":560,"y":340,"wires":[]},{"id":"696237de.1eb568","type":"inject","z":"675ddecd.d7a01","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":280,"wires":[["8777601e.137e5"]]}]

```

---

<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:** [25 March 2020 11:57 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/12 "2020-03-25T11:57:50Z")

</div>

Please read this link and edit your previous post so that we can import the flow.  
Also tell us what about it does not work.

> [@How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506):
>
> To share code samples or flow json in this forum, you need to take care to format it properly so that it is displayed correctly. The easiest way to do that is to click the 'Preformatted Text' button in the toolbar: [image] Then paste in your code or flow json. You should end up with three back-tick characters - ``` - on their own line before and after the code. On standard US English keyboards, this is on the same key as the ~ character. Using the backticks will ens…

---

<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:** [25 March 2020 12:09 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/13 "2020-03-25T12:09:17Z")

</div>

And what does not work? Your flow only has the the nodes to inject one value (1).

---

<div class="post-metadata">

**Author:** ![usmanEmder](https://avatars.discourse-cdn.com/v4/letter/u/977dab/32.png) [@usmanEmder](https://discourse.nodered.org/u/usmanEmder)\
**Post date:** [25 March 2020 12:12 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/14 "2020-03-25T12:12:22Z")

</div>

Actually, I mounted Servo motor with smart home door and wanna to open and close the door with servo movement.

---

<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:** [25 March 2020 12:14 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/15 "2020-03-25T12:14:31Z")

</div>

So if you put different values in inject nodes are you able to make it move the right points?

---

<div class="post-metadata">

**Author:** ![usmanEmder](https://avatars.discourse-cdn.com/v4/letter/u/977dab/32.png) [@usmanEmder](https://discourse.nodered.org/u/usmanEmder)\
**Post date:** [25 March 2020 12:17 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/16 "2020-03-25T12:17:44Z")

</div>

Different values in inject node means. Yes, I know I can add 0 to 9 as mention payload number.

---

<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:** [25 March 2020 13:30 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/17 "2020-03-25T13:30:35Z")

</div>

So what inject values give you the two positions from the servo that you need?

---

<div class="post-metadata">

**Author:** ![usmanEmder](https://avatars.discourse-cdn.com/v4/letter/u/977dab/32.png) [@usmanEmder](https://discourse.nodered.org/u/usmanEmder)\
**Post date:** [25 March 2020 15:09 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/18 "2020-03-25T15:09:03Z")

</div>

Actually, in my case, I wanna open and close the servo motor mounted door with RFID ( which is already connected and working fine). And I wanna node as shown in picture. ![error](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/169c108d23761bf2d4eeed17f898964a518f57a3.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:** [25 March 2020 15:20 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/19 "2020-03-25T15:20:43Z")

</div>

So we need to know two things.

1. The answer to my previous question, which you haven't answered, do you know what values you need to send to the servo node?
2. Assuming you do know (or have now worked it out) what are they
3. Put a debug node showing the output of the RFID node and show us what it shows for the open and closed position.

---

<div class="post-metadata">

**Author:** ![usmanEmder](https://avatars.discourse-cdn.com/v4/letter/u/977dab/32.png) [@usmanEmder](https://discourse.nodered.org/u/usmanEmder)\
**Post date:** [25 March 2020 15:26 UTC](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678/20 "2020-03-25T15:26:24Z")

</div>

Well, I am not sure what values I need to assign and where I need to assign for Servo. But physically, I need 0 to 95°.

[Next page](https://discourse.nodered.org/t/servo-motor-with-fixed-angle/22678.md?page=2)
