Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

An algorithm for controlling temperature and humidity of greenhouse and aviculture

Status
Not open for further replies.

amindzo

Member
Hi, i want to control the humidity and temperature of the greenhouse and aviculture,so i need a good and simple algorithm,I use SHT75 (a digital temperature and humidity sensor for measuring temperature and humidity) and PIC16F877A. I don't have any problem to work with this sensor and microcontroller,i just want a good idea for controlling algorithm.Imagine we have 4 variables: 1)real_temp 2)real_humid 3)temp_value 4)humid_value
variables 1 and 2 are real temperature and real RH that measured by sensor and variables 3 and 4 are favorite values for temperature and humidity that inserted by operator with keyboard.I want to measure temperature and humidity every 10 minutes and execute the controlling program in a subroutine so i want an algorithm that control the temperature and humidity and adjust them in favorite values.
 
Last edited:
Hi, i want to control the humidity and temperature of the greenhouse and aviculture,so i need a good and simple algorithm,I use SHT75 (a digital temperature and humidity sensor for measuring temperature and humidity) and PIC16F877A. I don't have any problem to work with this sensor and microcontroller,i just want a good idea for controlling algorithm.Imagine we have 4 variables: 1)real_temp 2)real_humid 3)temp_value 4)humid_value
variables 1 and 2 are real temperature and real RH that measured by sensor and variables 3 and 4 are favorite values for temperature and humidity that inserted by operator with keyboard.I want to measure temperature and humidity every 10 minutes and execute the controlling program in a subroutine so i want an algorithm that control the temperature and humidity and adjust them in favorite values.

The classic control algorithm is the PID method. You can search the web for lots of information and help on the topic.

PID controller - Wikipedia, the free encyclopedia

PID can be implemented on a PIC and there is code out there if you search for it.

Good luck
 
i just want a simple and utility algorithm,for example with conditional causes:

IF (real_temp)<((temp_value)-1) then

turn on heaters
............
............
ENDIF

i should have a margin for temperature and humidity to avoid frequently turning on and off ,fans and heaters.for example if the favorite value is 29C', i should use (29-1) and (29+1) in my algorithm,are agree with me?
 
i just want a simple and utility algorithm,for example with conditional causes:

IF (real_temp)<((temp_value)-1) then

turn on heaters
............
............
ENDIF

i should have a margin for temperature and humidity to avoid frequently turning on and off ,fans and heaters.for example if the favorite value is 29C', i should use (29-1) and (29+1) in my algorithm,are agree with me?

What you are describing is a simple on/off gap controller, not unlike a simple thermostat control on a home central air heater. It may work for your application but you will have to experment with the actual gap range you can maintain and possible over and under shoot of desired temperature due to the process lag in the heater Vs your load.
 
Last edited:
for controlling, i have 8 fans,2 heaters and there is a pad on one side of the aviculture and greenhouse that i can control the water with valve that pour on the pad and big fans (2.5Kwatt) on the other side of the saloon pull the air and adjust temperature and humidity of the saloon.the saloon approximately has 20 meter width and 75 meter length.
you are right but i should work on that really hard and it takes some time,i should do it as soon as possible.I have read somethings about PID controllers and other controller in university 4 years ago but it's hard for me to implement those mathematical formulas in real environment ,could you help me more?
 
Last edited:
for controlling, i have 8 fans,2 heaters and there is a pad on one side of the aviculture and greenhouse that i can control the water with valve that pour on the pad and big fans (2.5Kwatt) on the other side of the saloon pull the air and adjust temperature and humidity of the saloon.the saloon approximately has 20 meter width and 75 meter length.
you are right but i should work on that really hard and it takes some time,i should do it as soon as possible.I have read somethings about PID controllers and other controller in university 4 years ago but it's hard for me to implement those mathematical formulas in real environment ,could you help me more?

I'm afraid I can only give you general information I've tried to pass on, not specific solutions for your application.

There is much to consider for a complete solution. While PID controller(s) would to the best general solution, you also have to think about additonal safety considerations in case of failure in control components (electrical and mechanical) that could lead to run away heating or cooling. There is much information on the internet on process control, you just have to search and study.

Good luck
 
Last edited:
thanks but i can do it with my sensor SHT75 and controlling algorithm so i don't need DS1620.My problem is the controlling algorithm.
 
i just want a simple and utility algorithm,for example with conditional causes:

IF (real_temp)<((temp_value)-1) then

turn on heaters
............
............
ENDIF
Sounds like a Fuzzy Logic controller would be appropriate for your needs. It basically uses a series of If-Then statements to control a system. It tends to be less complicated and more intuitive then a PID system. See Fuzzy logic tutorial. or fuzzyTECH or **broken link removed** or **broken link removed** for more info. See **broken link removed** for a Fuzzy Logic example.

