# Need pointers on type of maths for a multi input, multi output control system

Hi team, I think I'm in over my head so thought I'd pose a question here to try and get on the right path.

I've installed a greenhouse recently and thought regulating the temperature and humidity would be an interesting arduino project.

I started playing with PID logic but quickly realised a SISO solution wasn't going to work. What I have is a PWM fan blowing in, PWM fan blowing out, and a relay controlled pump for a misting system. I'm using a couple of DHT22 sensors inside and out to check temp and humidity environmentals.

I made some progress with PID logic but then got stuck in a big if/else structure trying to get smart about whether to blow air in and/or out depending on relative and target temp and humidity in conjunction with running the misting system.

I'm not looking for code, rather the kind of maths I should be using to build a suitable control model.

Any pointers would be greatly appreciated.

Would not the amount of air going out simply equal the amount going in, bar barometric changes?

Paul__B:
Would not the amount of air going out simply equal the amount going in, bar barometric changes?

The idea is that I don't run the inward fan if the humidity outside is higher than inside AND inside is above the set point.

Likewise, I don't want to run fan inward to reduce temp if outside is greater than inside AND inside is above the set point, and vice versa.

It obviously isn't a fully sealed system but I don't want to exacerbate temp or humidity issue using overly simple logic.

Paul is right - your intake and exhaust are NOT independent. When you blow air out where does the air to replace it come from? Yes - from outside.

You can implement PID control and there is a very good reference here that shows how you can do it with an arduino.

Dont be put off by the math. Its DISCRETE calculus dead easy to implement in code

• P: instanteneousError = setpoint – input;

• I: cumulativeError = += error * elapsedTime;

• D: rateOfError = (error – errorLastCalculation)/elapsedTime;

However you have another issue.

Suppose your temp set point is 18 degrees and 50% humidity. If you CAN maintain that through the day, then at night the greenhouse will cool unless you have a way of heating it. And as it cools the internal humidity will rise; but the OUTSide temperature has dropped so you cant blow air through to reduce it.

Fun project

What is the PID calculation controlling?

I find it hard to imagine that any PID is needed to maintain a reasonable atmosphere in a greenhouse.

...R

johnerrington:
Paul is right - your intake and exhaust are NOT independent. When you blow air out where does the air to replace it come from? Yes - from outside.

True but it isn’t going to be a blast of potentially hot dry air. Likewise if it is more humid outside I can pull the air in without needing to run the misting system.

You can implement PID control and there is a very good reference here that shows how you can do it with an arduino.

I’m fine with configuring PID’s. Issue is balancing whether to pull air into the greenhouse depending on relative humidity which requires comparing internal and external sensors, ie multiple inputs.

However you have another issue.

Suppose your temp set point is 18 degrees and 50% humidity. If you CAN maintain that through the day, then at night the greenhouse will cool unless you have a way of heating it. And as it cools the internal humidity will rise; but the OUTSide temperature has dropped so you cant blow air through to reduce it.

Good point. I have tube heaters with thermostats which assists with the temp. Excess humidity is less of problem than too low.

Fun project

Is so far

Robin2:
What is the PID calculation controlling?

I find it hard to imagine that any PID is needed to maintain a reasonable atmosphere in a greenhouse.

…R

it’s about trying to avoid too low/high a temperature or low/high humidity and not running fans and misting pump full bore and overshooting. I have thermostat controlled tube heaters to deal with low temps.

I would have thought proportional control would be sufficient to control the fans using PWM
I and D seems overkill and would add complexity to the control algorithm

I really don't see a need for PID here either.

I think you need to decide whether temperature or humidity should be your primary driver. I'd think temperature is the key - too hot will kill your plants, I doubt that excess humidity will do damage.

Given that, run the fans to get the temperature up or down and humidify if you must. If you need humidity and you can get it from outside without busting temperature limits - do so.

Given the lags and non linerarities in your green house system ( eg changes in response depending on outside temperature and it’s effect on RH ) I would have just gone with on /off control and see how it performed. Then maybe something a bit more complex if it shows any shortcomings .

Multi loop systems , especially non linear ones can be complex to sort out with PID , you’ll need a master loop and slower responding other loops ( eg temperature, humidity )

To increase humidity, boil water to steam, to decrease, condense on a cold surface and drain outside.

garglebutt:
it’s about trying to avoid too low/high a temperature

You have not said what the PID code is controlling.

…R

Robin2:
You have not said what the PID code is controlling.

...R

Fan speeds via PWM and emulated slow PWM for the pump (since it is on/off via relay).

wildbill:
I really don't see a need for PID here either.

I think you need to decide whether temperature or humidity should be your primary driver. I'd think temperature is the key - too hot will kill your plants, I doubt that excess humidity will do damage.

Given that, run the fans to get the temperature up or down and humidify if you must. If you need humidity and you can get it from outside without busting temperature limits - do so.

I see your point. It's only running on my bench for now. Time to move into the real world!

garglebutt:
Fan speeds via PWM and emulated slow PWM for the pump (since it is on/off via relay).

I can't see how controlling those carefully would matter at all. Just figure out a suitable PWM value and use that. Or maybe two or three values to be used when more of less puff is required.

Fine control of the fan speed is a bit like worrying about the quality of the steering wheel in a racing car that has no engine.

...R