bugis33:
Thank you for responding to my request for help. I want to control the 8 channel relay block with this code using 3 thermocouples and a flame sensor. It should be noted that when the temp1 does not reach the specified temperature and the flame sensor is inactive, pin_4 should be operated at intervals of 5 and 10 seconds and pin_8 at intervals of 7 and 10 seconds, and when the flame sensor is activated and the temperature is still lower than the specified pin_8, it should be LOW and pin_4 should be in range 3 and 7 seconds. when it reaches the highest specified temperature pin_4 and pin_8 to be LOW, but every 20 seconds they get "HIGH" for about a quarter of a second
I use the FSM for the timer.
those curly brackets are just a mistake. I've made some changes to my colleague comments, but no one changes.
This
if (temp1 <= 20 && flame_pin, HIGH)
{
fsm_doz.check_timer();
fsm_uzd.check_timer();
}
else if (temp1 <= 20 && flame_pin, LOW)
{
fsm1_doz.check_timer();
fsm1_uzd.check_timer();
}
should be
if (temp1 <= 20 && flame_pin == HIGH)
{
fsm_doz.check_timer();
fsm_uzd.check_timer();
}
else if (temp1 <= 20 && flame_pin == LOW)
{
fsm1_doz.check_timer();
fsm1_uzd.check_timer();
}
I don't know about the fsm code, all it does, but it seems there's either too much or not enough code since in loop() it only does time check calls with no off/off/reset that I would expect if the timers do not run over and over which they should not. Perhaps they only run once and the code to start them up is missing, I dunno.
You have fsm and fsm1 with added functions to turn pins on and off as well as loop() code managing the same pins which may be a source of error.
You also have many serial prints to help track what is happening. I would print millis() at the start of all of those reports to know the when as well as the what of each. You might even print more info to track the code execution all the way through and print critical values, we call these 'debug prints' to help find bugs.
I write my own timers, it makes life easier. I write my own state machines too. These tutorials teach those with timers in the first and state machine in the second (but not at the top, scroll down or edit->find the word machine).
- Gammon Forum : Electronics : Microprocessors : How to do multiple things at once ... like cook bacon and eggs
- Gammon Forum : Electronics : Microprocessors : How to process incoming serial data without blocking
One state machine could handle this whole job though you'd have to define the states and actions to do it.
Serial.begin() should be a higher value than 9600. It should be fast as it can (or at least 115200) to empty the print queue quicker, do not forget to change the baud rate of serial monitor to match.