Getting "Stack Overflow" error on Particle

I have a Particle Electron on a Control Everything MCP23008 Relay board.

I’m turning on a heater and after a timer runs out, I want to turn it off.
When I run the function to turn off the heater, the Electron starts blinking red (SOS) with the Stack Overflow error when I try to set LED like this…;

Complete Code below…
Please Help! I’ve been stuck on this problem for two days, in which I’ve tried every conceivable way I can think of.

If I uncomment lines 71 or 72, I get the stack overflow error.
_ // Blynk.virtualWrite(V12, “On”);_
_ //led1.setvalue(250);_

// This #include statement was automatically added by the Particle IDE.
#include "NCD2Relay/NCD2Relay.h"
#include "blynk/blynk.h"

//#define BLYNK_DEBUG       // Uncomment this to see debug prints
#define BLYNK_PRINT Serial

NCD2Relay relayController; // Relay Controller Object 

char auth[] = "auth Code ";//Authorization Token for blynk

WidgetLED led1(V11); // widget 'type' for Relay 1
WidgetLED led2(V12); // widget 'type' for Relay 2

int relay1Control = 0;
int relay2Control = 0;
int relay1Status = 0; // relay 1 Status
int relay2Status = 0; // relay 2 Status 

int offDelayMinutes = 5; //Timer for Off delay on Relays

Timer offDelayTimer(10000 , turnOffHeater, true);//Off delay Timer for Heater

//SYSTEM_MODE(SEMI_AUTOMATIC);//runs Code even if there is no cell connection

void setup() {
    Serial.println("Setup Started");
    relayController.setAddress(0,0,0);// Start Relay Controller Object
    Blynk.begin(auth, IPAddress(45,55,130,102), 8442);//Start Connection to Blynk Servers

    FuelGauge fuel;//Create Battery charged object
    Serial.println( fuel.getSoC() );//Prints the battery Level in Percent
    Serial.println("Setup Done");;;
//*************************************Main Loop********************************************
void loop() {;// Start Blynk!

void turnOffHeater(){
    relay1Status = relayController.readRelayStatus(1);
void turnOnHeater(){
    Serial.println("Turning On Heater");

    relay1Control = param.asInt();
    Serial.println(relay1Control);//print relay 1 Control
    if (relay1Control == 1){ turnOnHeater(); }
 void turnOffLED1(){
  Serial.println("inside turn off LED");
 // Blynk.virtualWrite(V12, "On");

What do you mean??
Which widget are you using for turning on the heater??

The offDelayTimer starts as a one-shot Timer in the turnOnHeater() function.

I can get the relay to come on, but when the timer runs out and relay turns off I call the function and the Electron goes into SOS Mode, until I comment out that part of the code.

I’m using a Button on the Blynk app to turn on the relay.

Are you able to upload new code??
What do you want ??
And what purpose you are using this timer’s??

Use else statement to call turnoff function.

After it goes into SOS Mode, it automatically restarts and the sketch runs as it should, but the LED on the app never goes off.
Yes, I can upload new code to it, I’ve done that over 50 times now trying to figure out what I’m doing wrong.

The Timer is basically a off delay for the relay which turns off a heater after a set amount of time.

I’ve already tried a if statement, but I’ll try again.

Use simple code for testing &
Remove all the timmers and make it work only on button.

I guess I’ll do that.

So I finally found this.

On the very last post.
Seems like Software Timers and Blynk won’t work together.

Thanks for the Help saurabh47.

Looks like sometimes you just need somebody to tell you to ‘step back and restart’.

1 Like

Have you solved your problem??

The problem was using Software Timer and Blynk together.

I’m now looking for a simple solution to set a off Delay on my relay.

Use simple timer function for relay this will work as charm.
guidance for simpletimer function is available in docs.
Never use delay’s for Blynk