/* Toaster Oven SMT soldering control Adrian Bowyer 2 November 2011 Licence: GPL https://reprap.org/wiki/Toaster_Oven_Reflow_Technique */ const int heatPin = 13; // the number of the LED pin. This also controls the heater int heatState = LOW; // heatState used to set the LED and heater long previousMillis = 0; // will store last time LED/heater was updated const long interval = 1000; // interval at which to sample temperature (milliseconds) const int tempPin = 0; // Analogue pin for temperature reading long time = 0; // Time since start in seconds bool done=false; // Flag to indicate that the process has finished // The temperature/time profile as {secs, temp} // This profile is linearly interpolated to get the required temperature at any time. // PLEN is the number of entries #define PLEN 6 long profile[PLEN][2] = { {0, 15}, {120, 150}, {220, 183}, {280, 215}, {320, 183}, {350, 0} }; // Linearly interpolate the profile for the current time in secs, t int target(long t) { if(t <= profile[0][0]) return profile[0][1]; if(t >= profile[PLEN-1][0]) { done = true; // We are off the end of the time curve return profile[PLEN-1][1]; } for(int i = 1; i < PLEN-1; i++) { if(t <= profile[i][0]) return (int)(profile[i-1][1] + ((t - profile[i-1][0])*(profile[i][1] - profile[i-1][1]))/ (profile[i][0] - profile[i-1][0])); } return 0; } // Measure the actual temperature from the thermocouple int temperature() { return ( 5.0 * analogRead(tempPin) * 100.0) / 1024.0; } // Get the show on the road void setup() { pinMode(heatPin, OUTPUT); pinMode(tempPin, INPUT); Serial.begin(9600); Serial.println("\n\n\nTime, target, temp"); done = false; } // Go round and round void loop() { int t; unsigned long currentMillis = millis(); if(currentMillis - previousMillis > interval) { previousMillis = currentMillis; // set next time // Get the actual temperature t = temperature(); // One second has passed time++; // Find the target temperature int tg = target(time); // Simple bang-bang temperature control if (t < tg) { heatState = HIGH; } else { heatState = LOW; } // Turn the heater on or off (and the LED) digitalWrite(heatPin, heatState); // Keep the user amused if(done) { Serial.print((char)0x07); // Bell to wake the user up... Serial.print((char)0x07); Serial.print("FINISHED "); } Serial.print(time); Serial.print(", "); Serial.print(tg); Serial.print(", "); Serial.println(t); } }