Fuzzy Logic is not well know but the Japanese have used it in a number of products. I believe it's even been used to smoothly control the movements of a Japanese subway train.

PID control was originally designed for analog control loops since it meshed well with the analog functions easily performed by op amps (integration, differentiation, summing). It's not generally such a good fit for microprocessors since you are basically having the processor perform a series of complicated functions to simulate the analog integration and differentiation required in a PID loop. This is complicated to write and difficult for a µP to do. Fuzzy Logic uses a series of If-Then statements which are easily performed by a µP and does not usually require solving any mathemetical functions. Another advantage of a Fuzzy Logic controller is that, if it isn't working properly, it's usually apparent what part of the code needs to be tweaked to improve the operation.
 
Last edited:
Sounds like a Fuzzy Logic controller would be appropriate for your needs. It basically uses a series of If-Then statements to control a system. It tends to be less complicated and more intuitive then a PID system. See Fuzzy logic tutorial. or fuzzyTECH or **broken link removed** or **broken link removed** for more info. See **broken link removed** for a Fuzzy Logic example.

Fuzzy Logic is not well know but the Japanese have used it in a number of products. I believe it's even been used to smoothly control the movements of a Japanese subway train.

PID control was originally designed for analog control loops since it meshed well with the analog functions easily performed by op amps (integration, differentiation, summing). It's not generally such a good fit for microprocessors since you are basically having the processor perform a series of complicated functions to simulate the analog integration and differentiation required in a PID loop. This is complicated to write and difficult for a µP to do. Fuzzy Logic uses a series of If-Then statements which are easily performed by a µP and does not usually require solving any mathemetical functions.

I agree that fuzzy logic could be a solution for the OP, however I feel it would no more or less difficult to implement into a real process then the standard PID methods.

However I do not nessessarly agree with your other statement:

"PID control was originally designed for analog control loops since it meshed well with the analog functions easily performed by op amps (integration, differentiation, summing). It's not generally such a good fit for microprocessors since you are basically having the processor perform a series of complicated functions to simulate the analog integration and differentiation required in a PID loop. This is complicated to write and difficult for a µP to do. Fuzzy Logic uses a series of If-Then statements which are easily performed by a µP and does not usually require solving any mathemetical functions."

Your correct that PID were implemented with older techknowleges (analog electronics, pnumatic, etc) however all the major process control manufactures (DCS and PLC vendors) have long converted to controllers using embedded digital components and methods, typically using uP(s). One would be hard pressed to find a current commercial PID controller made today that uses analog op amps to perform the basic PID algorithm.

Lefty
 
Last edited:
I agree that fuzzy logic could be a solution for the OP, however I feel it would no more or less difficult to implement into a real process then the standard PID methods.

However I do not nessessarly agree with your other statement:

"PID control was originally designed for analog control loops since it meshed well with the analog functions easily performed by op amps (integration, differentiation, summing). It's not generally such a good fit for microprocessors since you are basically having the processor perform a series of complicated functions to simulate the analog integration and differentiation required in a PID loop. This is complicated to write and difficult for a µP to do. Fuzzy Logic uses a series of If-Then statements which are easily performed by a µP and does not usually require solving any mathematical functions."

Your correct that PID were implemented with older techknowleges (analog electronics, pnumatic, etc) however all the major process control manufactures (DECS and PLC vendors) have long converted to controllers using embedded digital components and methods, typically using uP(s). One would be hard pressed to find a current commercial PID controller made today that uses analog op amps to perform the basic PID algorithm.

Lefty
Well, I understand your disagreement. PID certainly is the common way to do control loops. But I believe that's more from legacy issues than it being the best way. I'm aware that actual analog control circuitry is now seldom used, but the processors are still simulating the functions. That requires a significant amount of complex software and processing power. If you buy a control processor from a commercial vendor, the software's already done for you. But if you are doing the loop with your own PIC then you need to write that software or download it from someone who's already written it. And that can require significant program memory space.

PID requires a certain mathematical model of the system to design a stable loop. Thats how the various PID values are determined for stable loop control. And if the model mathematical constants deviates significantly from the actual system, then instability can result. Fuzzy Logic generally does not require such a mathematical model to write the control functions and achieve a stable loop, although a general model of the system is needed, of course.

I thus believe it's easier for a beginner to understand, design, and implement a stable control loop in a small µC with Fuzzy Logic then with a PID loop. It certainly seems that Fuzzy Logic would be a good fit to amindzo's control needs and his knowledge. He can start out with a simple loop with a few statements and easily add to it to improve it's performance, if necessary. And if it's not performing correctly, it's usually apparent where the problem is in the code. That's generally not so with a PID loop.

