For the convenience of all users the code attached as *.ino-file as a code-section
#include "max6675.h"
#include "LiquidCrystal_I2C.h"
#include "Wire.h"
#include "AccelStepper.h"
//thermocouple 1 FOR FLUE
int ktcSO = 8;
int ktcCS = 9;
int ktcCLK = 10;
//thermocouple 2 FOR FIREBOX
int ktc2SO = 5;
int ktc2CS = 6;
int ktc2CLK = 7;
//blower relay pin 4
int fanEnable = 4; //yellow wire, green wire at fan harness
int fanAuto = 11; //red wire
MAX6675 ktc(ktcCLK, ktcCS, ktcSO);
MAX6675 ktc2(ktc2CLK, ktc2CS, ktc2SO);
LiquidCrystal_I2C lcd(0x3F, A4, A5);
float temp;
float temp2;
// AccelStepper Setup
AccelStepper stepper(1, A1, A2); //AccelStepper(motorInterfaceType, stepPin, dirPin);
// 1 = Easy Driver type interface
// Pin A1 connected to STEP pin
// Pin A2 connected to DIR pin
const byte fullclose = 0; //fully close valve button
const byte load = 1; //opens the valve to load wood
const byte runposition = 2; //this sets the valve to the run position quickly
const byte home_switch = 3; //stops the stepper at home
int rpm; // new variable sets stepper speed
int location; //new variable for stepper location
int ENA = A3; //enables rotation of stepper
int enablefanLCD; //place to store the status of the fan enable signal which is only used for the LCD
int autofanLCD; //place to store the fan auto signal which is only used for the LCD
// Stepper
// Stepper Travel Variables
long initial_homing = -1; // Used to Home Stepper at startup
int runningposition = 330; //steps for valve close to running position
int fullyclosed = 0; //this is the steps to shut the valve fully
boolean alreadyRun = 0; //lock out valve from opening a second time w/o reset
boolean fandelay = 0; //delay for fan off timer when the open valve button is pressed
unsigned long previousMillis = 0; //stores last time display updated
const long interval = 7000; //this is the display refresh time
unsigned long fanMillis = 0; //stores last time fan off was updated
const long fan_delay = 150000; //this is the fan delay for loading wood
void setup() {
Serial.begin(9600);
delay(500); // give the MAX a little time to settle
lcd.init();
lcd.backlight();
lcd.clear();
lcd.print("BOOTING");
digitalWrite(fanEnable, LOW);
pinMode(fanEnable, OUTPUT);
digitalWrite(fanAuto, LOW);
pinMode(fanAuto, OUTPUT);
delay(1000);
//the following lines control stepper motor
pinMode(home_switch, INPUT_PULLUP);
pinMode(fullclose, INPUT_PULLUP);
pinMode(load, INPUT_PULLUP);
pinMode(runposition, INPUT_PULLUP);
pinMode(ENA, OUTPUT);
lcd.clear();
lcd.print("Homing......");
digitalWrite(ENA, LOW);
stepperHome();
digitalWrite(ENA, HIGH);
}
void loop() {
// basic readout test
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time the action happened
previousMillis = currentMillis;
digitalWrite(ENA, HIGH); //disables the stepper to allow accurate temperature readings
delay(150);
temp = (ktc.readFahrenheit() );
delay(50);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(temp);
lcd.print("F");
lcd.setCursor(8, 0);
lcd.print("FLUE TEMP");
temp2 = (ktc2.readFahrenheit() );
lcd.setCursor(0, 1);
lcd.print(temp2);
lcd.print("F");
lcd.setCursor(8, 1);
lcd.print("FIREBOX TEMP");
lcd.setCursor(0, 2);
lcd.print(round(stepper.currentPosition()) / 3625 * 100);
lcd.setCursor(5, 2);
lcd.print("%");
lcd.setCursor(8, 2);
lcd.print("THROTTLE");
//lcd.setCursor(0, 3);
enablefanLCD = (digitalRead(fanEnable));
autofanLCD = (digitalRead(fanAuto));
lcd.setCursor(0, 3);
if (enablefanLCD == 0) {
lcd.print("OFF");
}
else if (enablefanLCD == 1 && autofanLCD == 0) {
lcd.print("LOW");
}
else if (enablefanLCD == 1 && autofanLCD == 1) {
lcd.print("AUTO");
}
lcd.setCursor(8, 3);
lcd.print("FAN");
digitalWrite(ENA, LOW);//enables the stepper to allow motion
}
// begin establishing fan control parameters
if (temp2 >= 235) {
digitalWrite(fanEnable, HIGH); //enables the fan power relay
//delay(500);
digitalWrite(fanAuto, HIGH); //sets the signal to enable auto fan control
}
else if ((temp >= 250) && ((temp2 <= 230) && (temp2 >= 195.5))) {
digitalWrite(fanEnable, HIGH); //enables the fan power relay
digitalWrite(fanAuto, LOW);//sets the signal disable auto fan control
}
else if ((temp <= 250) && ((temp2 <= 230) && (temp2 >= 195.5))) {
digitalWrite(fanEnable, HIGH); //enables the fan power relay
digitalWrite(fanAuto, LOW);//sets the signal disable auto fan control
}
else if (temp2 <= 194.5) { //194.5
digitalWrite(fanEnable, LOW); //disables fan power relay
digitalWrite(fanAuto, LOW); //sets the signal to disable auto fan control
}
//end fan control establishment
//the following lines control stepper motor
if (digitalRead(load) == LOW) {//this will open the air valve and delay the blower fan
//while (digitalRead(load)== LOW)
//(fandelay == 0) //writes the fan millis delay time once
// {
// fanMillis = millis();// fixed fan delay time
//fandelay = 1; //disable the capture of the initial time used to delay the fan
//}
//delay(500);
//digitalWrite(fanEnable, LOW); //disable the fan
//if (currentMillis - fanMillis >= fan_delay) //fan disable timer
// {
// delay (150000);
//digitalWrite(fanEnable, HIGH); //enable the fan
//fandelay = 0; //enable the capture of the initial time used to delay the fan
//delay (500);
//}
digitalWrite(ENA, LOW); //enable stepper motor
stepperHome();
alreadyRun = 0;
delay (1000);
digitalWrite(ENA, HIGH);// disables stepper motor
}
if (digitalRead(fullclose) == LOW) {//this fully closes the air valve on button push and locks from reopen
alreadyRun = 1;
location = fullyclosed;
digitalWrite(ENA, LOW);
stepper.setMaxSpeed(500);//stepper.runSpeed();
stepper.setAcceleration(500);
stepper.moveTo(location);// Run to target position with set speed and acceleration/deceleration:
}
stepper.run();
if (stepper.distanceToGo() == 0) {
digitalWrite(ENA, HIGH);
}
if (digitalRead(runposition) == LOW) {
alreadyRun = 1;
location = runningposition;
digitalWrite(ENA, LOW);
stepper.setMaxSpeed(500);
stepper.setAcceleration(500);
stepper.moveTo(location); // Run to target position with set speed and acceleration/deceleration:
}
stepper.run();
if (stepper.distanceToGo() == 0) {
digitalWrite(ENA, HIGH);
}
if ((temp > 550) && (temp2 >= 195) && (alreadyRun == 0)) {//this wil close the air valve when the stove is coming up to temp
alreadyRun = 1;
location = runningposition;
digitalWrite(ENA, LOW); //enables the stepper motor
stepper.setMaxSpeed(3.5);
stepper.setAcceleration(5000);// Set the target position:
stepper.moveTo(location);// Run to target position with set speed and acceleration/deceleration
}
stepper.run();
if (stepper.distanceToGo() == 0) {
digitalWrite(ENA, HIGH); //disables the stepper motor
}
}
void stepperHome() {
stepper.setCurrentPosition(0);
stepper.setMaxSpeed(1000.0); // Set Max Speed of Stepper (Slower to get better accuracy)
stepper.setAcceleration(500.0); // Set Acceleration of Stepper
// Start Homing procedure of Stepper Motor at startup
Serial.print("Stepper is Homing . . . . . . . . . . . ");
while (digitalRead(home_switch)) {
// Make the Stepper move CCW until the switch is activated
stepper.moveTo(initial_homing); // Set the position to move to
initial_homing++; // Decrease by 1 for next move if needed
stepper.run(); // Start moving the stepper
delay(5);
}
stepper.setCurrentPosition(0); // Set the current position as zero for now
stepper.setMaxSpeed(100.0); // Set Max Speed of Stepper (Slower to get better accuracy)
stepper.setAcceleration(100.0); // Set Acceleration of Stepper
initial_homing = 1;
while (!digitalRead(home_switch)) {
// Make the Stepper move CW until the switch is deactivated
stepper.moveTo(initial_homing);
stepper.run();
initial_homing--;
delay(5);
}
stepper.setCurrentPosition(3625);
Serial.println("Homing Completed");
}
You had some doubled and some unescessary curly braces in your code
I removed them
As you are working on a project where the arduino shall control a fire
the whole code should be written to follow the non-blocking paradigma.
This is a medium advanced programming-technique that requires quite some learning
The non-blocking code will even eliminate the second arduino if you wish.
Would you like to learn it?
Your functional description given in post # 1 is not really clear to me
What kind of signal?
I guess voltage 0V / 5V logical LOW / HIGH
what is the reaction of the signal-receiving Arduino if this arduino receives signal LOW ?
what is the reaction of the signal-receiving Arduino if this arduino receives signal HIGH?
This button is connected to which arduino?
wood-feeder-arduino?
or
air-blower-control-arduino?
delay() for exactly what?
Is this more precise version of your question correct?
"How can a switch OFF the air-blower for 150 seconds if I press the "load-wood-button"?
If not correct post the corrected question
best regards Stefan