# Use a servo controlled valve as the part cooling fan?

**URL:** <https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983>\
**Category:** General Discussion\
**Created:** [February 7, 2022, 2:18pm UTC](https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983 "2022-02-07T14:18:39Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![amv101](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@amv101](https://klipper.discourse.group/u/amv101)\
**Post date:** [February 7, 2022, 2:18pm UTC](https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983/1 "2022-02-07T14:18:39Z")

</div>

Greetings! I have an air pump that I use for remote hotend and part cooling on my high temp printer. Currently, the pump output is regulated by the part fan output.

I was wanting to use a servo controlled valve so that I can use an air tank. When the part cooling fan is at 0%, then the valve would be closed with the servo angle 0. When the fan is at 50% the servo angle would be 90, and with the fan at 100% the servo angle would be 180. This is just an example for reference.

Is this something that can be done in Klipper with the servo or PWM controls?

---

<div class="post-metadata">

**Author:** ![w00sh](https://avatars.discourse-cdn.com/v4/letter/w/b5ac83/32.png) [@w00sh](https://klipper.discourse.group/u/w00sh)\
**Post date:** [February 7, 2022, 4:50pm UTC](https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983/2 "2022-02-07T16:50:13Z")

</div>

Try

> Additional servos, LEDs, buttons, and other pins

[https://www.klipper3d.org/Config\_Reference.html](https://www.klipper3d.org/Config_Reference.html)

Btw, have you posted anywehere how you’re cooling the hot-end? I think compressed air is the way to go, but have not tried yet.

---

<div class="post-metadata">

**Author:** ![Sineos](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/sineos/32/18_2.png) [@Sineos](https://klipper.discourse.group/u/Sineos)\
**Post date:** [February 7, 2022, 6:14pm UTC](https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983/3 "2022-02-07T18:14:06Z")

</div>

Basically quite easy:

```auto
[servo myServo]
pin: myPin
initial_angle: 0
maximum_servo_angle = 90
minimum_pulse_width = 0.001
maximum_pulse_width = 0.002

```

Then control it with:

```auto
SET_SERVO SERVO=myServo ANGLE=90

```

---

<div class="post-metadata">

**Author:** ![amv101](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@amv101](https://klipper.discourse.group/u/amv101)\
**Post date:** [February 7, 2022, 7:17pm UTC](https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983/4 "2022-02-07T19:17:18Z")

</div>

Thanks for the help. I am new to Klipper, coming from Marlin.

I understand for the most part what you described. How would I control the servo in Klipper as the part cooling fan?

---

<div class="post-metadata">

**Author:** ![amv101](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@amv101](https://klipper.discourse.group/u/amv101)\
**Post date:** [February 7, 2022, 7:19pm UTC](https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983/5 "2022-02-07T19:19:51Z")

</div>

Thanks! I dont have anything posted. I am just using a diaphragm pump (Berg style) mounted to the outside frame, with some silicone tubing going to a custom V6 hotend fan shroud I designed.

---

<div class="post-metadata">

**Author:** ![jjarosz](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@jjarosz](https://klipper.discourse.group/u/jjarosz)\
**Post date:** [February 8, 2022, 12:27pm UTC](https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983/6 "2022-02-08T12:27:21Z")

</div>

You could build a “delayed gcode macro” that referenced the fan speed (0-255) and convert it to the stepper angle (0-180), then modify the stepper angle automatically.

---

<div class="post-metadata">

**Author:** ![jjarosz](https://avatars.discourse-cdn.com/v4/letter/j/22d042/32.png) [@jjarosz](https://klipper.discourse.group/u/jjarosz)\
**Post date:** [February 8, 2022, 1:49pm UTC](https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983/7 "2022-02-08T13:49:49Z")

</div>

Klipper reports the fan speed between 0.0 and 1.0.

Once you setup your servo like @Sineos posted, then you can use a combination of gcode\_macro and delayed\_gcode to automate the fan speed to servo angle with something like this:

```auto
[delayed_gcode set_stepper_angle_timer]
initial_duration: 1
gcode:
    # Delayed gcode will poll every second and update the servo angle
    SET_STEPPER_ANGLE
    UPDATE_DELAYED_GCODE ID=set_stepper_angle_timer DURATION=1

[gcode_macro SET_STEPPER_ANGLE]
gcode:
    # Set the servo angle based on the part cooling fan speed
    # Fan = 0.0, servo angle = 0
    # Fan = 0.5, servo angle = 90
    # Fan = 1.0, servo angle = 180
    SET_SERVO SERVO=myServo ANGLE={% printer.fan.speed * 180 %}

```

I might not have the Jinja2 syntax correct` {% printer.fan.speed * 180 %}`, and if you are not using the standard part cooling fan, that will need to be adjusted as well.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Sineos](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/sineos/32/18_2.png) [@Sineos](https://klipper.discourse.group/u/Sineos)\
**Post date:** [February 8, 2022, 3:58pm UTC](https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983/8 "2022-02-08T15:58:59Z")

</div>

Nice ideas @jjarosz  
Another approach could be to define a custom M106 macro (no idea if this would work) or a completely new command and post-process your GCODE file to use the new command instead of the regular M106.

Quite specific requirement, so probably a lot tinkering.

---

<div class="post-metadata">

**Author:** ![amv101](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@amv101](https://klipper.discourse.group/u/amv101)\
**Post date:** [February 8, 2022, 7:55pm UTC](https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983/9 "2022-02-08T19:55:45Z")

</div>

@jjarosz Thanks for the help! I will try to get it working based on your suggestion. I am new to Klipper and havent tried any of the custom macro stuff yet so this should be a fun rabbit hole. Thanks again.

---

<div class="post-metadata">

**Author:** ![ssackett](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/ssackett/32/769_2.png) [@ssackett](https://klipper.discourse.group/u/ssackett)\
**Post date:** [May 5, 2022, 7:15pm UTC](https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983/10 "2022-05-05T19:15:44Z")

</div>

Hi, I am trying to understand the configuration syntax and whether it provides a way to tell Klipper that I am using a [fan] that is controlled like a [servo] rather than by PWM.

For example something like:

[servo myservo]  
…

[fan myservo]  
…

---

<div class="post-metadata">

**Author:** ![Chief](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/chief/32/3251_2.png) [@Chief](https://klipper.discourse.group/u/Chief)\
**Post date:** [January 4, 2023, 2:50am UTC](https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983/11 "2023-01-04T02:50:52Z")

</div>

Hey AMV101!  
How did this work? I had the same idea and just came across this in my search for answers. I have everything in place, just trying to get the config to work.

---

<div class="post-metadata">

**Author:** ![amv101](https://avatars.discourse-cdn.com/v4/letter/a/bbe5ce/32.png) [@amv101](https://klipper.discourse.group/u/amv101)\
**Post date:** [January 4, 2023, 3:28am UTC](https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983/12 "2023-01-04T03:28:12Z")

</div>

Yes I think it worked from my tests, but I moved on from that idea and cant remember if I had to change anything.

---

<div class="post-metadata">

**Author:** ![Chief](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/chief/32/3251_2.png) [@Chief](https://klipper.discourse.group/u/Chief)\
**Post date:** [January 5, 2023, 11:36pm UTC](https://klipper.discourse.group/t/use-a-servo-controlled-valve-as-the-part-cooling-fan/1983/13 "2023-01-05T23:36:36Z")

</div>

Hello everyone,  
I’d like to revive this conversation as I am trying this avenue myself. Thanks to the previous posters who have helped.  
I am having trouble with jjarosz answer as Klipper will not recognize the name seen at the bottom, printer.fan.speed  
I tried removing printer and also putting fan in brackets to no avail. How do I reference the fan speed into the macro controlling the servo?  
I have attached my printer.cfg file below  
[printer.cfg](https://klipper.discourse.group/uploads/short-url/rjFPHnIEF9P5wnARRTJLen5Q9IZ.cfg) (3.6 KB)
