Go Down

Topic: assistance with temp comtrol project plzzzzz. (Read 2154 times) previous topic - next topic


hello .. i am doin a project to heat an aquarium using pid control :

"Many people keep aquaria indoors now because they enjoy the relaxing feel of them.  Indoor environments are to a large degree air conditioned these days and as such sometimes the fish can be uncomfortable and even be harmed by the cold temperatures they may be subjected to.  Tropical fish generally enjoy temperatures from 22°C - 26°C and we know that it can get colder than this in some indoor environments.  Your project is to design a control system to regulate the temperature for such an aquarium for tropical fishes.  You MUST build a functional prototype of your system.  You are to use the arduino microprocessor as your hardware platform for implementation of your continuous control strategy."

i am using the arduino uno, tmp 36 temp sensor, a 300w heater, 12 volt relay, lcd display and i have some transistors and resistors, water pump, aquraium.

i am however brand new to ardino programming (kno a little bit of c+).. i have gotten the sketch for the temp sensor to work and plan to use pwm to control the heater via the relay using "if" or "while" statements.... i wud like some assistance in understanding how to use the pid library and how to best use the pwm  in this project...

will post my sketch thus far later.... any assistance will be greatly appreciated


Mechanical relays tend to work too slowly to be controlled by hardware PWM (analogWrite()).  They would buzz a lot. Use software PWM to control the relay over longer time periods, like ten pulses per minute instead of hundreds of pulses per second.

Is the heater a Mains heater?  You could use a Solid State Relay (SSR) to control it with  hardware PWM because the SSR can switch on and off much faster than a mechanical relay.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


the heater is power by 110v mains

well from the testing i have done the time period will have to be pretty long based on the size of the aquarium and the heater capacity.. it takes about 4 minutes to go from 21 Celsius to 26 Celsius.. still trying to work out the period though...

what exactly do you mean by software pwm?


what exactly do you mean by software pwm?

Calculate percent heat needed: 0 to 100
Turn on relay.
delay PWM period * percent heat needed
Turn off relay.
delay PWM period * (100 - percent heat needed)

I'd use a PWM period between 6 and 60 seconds.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


ok so i was confused for a while trying to figure out how to set the pwm period.. but i think i finally think i got that part

int led = 13;
float percent;
float period=60000;
float ontime;

void setup() {               
  pinMode(led, OUTPUT);

void loop() {
                          // percent calculated through pid some how here
  digitalWrite(led, HIGH);   // turn the heater on
  delay(ontime);               // wait on
  digitalWrite(led, LOW);    // turn theheater off
  delay(period-ontime);               // wait off

the next thing i need is how to implement the pid.. that part is what has me confused..


Why do you need the PID at all? Is it a requirement on the assignment? You can control it far more simply by turning the heater on when it's getting cold and off when it's warm enough. Make sure there's sufficient distance between your two limit points that you're not turning on & off continuously. Maybe turn on at 23C and off at 25C. You can use the PID of course, but its not as useful if you don't have proportional control of the output - although I do appreciate that you're simulating that with PWM - I'm just confused as to the need to make it so complex.


yes pid is a requirement, we also need to come up with the transfer function, plot a graph for the response to a set input change and find the time constant


Are you going to implement the PID control algorithm yourself, or use the standard PID library? The standard library should be easier to get working and more reliable (since it has already been tested and debugged) but may be harder for you to work out how to model the behaviour mathematically.
I only provide help via the forum - please do not contact me for private consultancy.


If you're going to use the library, this blog post by the author is worth a read: http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/. If you're going to roll your own, reading it is crucial ;)


i have seen and read that over and over... what i am having trouble with is how to put that into my sketch to control.. i'm sure its not jus a cut and paste.. if u anyone can pint me to a working example of the code (in a simple project) so i can follow the code pattern it wud be very help..

what i have so for is:

input=current temp \\as read from the tmp36

error= set point - current temp 

output= percent of period \\to adjust duty cycle

the temperature is being sensed every second.. but i my hav to increase that time because the readings are a bit too erratic....


How much water do you have to heat? While thinking about frequency of sampling, it may be worth doing the math to see how long the heater will take to have a measurable effect.


we have that part covered.. did some experiments to measure heating and cooling time. so we can adjust the time to suit thats no biggie.

another question does all the code have to be on the same sketch page? or can i write my sensing code on one sketch, the pid code on another sketch and add the sketches to one file to run at the same time


You can use multiple files.  All the other .h, .ino and .cpp files in the same folder will show up in tabs in the IDE. The little arrow at the right end of the tab bar will let you create a new tab.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp


thanks ..

lil update we can use pi instead of pid


The specific heat of water is 4.187 kJ/kgK.
In other words you need to input 4.187kJ to raise the temperature of 1kg of water by 1 degree centigrade or kelvin.
That is a lot of energy, which explains why water and water mist are so good at putting out fires.

If you know the wattage of your heater and the mass of water you have to heat you can probably calculate fairly accurately how long the heater needs to be on for to change the temperature by a desired amount. The main thing introducing an inaccuracy will be how fast the tank loses heat, which will depend on the ambient temperature and how hot you are trying to make the water.

You are going to use a PID for the control but doing some calculations will help you tune it and confirm your results.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131