int output = 0; int temp = 0; int settemp = 630; String inputString = ""; // a string to hold incoming data boolean rap = false; boolean stringComplete = false; // whether the string is complete int t = 0; void setup() { Serial.begin(9600); inputString.reserve(200); pinMode(6, OUTPUT); digitalWrite(6, LOW); } void loop() { serialEvent(); if (stringComplete) { Serial.println(inputString); t = inputString.toInt(); //settemp = t //sets the set temp to the serial input inputString = ""; stringComplete = false; } rapid(); pid(); } void rapid() { //Controls the soldering iron by rapidly heating it up in the beginning. if (rap == false) { digitalWrite(6, HIGH); do { temp = analogRead(0); Serial.print("rapid"); Serial.println(temp); } while (temp - settemp > 10); digitalWrite(6, LOW); rap = true; } } void pid() { //Controls the soldering with slow active power heating. temp = analogRead(0); output = temp - settemp; if (output < 0) { output = 0; } if (output > 255) { output = 255; } Serial.print("pid"); Serial.print(temp); Serial.print(", "); Serial.println(output); analogWrite(6, output); } void serialEvent() { //Serial communication that can be used to update settemp while (Serial.available()) { char inChar = (char)Serial.read(); inputString += inChar; if (inChar == '\n') { stringComplete = true; } } }