nodemcu resets itself

Hi there,

I have been working on a project and tried out this code but unfortunately the system reboots. I am not sure whats wrong with it.

HERE IS THE CODE

#include <ESP8266WiFi.h>
#include<FirebaseArduino.h>
#define FIREBASE_HOST “homeautomation-4686a.firebaseio.com” //Your Firebase Project URL goes here without “http:” , “” and “/”
#define FIREBASE_AUTH “ZhQ2RKIDTbbnQ9ug2n8sqdyVQtIxhY9” //Your Firebase Database Secret goes here
#define WIFI_SSID “RUSH @ NETWORK” //your WiFi SSID for which yout NodeMCU connects
#define WIFI_PASSWORD “m3” //Password of your wifi network

#define Relay1 12 //D6
int val1;

#define Relay2 14 //D2
int val2;

#define Relay3 4 //D1
int val3;

#define Relay4 5 //D5
int val4;

void setup()
{
Serial.begin(115200); // Select the same baud rate if you want to see the datas on Serial Monitor
pinMode(Relay1,OUTPUT);
pinMode(Relay2,OUTPUT);
pinMode(Relay3,OUTPUT);
pinMode(Relay4,OUTPUT);

digitalWrite(Relay1,HIGH);
digitalWrite(Relay2,HIGH);
digitalWrite(Relay3,HIGH);
digitalWrite(Relay4,HIGH);

WiFi.begin(WIFI_SSID,WIFI_PASSWORD);
Serial.print(“connecting”);
while (WiFi.status()!=WL_CONNECTED){
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print(“connected:”);
Serial.println(WiFi.localIP());

Firebase.begin(FIREBASE_HOST,FIREBASE_AUTH);

Firebase.setInt(“S1”,0); //Here the varialbe"S1",“S2”,“S3” and “S4” needs to be the one which is used in our Firebase and MIT App Inventor
Firebase.setInt(“S2”,0);
Firebase.setInt(“S3”,0);
Firebase.setInt(“S4”,0);

}
void firebasereconnect()
{
Serial.println(“Trying to reconnect”);
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

void loop()
{

val1=Firebase.getString(“S1”).toInt(); //Reading the value of the varialble Status from the firebase

if(val1==1) // If, the Status is 1, turn on the Relay1
{
digitalWrite(Relay1,LOW);
Serial.println(“light 1 ON”);
}
else if(val1==0) // If, the Status is 0, turn Off the Relay1
{
digitalWrite(Relay1,HIGH);
Serial.println(“light 1 OFF”);
}

val2=Firebase.getString(“S2”).toInt(); //Reading the value of the varialble Status from the firebase

if(val2==1) // If, the Status is 1, turn on the Relay2
{
digitalWrite(Relay2,LOW);
Serial.println(“light 2 ON”);
}
else if(val2==0) // If, the Status is 0, turn Off the Relay2
{
digitalWrite(Relay2,HIGH);
Serial.println(“light 2 OFF”);
}

val3=Firebase.getString(“S3”).toInt(); //Reading the value of the varialble Status from the firebase

if(val3==1) // If, the Status is 1, turn on the Relay3
{
digitalWrite(Relay3,LOW);
Serial.println(“light 3 ON”);
}
else if(val3==0) // If, the Status is 0, turn Off the Relay3
{
digitalWrite(Relay3,HIGH);
Serial.println(“light 3 OFF”);
}

val4=Firebase.getString(“S4”).toInt(); //Reading the value of the varialble Status from the firebase

if(val4==1) // If, the Status is 1, turn on the Relay4
{
digitalWrite(Relay4,LOW);
Serial.println(“light 4 ON”);
}
else if(val4==0) // If, the Status is 0, turn Off the Relay4
{
digitalWrite(Relay4,HIGH);
Serial.println(“light 4 OFF”);
}

}

HERE IS WHAT SERIAL PORT SAYS

Exception (9):
epc1=0x4020b068 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000036 depc=0x00000000

stack>>>

ctx: cont
sp: 3ffffc80 end: 3fffffc0 offset: 01a0
3ffffe20: 0000000b 3ffee980 3ffefa50 4020589c
3ffffe30: 3ffe87be 000001bb 3ffefa50 40206774
3ffffe40: 3ffe8875 0000003b 3ffefa50 40206bbc
3ffffe50: 0000003b 3ffee980 0000002e 40203668
3ffffe60: 3ffffea8 0000003b 3ffffe90 4020755c
3ffffe70: 3ffee97c 3ffffe90 3ffe8875 3fffff10
3ffffe80: 3ffee97c 3ffffed4 3ffefa4c 40204f1b
3ffffe90: 3ffef7e4 003b003f 00fffed4 3ffefb54
3ffffea0: 0036003f 00ffff8c 3ffefd24 0023002f
3ffffeb0: 00fe880b 3ffee978 3fffff8e 3fffff10
3ffffec0: 3ffee97c 3ffe87f2 3ffef8dc 40202ca8
3ffffed0: 3ffe880b 3ffefce8 3ffefd44 3ffeea54
3ffffee0: 3fffff8c 3fffff10 3ffe880b 4020362c
3ffffef0: 3fffff18 3fffff30 3fffff30 3ffeea54
3fffff00: 3fffff8c 3ffef8dc 3ffee978 40203f1d
3fffff10: 3ffee9b8 3ffefaf0 004e4f20 40209145
3fffff20: 3fffdad0 3ffee978 3fffff80 40203f5e
3fffff30: 40105231 0116b78c 3ffeeab0 00000000
3fffff40: 00000002 3ffeeab0 000003e8 3ffeea54
3fffff50: 3fffdad0 00000002 3fffff8c 4020755c
3fffff60: 3fffdad0 3fffff8c 3ffe873c 40207592
3fffff70: 3fffdad0 00000000 3ffee978 402011dd
3fffff80: 00000000 00000000 00000001 40003153
3fffff90: 3fffdad0 82000000 3ffeea14 40100175
3fffffa0: feefeffe 00000000 3ffeea14 40208400
3fffffb0: feefeffe feefeffe 3ffe8580 40100c49
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1392, room 16
tail 0
chksum 0xd0
csum 0xd0
v3d128e5c
~ld

thanks in advance

Exception 9 is an illegal mis-aligned memory access. Most likely, something, somewhere is using a bogus pointer to access something. Almost certainly something in that Firebase library (whatever that is....).

Litter the code with calls to the following function, passing in messages to let you know where the code is executing, to get a clue WHERE it is failing:

void waitUser(char *s)
{
    Serial.println(s);
    while (!serial.available())
        ;
    while (!serial.available())
    {
        Serial.read();
        delay(10);
    }
}

Regards, Ray L.