FSM code question

Hi there,
I am in the process of building a gas burner and ignitor controller and have found some code that appears to work but the maker is no longer available (hopefully he didn’t blow himself up).

I’ve attached the code and it compiles ok, but only does so in an old version of the IDE 1.0.5 R2.
I’ve also attached the circuit layout that came with the code.

It compiles ok but I have some questions and I don’t know how to read the code.

For example, what does it mean when pin 8 is flashing?
Ping 2 and 3 are an earth trigger?

If someone can help me dissect and understand this code, that would be greatly appreciated :slight_smile:

FiniteStateMachine.h (3.34 KB)

StandaloneBurner.ino (4.71 KB)

I’ve downloaded the FSM from https://playground.arduino.cc/Code/FiniteStateMachine; is that the version that you’re using? If not, please post a link.

Your code will compile in newer IDEs (the system I’m working on has 1.6.6 installed, did not update yet) if you include Arduino.h instead of WProgram.h in FiniteStateMachine.h


//#include <WProgram.h>
#include <Arduino.h>


By the looks of it, there are newer versions of the library that might have solved the above problem for you.

and if you add the function prototypes in the beginning of StandaloneBurner.ino

#include "FiniteStateMachine.h"

// function prototypes
void enterOff();
void updateOff();
void exitOff();

void enterOn();
void updateOn();
void exitOn();

void enterLighting();
void updateLighting();
void exitLighting();

void updateAlarm();

State Off = State(enterOff, updateOff, exitOff); // burner is off


Not sure what you mean by “earth trigger”. Pins 2 and 3 (from your diagram) control the respective relays. Both of those relays miss one wire in your drawing (by the looks of it); a relay has two (or three) pins that you connect the ‘device’ to (in your case the valve or the igniter) and two pins that are connected to the Arduino.

I will see what I can find about the flashing led; not familiar with the library so might not be able to find it.

The flashing LED on pin 8 appears the be the Alarm which means your burner failed to light or went out.

There is also a fundamental flaw in your code with the timing around how long to wait when trying to light, etc. It calculates the end time as the current time [millis()] plus the duration and then check for millis() being less than end time. This will usually work, but will break when millis() rolls over to 0.