/**************************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers
Pick one up today in the adafruit shop!
------> http://www.adafruit.com/category/63_98
This example is for a 128x64 pixel display using I2C to communicate
3 pins are required to interface (two I2C and one reset).
Adafruit invests time and resources providing this open
source code, please support Adafruit and open-source
hardware by purchasing products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries,
with contributions from the open source community.
BSD license, check license.txt for more information
All text above, and the splash screen below must be
included in any redistribution.
**************************************************************************/
//#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define VERSION "Reflow Controller 1.0"
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO: A4(SDA), A5(SCL)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES 10 // Number of snowflakes in the animation example
#define LOGO_HEIGHT 16
#define LOGO_WIDTH 16
// Pin definitions
const int thermistorPin = A0;
const int relayPin = 5; // Relay connected to pin D5
const int buttonUpPin = 2; // Up button
const int buttonDownPin = 3; // Down button
const int buttonSelectPin = 4; // Select button
// Reflow parameters
int preheatTemp = 150; // Initial preheat temperature (°C)
int preheatTime = 90; // Initial preheat time (seconds)
int soakTemp = 180; // Initial soak temperature (°C)
int soakTime = 90; // Initial soak time (seconds)
int reflowTemp = 250; // Initial reflow temperature (°C)
int reflowTime = 30; // Initial reflow time (seconds)
// Adjustable settings
int settingIndex = 0; // Index to track which setting is being adjusted
const int totalSettings = 6; // Total number of adjustable settings
// Control variables
bool reflowRunning = false;
unsigned long startTime;
int currentPhase = 0; // 0 = stopped, 1 = preheat, 2 = soak, 3 = reflow
int currentTemperature = 0;
// Thermistor parameters
const float BETA = 3950; // Beta coefficient
const float SERIES_RESISTOR = 10000; // 10k series resistor
// Function prototypes
void readTemperature();
void updateDisplay();
void handleButtons();
void controlRelay();
void adjustSettings();
/*
*/
void setup() {
Serial.begin(9600);
int tempA = 60;
int timeA = 200;
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.clearDisplay();
display.setTextSize(1.3);
display.setTextColor(SSD1306_WHITE);
// Display the curent App details
display.println(VERSION);
display.display();
delay(2000);
// display.display() is NOT necessary after every single drawing command,
// unless that's what you want...rather, you can batch up a bunch of
// drawing operations and then update the screen all at once by calling
// display.display(). These examples demonstrate both approaches...
// Button pin modes
pinMode(buttonUpPin, INPUT_PULLUP);
pinMode(buttonDownPin, INPUT_PULLUP);
pinMode(buttonSelectPin, INPUT_PULLUP);
// Relay pin mode
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, LOW); // Start with relay off
display.clearDisplay();
display.setCursor(0, 0);
}
void loop() {
readTemperature();
handleButtons();
updateDisplay();
controlRelay();
display.display();
display.setCursor(0, 0);
delay(200); // Short delay for debounce
}
/*
/*
display.print("Temp is: ");
display.print(tempA);
// display.display();
// display.setCursor(90, 0);
display.println(" 'C");
// line 2
display.println("");
display.print("Time is: ");
display.print(timeA);
display.println(" min");
// line 3
display.println("");
display.println("Set/Start/Stop");
display.display();
delay(2000);
*/
void readTemperature() {
int analogValue = analogRead(thermistorPin);
float resistance = SERIES_RESISTOR / ((1023.0 / analogValue) - 1);
float temperature = 1 / (log(resistance / 100000) / BETA + 1.0 / 298.15) - 273.15;
currentTemperature = round(temperature);
}
void updateDisplay() {
display.clearDisplay();
// lcd.clear();
// lcd.setCursor(0, 0);
if (reflowRunning) {
// Display current phase and temperature
// OLED version
// display.setTextSize(2);
// display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print("Temp: ");
display.print(currentTemperature);
display.println(" 'C");
// display.display();
// lcd.setCursor(0, 1);
switch (currentPhase) {
case 1:
display.println("Phase: Preheat");
break;
case 2:
display.println("Phase: Soak");
break;
case 3:
display.println("Phase: Reflow");
break;
default:
display.println("System: Stopped");
break;
}
} else {
// Display adjustable settings
switch (settingIndex) {
case 0:
display.print("Preheat Temp: ");
display.print(preheatTemp);
display.print((char)247);
display.println("C");
break;
case 1:
display.print("Preheat Time: ");
display.print(preheatTime);
display.println(" sec");
break;
case 2:
display.print("Soak Temp: ");
display.print(soakTemp);
display.print((char)247);
display.println("C");
break;
case 3:
display.print("Soak Time: ");
display.print(soakTime);
display.println(" sec");
break;
case 4:
display.print("Reflow Temp: ");
display.print(reflowTemp);
display.print((char)247);
display.println("C");
break;
case 5:
display.print("Reflow Time: ");
display.print(reflowTime);
display.println(" sec");
// display.display();
break;
}
// lcd.setCursor(0, 1);
display.println("Set/Run/Stop: */#/=");
// display.display();
}
// display.display();
// delay(1000);
// display.setCursor(0, 0);
}
void handleButtons() {
if (!digitalRead(buttonUpPin)) {
if (!reflowRunning) {
// Increase the current setting value
adjustSettings(1);
}
}
if (!digitalRead(buttonDownPin)) {
if (!reflowRunning) {
// Decrease the current setting value
adjustSettings(-1);
}
}
if (!digitalRead(buttonSelectPin)) {
if (reflowRunning) {
// Stop reflow process
reflowRunning = false;
digitalWrite(relayPin, LOW); // Turn off relay
currentPhase = 0;
} else {
// Start reflow process
reflowRunning = true;
startTime = millis();
currentPhase = 1; // Start with preheat phase
}
}
}
void adjustSettings(int change) {
switch (settingIndex) {
case 0:
preheatTemp = constrain(preheatTemp + change, 100, 200); // Adjust preheat temperature (100-200°C)
break;
case 1:
preheatTime = constrain(preheatTime + change, 30, 120); // Adjust preheat time (30-120 seconds)
break;
case 2:
soakTemp = constrain(soakTemp + change, 150, 200); // Adjust soak temperature (150-200°C)
break;
case 3:
soakTime = constrain(soakTime + change, 30, 120); // Adjust soak time (30-120 seconds)
break;
case 4:
reflowTemp = constrain(reflowTemp + change, 200, 260); // Adjust reflow temperature (200-260°C)
break;
case 5:
reflowTime = constrain(reflowTime + change, 10, 60); // Adjust reflow time (10-60 seconds)
break;
}
settingIndex = (settingIndex + 1) % totalSettings; // Move to the next setting
}
void controlRelay() {
if (reflowRunning) {
unsigned long elapsedTime = millis() - startTime;
if (currentPhase == 1) {
// Preheat phase
if (currentTemperature < preheatTemp) {
digitalWrite(relayPin, HIGH); // Turn on relay
} else {
digitalWrite(relayPin, LOW); // Turn off relay
}
if (elapsedTime >= preheatTime * 1000) {
currentPhase = 2; // Move to soak phase
startTime = millis(); // Reset timer
}
} else if (currentPhase == 2) {
// Soak phase
if (currentTemperature < soakTemp) {
digitalWrite(relayPin, HIGH); // Turn on relay
} else {
digitalWrite(relayPin, LOW); // Turn off relay
}
if (elapsedTime >= soakTime * 1000) {
currentPhase = 3; // Move to reflow phase
startTime = millis(); // Reset timer
}
} else if (currentPhase == 3) {
// Reflow phase
if (currentTemperature < reflowTemp) {
digitalWrite(relayPin, HIGH); // Turn on relay
} else {
digitalWrite(relayPin, LOW); // Turn off relay
}
if (elapsedTime >= reflowTime * 1000) {
reflowRunning = false; // Stop the system
digitalWrite(relayPin, LOW); // Turn off relay
currentPhase = 0; // Reset to initial state
}
}
}
}