-arduino
-lcd and i2c
-5v relay
-lm35 temperature sensor
I would like to make a controler from a test equipement that consists a heater plate and a cup of water.
I need to heat the water a a rate of 5c/minute from ambient temp until 100c.
I tryed in other program language (labview), but in arduino code I think I will find problems how to configure the code for the ramp. And my loop must be shorter to be more precise.
Another thing is that the heater plate at the begin is not fast, so the "ramp" must wait (=0) when we have incresing temperature the ramp can control the relay for tunr on/off the plate.
Hoppe you understand the project and help me to developt this part of the ramp.
Thanks for your repply.
I want to say that I need a ramp of 5c/min, but the loop must be shorter, about 10s and check the speed each cycle.
The code needs to add 0.833 each 10s loop to the mathematic ramp, and check if the temperature is on mathematic line or not and tunrs on or off the relay for that. And if the temperature is too low (at the beginning) need a condition to add zero instead 0.83.
Whether you are able to increase the temperature by 5 degrees per minute, or not, has NOTHING to do with the code. It has ALL to do with the heat source and the volume to be heated.
but the loop must be shorter, about 10s
loop() should be on the order of something more like 10 microseconds.
The code needs to add 0.833 each 10s loop to the mathematic ramp
0.833 Newtons per kilometer squared?
Hoppe not complicate.
What's complicated is your tap dancing. Tap dancing has no place in your project.
In labview I creat a line (law) that increases 0.833degrees c/10sec and control the relay (heater) following this line with feedback of the temp sensor.
As I am a newebie I will get an existing control temperature program, but in this case the setpoint is moving automatically.
But I not see how to do
ramp=ramp+0
loop
ramp=ramp+0.833
if temp>ramp
relay off
else ON
If temp<(ramp+5) \heater is starting heating so the ramp must wait
ramp=0
Do not even consider using delay(). Use millis(), instead, to see if it is time to do something (different).
That is, on each pass through loop(), use millis() to get the current time. Compare that to the previous time. The difference should be used to determine the expected change in temperature.
Then, measure the actual temperature, and compare that to the previous temperature, to get the amount of change. If the actual change was less than the needed change, turn the heater on. If the actual change was more than the needed change, turn the heater off.
Expect the heater to be bouncing on and off, though, as you are not likely to get a linear change in temperature running the heater full blast or nothing and using a crappy temperature sensor.
Search for PID loop temperature control - many threads on this.
To get a ramp you need to feed a ramping value in to the control input of the
PID loop.
Train your PID on more demanding step-changes of temperature though, With
heating you need to be careful not to overshoot (unless you have active cooling
as well as heating).
What people are trying to say is do this for scheduling a PID loop at 10s intervals:
#define DELAY 10000
unsigned long next_pid = 0L ;
void loop ()
{
if (millis () - next_pid >= DELAY)
{
next_pid += DELAY ;
myPID () ;
}
// other stuff can go here, updating display, check for button presses etc...
}
float setpoint = ?? ;
void myPID ()
{
// do the PID stuff here, it gets called every 10s
setpoint += 5.0/6.0 ;
// PID calcs
// handle relay
}
Thanks for your good help.
But I was worked with the system in labview and witn a ON/OFF control and it is quite good.
With PID I am afraid that the system take many time to get the set point. I expect overshot but +-0.5C will be nothing.
Please se the picture, the problem will be at the beggining the heater will be slowly and the red ramp needs to wait for the temperature.
If you have a working Labview program, simply use the same hardware and adapt the various labview blocks to Arduino code.
In this case, there is nothing that labview can do that the arduino cannot. More specifically, I would use the same sensor and heater, if they are working for you.
What you are really looking for is a state machine.
here is the first version with errors.
The code increases 5 degrees /min in templaw and temp follows templaw if temp is slow, templaw waits. Please help me find the error.
Best regards
cpalha
//control a water heater beaker at 5C/min
int tempPin = A0; // the output pin of LM35
float temp;
int led = 8; // led pin
float templaw=5; // the law ramp
void setup() {
pinMode(led, OUTPUT);
pinMode(tempPin, INPUT);
Serial.begin(9600);
}
void loop() {
temp = readTemp(); // get the temperature
if temp < templaw + 2; {
templaw = templaw + 0;
} else {
templaw = templaw + 0.83;//gives an increase of 5C/min
}
if(temp > templaw) { // if temp is higher than tempMax
digitalWrite(led, LOW); // turn on led in future relay
} else { // else turn of led in future relay
digitalWrite(led, HIGH);
}
Serial.print("TEMP: ");
Serial.println(temp); // display the temperature
Serial.print("TEMPLAW: ");
Serial.println(templaw);
delay(10000);
}
int readTemp() { // get the temperature and convert it to celsius
temp = analogRead(tempPin);
return temp * 0.48828125;
}