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…
Thanks…
Code:
// 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>
//DHT22
#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
DHT dht(DHTPIN, DHTTYPE);
int loopCount;
HC_SR04 rangeFinder = HC_SR04(trigPin, echoPin);
// Set-up
void setup()
{
// DHT22
Serial.begin(9600);
Blynk.begin(auth);
Serial.println("Starting Vault-Eye");
Particle.publish("state", " Vault-Eye Monitoring Sytem Online");
dht.begin();
loopCount = 0;
delay(1000);
pinMode(GasSensor, INPUT); //Gas Sensor MQ2
heightLevel=100;
deviation=10;
}
void loop()
{
Blynk.run();
// For HC_SR04
inches = rangeFinder.getDistanceInch();
percentage=100-(((inches-deviation)*100)/heightLevel);
// 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!");
return;
}
// Must send in temp in Fahrenheit!
float hi = dht.getHeatIndex();
float dp = dht.getDewPoint();
float k = dht.getTempKelvin();
Serial.print("Humid: ");
Serial.print(h);
Serial.print("% ");
Serial.print("Temp: ");
Serial.print(f);
Serial.print("*F ");
Serial.println(Time.timeStr());
//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));
delay(1000);
Particle.publish("Indoor Air Quality (ppm)", strTxt);
delay(2000);
Particle.publish("Height (inches)", (String) inches, 60, PRIVATE);
if (percentage < 10)
Particle.publish("Water Level High", String(percentage), 60, PRIVATE);
delay(3000);
}