Assistance Needed for PWM Control with Trigger Configuration: Daily Time Span

Hello everyone,

Currently, I am using the Trigger Configuration: Trigger: Daily Time Span function combined with the Output: On/Off/Duration action to switch my membrane pump on and off at specific intervals within a set time span. This setup is working well.

Now, I want to achieve the same behavior but with a fixed PWM value instead of just on and off states. Unfortunately, I couldn’t find a suitable function for this.

Can someone please explain how I can achieve this in the simplest way possible?

Thank you in advance for your help!

First you need to setup an Output that uses PWM in the Outputs page…

Then in your Trigger Function settings, for setting a single fixed PWM value, you can use the Output: Duty Cycle Action


You can also ramp the PWM duty cycle up or down over a set range and time using the Output: Ramp Duty Cycle.

Hello Jason,

Thank you for the quick response. I have already tried both suggestions. In the On/Off Duration action, I can set the duration in seconds, but with the Output: Duty Cycle action, I can’t do that.


I have my pump turning on for 1 minute every 15 minutes from 05:00 to 23:00. I want to do the same but with a specific PWM value.

I also tried using the Output: Ramp Duty Cycle action. However, I want a constant PWM value, not a ramp. Therefore, I entered these values, but it didn’t work.

Can anyone help me figure out the best way to achieve this?

Why are you trying to control a diaphragm pump with a PWM value?
Is this pump an AC or DC driven motor?
PWM signal is usually used to control the speed of a DC-driven motor (like a fan) or the brightness of DC-driven LED lights.
PWM only works with DC current, it will not work for AC current.
One reason you can’t use PWM on that pump is because you haven’t set up that pump as a PWM Output in the Mycodo Outputs page, and you most likely won’t be able to.
A pump is usually either on or off, it’s not an output that is usually controlled by a PWM signal.
A pump is usually designed to run at a specific RPM and pressure, if you drive the pump with PWM signal and change that RPM, the pump most likely will not operate correctly.
If you are trying to control the output of the pump, it’s easier to place an in-line valve on the output of the pump to control flow-rate rather than trying to control the motor speed of the pump.
Please explain in more detail exactly what you are trying to accomplish by driving this pump with a PWM signal so we can try to offer better answers to help you.

I am aware of what Pulse Width Modulation is. My hardware setup is complete and functioning, and the entire system is up and running.

I have a 12V DC diaphragm pump and several DC fans that I control via MOSFETs. These need to run dimmed at specific times of the day, with a particular pulse-to-pause ratio as described.

My Setup in General

I use a Raspberry Pi 4 with an ADS1115, which has three signal isolators for pH, EC, and soil moisture. Additionally, I use a BMS680 for temperature and humidity, and an SCD41 for temperature, humidity, and CO2. I also have an MLX90614 for leaf temperature. The temperature is taken as the average of these three sensors, and the humidity is averaged from both measurements. I calculate the VPD using the leaf temperature and the average humidity, regulated with a bang-bang control method from one of your tutorials. The temperature of the nutrient solution is measured with a DS18B20.

I also have several dosing pumps, SSR relay outlets for a heater, circulation pump, irrigation pump, light fan, and an exhaust fan controlled by PWM. The lighting is controlled with a 0-10V PWM signal.

Additionally, I have some level sensors and a flow meter for the reservoir, with the ports in the enclosure and on the board already in place, but I still need to configure them. I might try a custom function for this.

All the modules and components are housed in an enclosure with many DIN sockets and several 3D-printed holders (for sensors, mounts, etc.). If everything proves reliable and I find the time, I will create a custom PCB to suit my needs.

I might introduce my system in a dedicated thread at some point.

So, is there no ready-made action for my application?

You still haven’t explained exactly what the diaphragm pump is being used for and why you think you need to control it using PWM. Again, pumps usually aren’t controlled in this manner.
Is this diaphragm pump setup in your Outputs page as a PWM Output or an On/Off Output?
Please post a screenshot of the Output Settings for your “membranpumpe”.
Are you controlling this pump with a relay? A MOSFET? Both?
A wiring diagram of how this pump is connected to the Pi, a power source, and how you are modulating that power source with the PWM signal would also be really helpful.

I don’t quite understand what that has to do with it.

It’s a simple small diaphragm pump with an ordinary DC brushed motor.
It can indeed be controlled with a PWM signal or a lower analog voltage!

I want to run it with PWM to reduce the noise. It is used to oxygenate my nutrient solution (I have an airstone in the solution).