But you can certainly disagree. A free exchange of ideas always involves some disagreement.
 
Well, I understand your disagreement. PID certainly is the common way to do control loops. But I believe that's more from legacy issues than it being the best way. I'm aware that actual analog control circuitry is now seldom used, but the processors are still simulating the functions. That requires a significant amount of complex software and processing power. If you buy a control processor from a commercial vendor, the software's already done for you. But if you are doing the loop with your own PIC then you need to write that software or download it from someone who's already written it. And that can require significant program memory space.

PID requires a certain mathematical model of the system to design a stable loop. That's how the various PID values are determined for stable loop control. And if the model mathematical constants deviates significantly from the actual system, then instability can result. Fuzzy Logic generally does not require such a mathematical model to write the control functions and achieve a stable loop, although a general model of the system is needed, of course.

I thus believe it's easier for a beginner to understand, design, and implement a stable control loop in a small µC with Fuzzy Logic then with a PID loop. It certainly seems that Fuzzy Logic would be a good fit to amindzo's control needs and his knowledge. He can start out with a simple loop with a few statements and easily add to it to improve it's performance, if necessary. And if it's not performing correctly, it's usually apparent where the problem is in the code. That's generally not so with a PID loop.

But you can certainly disagree. A free exchange of ideas always involves some disagreement.

"But you can certainly disagree. A free exchange of ideas always involves some disagreement."

And that was certainly the spirit in which I made my comments. The PID algorithm uses proven calculations, not a model of the process, and almost always allows for the "tuning" of the three variable PID terms used. Indeed tuning a loop is often an art but there are guidelines for tuning if one can make an educated guess at the process lag of what is being controlled.

Often many commercial packaged PID controllers now offer an auto tune function that I've seen be very useful in optimizing tuning variables, especially temperature loops that have slow response times.

As far as actual uP code being available, I have seen many published in application bulletins and such. However they tend to just be the core requirements and leave undone the user interface and actual input/output sections and of course rarely try and show specific measurement sensors or final output control elements.

I'm thinking if I was in the OP shoes I would probably investigate and try and find an inexpensive PLC or perhaps a used PLC to handle the control functions and utilize a PC for a user interface display. While that might take a little more up front investment, I think it would have a much better chance of being successful. Just a thought.

Lefty
 
First I strongly suggest you have at least two temperature sensors. They are dirt chip compared to 1 night of runaway or no heating and dead birds.

The actual DIY sensor and controls for temperature are so inexpensive that you may want several setup to vote.

The actual control does not need to be complex. I have a much smaller simpler setup in my greenhouse that has worked well for 3 years. There is a program on the PC that talks to a uC in the greenhouse with a 2 wire sensor networks. The UI has setting for heat.

Cool on at - 85
Cool off at - 80

Heat off at - 75
Heat on at - 70​

The above would keep the temperature between slightly less then 70 and slightly more then 85.

I read my sensors once a minute. Adjust the heat and cool settings to meet you needs. The spread between on and off is hysteresis.

During heating the above will kick on at a reading of 70 or lower. If the heater has much thermal mass it will overshoot 75 by a degree or two. Do not use heating and cooling settings so close together that the heating
overshoot turns on the cooling.

I use a second set of setting with the temperature sensors to activate an vocal alarm on the PC. The settings are

Alarm greenhouse temperature - 90
Warning greenhouse temperature- 86

Warning greenhouse temperature - 75
Alarm greenhouse temperature - 70​

At 87 degrees it would be saying WARING greenhouse air temperature is 87 degrees.

My system has been a work in progress that I have not touched in several years. The PC UI is C# and the dirt simple uC uses a PIC with a 1 wire network.

I hope this helps

3v0

EDIT: in the snapshot the blue box shows the cooling is on. If it were heating it would be red. Actually the heating and cooling are disconnected from the power and the greenhouse door is open because there are no plants, it is not in use.

At one time I had the UI sending temperature data ot a mySQL data base server on a linux box. Another app could be used to query the server and generate temperature grapsh. It was a lot of fun but when i lost the server I did not put that part back up.

EDIT2: You can read more about it at WX175 Weather Station/Greenhouse Project
 

Attachments

  • cntrl1.jpg
    cntrl1.jpg
    57.6 KB · Views: 358
Last edited:
it's not a modern system.the water pour on the pads and big fans on the other side of the saloon pull the air and flow of the air make an approximately constant temperature and humidity in aviculture. in aviculture humidity is not as important as temperature(the pads not heated) but in greenhouse we use fog makers to control humidity exactly. The fans,heaters,valves and fog makers are controlled with PIC16F877A. i put some sensors in different places of saloon and measure the humidity and temperature and send data to main controller and that controller decide what to do and it will turn on/off fans,heaters,vaves and fog makers.for example for turning on a fan, i will make PORTB.0 high and it turns on the relay(5v 10A relay) then this relay will turn on the contactor( SIEMENS 3PH contactors) and contactor with turn on the fan.i also put a keypad to control each fan and heater automatically or manually that can selected with the operator.

