Hard_Fault - PhotonH and Blynk

I’m using two Particle PhotonH … I’m running the same code in both devices with two different Blynk auth: tokens… After flashing, I can read all the readings through console and through Blynk app…

After running the devices for few minutes, both devices reset, and they go through Hard_Fault… after 30 seconds they become normal… but every 5 minutes, both devices rest, turning red…

How can I solve this…


// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT_Particle.h>

// This #include statement was automatically added by the Particle IDE.
#include <HC_SR04.h>

// This #include statement was automatically added by the Particle IDE.
#include <blynk.h>

    #define DHTPIN D2     // what pin we're connected to for dht22
    #define DHTTYPE DHT22		// DHT 22 (AM2302)

// Initialize
    // For HC_SR04
    int inches = 0;
    int percentage,heightLevel, deviation;
    int trigPin = D4;
    int echoPin = D5;
    char auth[] = "9205e5e0b6d049f8800776b04ac398a0";
    // For MQ2
    int GasSensor = A0;
    char strTxt[40];
    // For DHT22
    // Connect pin 1 (on the left) of the sensor to +5V
    // Connect pin 2 of the sensor to whatever your DHTPIN is
    // Connect pin 4 (on the right) of the sensor to GROUND
    // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
    int loopCount;
    HC_SR04 rangeFinder = HC_SR04(trigPin, echoPin);
// Set-up

void setup() 
    // DHT22 
	Serial.println("Starting Vault-Eye");
	Particle.publish("state", " Vault-Eye Monitoring Sytem Online");

	loopCount = 0;
	pinMode(GasSensor, INPUT); //Gas Sensor MQ2
void loop()
    // For HC_SR04
    inches = rangeFinder.getDistanceInch();
    // FOr MQ2
    sprintf(strTxt, "%u", analogRead(GasSensor));
    // For DHT22
    	float h = dht.getHumidity();
    // Read temperature as Celsius
	    float t = dht.getTempCelcius();
    // Read temperature as Farenheit
	    float f = dht.getTempFarenheit();
    // Check if any reads failed and exit early (to try again).
	    if (isnan(h) || isnan(t) || isnan(f))
		Serial.println("Failed to read from DHT sensor!");

    // Must send in temp in Fahrenheit!
    	float hi = dht.getHeatIndex();
    	float dp = dht.getDewPoint();
    	float k = dht.getTempKelvin();

    	Serial.print("Humid: "); 
	    Serial.print("% ");
	    Serial.print("Temp: "); 
	    Serial.print("*F ");
	    //String timeStamp = Time.timeStr();
	   Blynk.virtualWrite(V1, f);
	   Blynk.virtualWrite(V2, h);
	   Blynk.virtualWrite(V3, strTxt);
	   Blynk.virtualWrite(V4, inches);
	   Blynk.virtualWrite(V5, f);
	   Blynk.virtualWrite(V6, h);
	   Blynk.virtualWrite(V7, strTxt);
	   Blynk.virtualWrite(V8, inches);
       Particle.publish("Temperature & Humidty Status", String::format("\Humidity(%%)\: %4.2f - \Temperature(°F)\: %4.2f", h, f));

	   Particle.publish("Indoor Air Quality (ppm)", strTxt);

	   Particle.publish("Height (inches)", (String) inches, 60, PRIVATE);
	 if (percentage < 10)
        Particle.publish("Water Level High", String(percentage), 60, PRIVATE);

Please descripe what happend if you deactivate the Blynk-Statements (//). Do you get the same error image?

Blynk.run() should not be delayed.
To achieve that you should replace your delay() statements with non-blocking logic (aka soft delay or millis() delay).
You may want to replace String objects with C strings (char[]) too.

And maybe just use one combined publish instead of 3 or 4.

Hi ScruffR, thanks for the reply… Im new to Particle and Blynk… If you can please be kind enough to post what needs to be fix to avoid the HARD_FAULT…

Thank You