I want to control the draft door on my wood furnace with a servo that will move to preset angle values at three different supply air temperature reading inputs. I tried writing the code with if and else statements, but it only seems to react to the highest temp setting, and the lowest temp settings. It seems to ignore the mid temp trigger setting. Not sure why it ignores the mid temp request.
#include <max6675.h>
#include <Servo.h>
Servo myservo;
float Temp;
int pos=0;
// Supply Air Temperature Sensor
int thermo1so = 12; // so
int thermo1cs = 10; // cs
int thermo1sck = 13; // sck
MAX6675 thermocouple1(thermo1sck, thermo1cs, thermo1so);
void setup (){
Serial.begin(115200);
myservo.attach(5);
}
void loop() {
Temp = thermocouple1.readFahrenheit();
Serial.print("SPLY Temp = ");
Serial.println(Temp);
if (Temp >130)
myservo.write (0);
else
if (Temp >123 && <127); //This statement with && works now. Changed from if (Temp>123<127)
myservo.write (120);
else
if (Temp <115);
myservo.write (135);
delay(1000);
}
Interesting project. Posting a schematic, not a frizzy picture with links to technical information on the hardware devices would be a big help. Also check in the instructions there is a proper way to post code, making it much easier to follow. Try swapping the second and third statements.
I can't have 125<temp, because there is a lower temp that triggers the full open damper position. Then every loop when the temp is below the minimum setpoint, the servo will cycle trying to meet both angle requirements. I can spread the temp to say 123 & 127. I use the MAX6675 and a thermocouple to provide the temp input. It has a resolution of 0.25 degrees. So between 125 and 127, there are 8 temp differences to go through, not just one.
The idea is not to create a PID control with minute adjustments. It is designed to have just three setpoints and three angle settings. Once a temp is hit the damper sits at the specified angle until another temp setpoint is hit and adjusts to the new angle and sits and waits for the next temp to trigger. Like I mentioned it works fine for the max and min temp triggers, It just ignores the mid temp trigger. That is why I think the code is incorrect. I'm not very experienced in this processing language, and am trying to follow others' examples, but I am stumped on this one. I thought I did this correctly, but it doesn't seem to have worked out that way.
Anyway, thanks for your input. I'll have to keep at I will figure it out someday.
Thanks Bill,
That worked out perfectly. My supply temp ranges from between 117F to 135 F. With some fine tuning I can probably get the range a bit closer.
Also, Can a PID algorithm be used to control a servo ? I know the servo requires a PWM signal. I'm just not sure if the PID will generate the proper signals needed.
You can use PID. You can even configure it to give you an output between 0 and 180 and just pass that to Servo.write.
I wouldn't bother with it initially though, you can use the map function to transform the 117 to 135 range to 0 to 180 and only if that doesn't suit would I consider PID.
That's just what Your attempt to code the interval Yourself! Do agree that (temp > 125) is exactly the same as (125 < temp)!
No, not 8. 7. There are 125,25, 125,50, 125,75, 126,00, 126,25, 126,50 and 126.75. Know the difference between > and >=.
Yes. You would set Input to your measured temperature and Setpoint to your desired temperature and let Output drive the servo.
The Output range is arbitrary... whatever you need for a control signal. The PID_v1 library defaults to a range of 0 to 255 but provides library functions to set the Output limits. You could use 0 to 180 for servo.write() or 500 to 2500 for servo.writeMicroseconds().