imagine that we have 8 fans and 2 heaters and a valve for pour water on the pad(work as a cooler in hot weather and increase humidity)
fans: fan1 fan2 fan3 fan4 fan5 fan6 fan7 fan8
heaters: heater1 heater2
valve: valve1
fan1,fan3 fan5 and fan7 are always on for ventilation in aviculture.
for controlling i should use fan2,fan4,fan6 and fan8 and also heaters and valve.
so in my algorithm when i tell fans ,it means fan2,fan4,fan6 and fan8

in aviculture humidity is not as important as temperature so i exert this margine for temperature and humidity:
for temperature: (setpoint-1) and (setpoint+1)
for humidity: (setpoint-4) and (setpoint+4)

this is my algorithm that executed every 10 mintutes:


1-if (temp<(setpoint-1)) and (humidity<(setpoint-4)) then

turn on heaters
turn off fans

if the situation is not changed for 20 minutes then turn on valve

if the situation is not changed for 40 minutes turn on alarm

2- if (temp<(setpoint-1)) and (humidity>(setpoint+4) then

turn off valve
turn on heaters
turn off fans

if the situation is not changed for 20 minutes then turn on fans(for reducing humidity)

if the situation is not changed for 40 minutes then turn on alarm

3-if (temp>(setpoint+1)) and (humidity>(setpoint+4)) then

turn off valve
turn off heater

if the situation is not changed for 10 minutes then turn on fans

if the situation is not changed for 20 minutes turn on valve(for reducing temperature)

if the situation is not changed for 40 minutes turn on on alarm


4-if (temp>(setpoint+1)) and (humidity<(setpoint-4) then

turn off heaters

if the situation is not changed for 10 minutes then turn on fans and valve

if the situation is not changed for 40 minutes then turn on alarm
 
Last edited:
Do the fans that blow air through the pads use outside or inside air ?

Do the other fans move inside air or do they replace the inside air ?

Do you have an outside air temperature and humidity sensor ?

Does the enviorment respond so slowly that it makes sense to take readings only every 10 minutes ?

EDIT: It may be that outside will always be too dry to need humidity monitoring.
 
Last edited:
the fans pull the inside air to outside(all of fans).we have some small windows that fresh air comes from them and fans pull the inside air to outside. we live in a mild area,especially in summer it has a hot and humid weather.(maX : 40-42C' and 80% humidity).i haven't put any sensor outside.
 
I am still trying to get an idea of what your system looks like.

We call the units that move air through a wet pad, evaporative coolers or swamp coolers. The air and water for these can be controlled separately.

I would place both temperature and humidity sensors outside.

It may be best to have a small cooler that did not use outside air to raise the humidity while heating?
For Heating and cooling start with somthing like this

If (inside is too hot) then
{
if (outside air is cool) then
{
use fan to bring in cool outside air // A
}
else /* outside air it not cool enough to cool inside */
{
use swamp cooler // B
}
}

The fan in case A could be the swamp cooler with the water turned off

If (inside is too cool) then
{
Start heaters.
}
else
{
Stop heaters.
}


It is difficult to control humidity independant of the cooling.

if ((not cooling) and (low humidity)) then
{
start swamp cooler
}


These rules are far from perfected and there is a lot I do not know about your setup.

Lets say the outside air is too cold but the inside air is too warm. You can cool the inside with outside air but you need to be sure not to bring in so much outside air that the inside becomes too cold. You can either use a variable speed fan or turn the fan on and off as needed. Unless your enclosure is large I would think reading the sensors every 10 minutes is going to be too infrequent. I read mine once a minute.
 
we need fresh air because in this environment we have ammonia gas that will harmful for chickens.i will add an ammonia sensor for this problem later.when ammonia gas concentration reaches or wants to go higher than 25ppm,all of the fans should turn on for good ventilation .when fans pull the air outside the inside pressure decrease and fresh air comes in via small windows, small windows are in the length of the saloon (both sides) and pad placed on width of the saloon and fans are placed on the other side(in front of them).and we have 2 big heaters on the right and left of the saloon that is near pad.i want to use this system in old aviculture that they adjusted humidity and temperature manually with an operator.some of the aviculture has non changeable revolution fans and some of them have changeable ones.In non changeable revolution fans i have to turn on and off them and in changeable revolution ones i will decrease or increase the revolution.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top