Of course, I used just an N-channel MOSFET. Why would I put a PWM signal on a relay? That wouldn’t work at all!

On the output page, I currently have the pump configured twice, once as an On/Off output and once as a PWM output. The same setup is used for the DC fans.

Everything is correct there. I can control them with a PWM signal, for example, through the output page or other functions.

Both the pump and my DC fans can be dimmed perfectly. They are controlled by PWM to reduce noise and strong air movement.

I just want to know how to configure my outputs, like the pump or my fans, to run at a specific PWM value within a certain time period.

For example:

from 05:00 to 23:00, with the pump or fans running at 70% for 1 minute every 15 minutes, and off for the rest of the time.

Most people simply run their air stones 24/7, some people may turn them off at night if their air pump is too noisy. Not really sure what the point is of turning them on for only 1 minute every 15 minutes… just let it run through the whole span duration. Oxygenation of your nutrient tank is a pretty critical thing, pH will swing drastically without constant oxygenation, not to mention if you are running the air stone you don’t really need a circulation pump.

If you really need to run the pump at a specific PWM and also run it for 1 minute every 15 minutes then try the following setup…

I’m not sure there is a way to do what you are trying to do without maybe writing a Custom Module or maybe using a Conditional Controller… but I do know it’s not good to have Outputs duplicated… you need to have your fans or pumps (or any output) configured only once.
(This is what made it confusing as to whether you were using a relay or a mosfet… why would you have one output device setup with two different Output Modules in Mycodo? That doesn’t make sense at all and is probably causing hardware and software conflicts!)

If you need a PWM Output, use only the PWM Output and delete the On/Off Output.

Then open the PWM Output settings:
Set the Startup State to “User Set Value”
Set the Startup Value to 70 (or whatever value you need)
Now every time Mycodo boots, your pump should turn on and run at 70% speed.


After that you should be able to use the On/Off Duration Action in your Daily Time Span Function and when you turn the pump on it should run at that 70% PWM value you set in the PWM Output settings.
Of course you’ll need to setup a couple of other Functions to make sure the pump is turned off after each reboot and after each Daily Time Span is over.
It’s just easier (and better for your system) to let the air pump run all day.
If this doesn’t work, I can’t think of any other way to do this other than programming it yourself in a Conditional Function or Custom Module.

That sounds like a logical and sensible solution. I will test your suggestion later.

I configured with two outputs (PWM & On/Off) as a test. Eventually, I will remove one of them. Thanks for the hint that it might cause problems.

I might also consider running the pump dimmed 24/7. I thought I didn’t need that much oxygen, and I wanted to reduce noise, power consumption, and wear and tear.

But for my small fans, I would definitely like to implement it this way.

Thanks already, I will let you know later if it works.

You can always just buy a Tetra Whisper air pump. I have 2 of these running 24/7 and I can’t hear them running at all they are so quiet… I have a small one for my 5 gallon humidifier tank and a larger one for my nutrient tank. They are designed to run 24/7 and last for many years. They are not expensive and come in different sizes…

https://www.amazon.com/gp/product/B0009YF4FI/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&th=1

Yes, oxygenation is very important, not only for your plant roots, but also for keeping your nutrient tank from growing bad bacteria that will change pH and could harm your plants.

If you are using computer fans, I really recommend using the Noctua brand since they are the quietest you can buy. I also have 2 of these running in my system as the main air exchangers and even running them at 100% is still almost too quiet to hear. They have been running for over 3 years almost non-stop and they are still working fine. They are a little more expensive than other fans, but they come with a 6-year manufacturer’s warranty and are very much worth the price.

https://www.amazon.com/gp/product/B00KF7O58G/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&th=1

Good luck.

Yes, Noctua fans are also the best PC fans I know, especially when it comes to their service with spare parts and accessories. However, I decided against PC fans in this setup. I wanted more airflow and used 12V car fans with 3D-printed parts to attach them to the frame. Unfortunately, they are a bit too loud for my liking, but the airflow is very good.

In principle, I also have a diaphragm pump from the German manufacturer Schego. These are excellent pumps, with spare parts available even after decades. However, I wanted something very small and aimed to run everything possible on 12V.

I initially misunderstood your solution; it’s a bit too complicated for my needs. I tried writing a Custom Action with ChatGPT to implement my application, and it worked perfectly on the first try. After a duration elapses, it sets another PWM value. This way, I can adjust everything flexibly and customize the intervals. If anyone is interested, I can post the code here.

But still, thank you for your efforts

1 Like