Hey guys, hope ya'll got a great weekend. I need some help on PID control code here.
I try to use PID control system to make a BBQ smoker temperature control. Here is part of the code.
if (Serial.available()>0) {
target_temp = Serial.parseInt();
Serial.println(target_temp);
}//set up target temperature, this can be changed anytime during program run
current_time = millis();
if (current_time - old_time > 3000) { //take temperature reading every 3 seconds
thermistorReading = analogRead(thermistorPin);
TempInF = 1047 - ( 2 * thermistorReading); //it convert analoge read from prob to temperature in Fahrenheit. the equation will change base on prob and resistor used in circuit
//Serial.print(thermistorReading); //for testing only
Serial.print("tempeature in Fahrenheit:");
Serial.println(TempInF);
Serial.print("Target tempeature in Fahrenheit:");
Serial.println(target_temp);
delay(1000); //just here to slow down the output for easier reading
if (TempInF <= target_temp) { //program active when reading temperature is smaller than target temperature
error = target_temp - TempInF;
Serial.print("tempeature difference:");
Serial.println(error);
interror = interror + error;
Serial.print("interror test:");
Serial.println(interror);
fan_speed = (float) (3 * error + 0.05 * interror);
Now, I have the output of the system. How can I transfor it to PWM signal that I can use to control the speed of fan? I'm thinking use map function, but how does it work? the range is a variable.