Hello, I am fairly new to blynk and I am using it to control multiple sensors and a servo via Arduino Mega. When I first start the project up, it works beautifully. The ir temperature and distance updates quickly and the servo responds (though that is a bit glitchy). But after a couple of minutes, everything stops responding. The sensor read-outs stop updating and the servo will no longer respond. Am I flooding the system? The code is attached below:
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial1
//Libraries
#include <BlynkSimpleStream.h>
#include <Servo.h>
#include "IRTemp.h"
//Authorization
char auth[] = "af30119367fd4b9ea111f78318fd9b14";
//UR Pines
#define trigPin 10
#define echoPin 13
//IR Pins
static const byte PIN_DATA = 2; // Choose any pins you like for these
static const byte PIN_CLOCK = 3;
static const byte PIN_ACQUIRE = 4;
//Alarm Pins
#define Light_PIN 5
#define Buzz_PIN 6
Servo servo;
BlynkTimer timer;
int heat = 80;
static const TempUnit SCALE=FAHRENHEIT; // Options are CELSIUS, FAHRENHEIT
IRTemp irTemp(PIN_ACQUIRE, PIN_CLOCK, PIN_DATA);
long duration, distance; // Duration used to calculate distance
float irTemperature, ambientTemperature;
int t1;
BLYNK_WRITE(V3)
{
servo.write(param.asInt()); // Servo
}
// Enable/disable blinking using virtual pin 4
BLYNK_WRITE(V4)
{
if (param.asInt()) {
timer.enable(t1);
} else {
timer.disable(t1);
digitalWrite(Light_PIN, LOW);
digitalWrite(Buzz_PIN, LOW);
}
}
// Change blink interval using virtual pin 5
BLYNK_WRITE(V5)
{
long interval = param.asLong();
boolean wasEnabled = timer.isEnabled(t1);
timer.deleteTimer(t1);
t1 = timer.setInterval(interval, alarmBlynk);
if (!wasEnabled) {
timer.disable(t1);
}
}
BLYNK_READ(V8){
Blynk.virtualWrite(8,distance);// virtualpin 8 distance
}
BLYNK_READ(V1){
Blynk.virtualWrite(1,irTemperature);// virtualpin 1 ir temperature
}
BLYNK_READ(V2){
Blynk.virtualWrite(2,ambientTemperature);// virtualpin 2 ambient temperature
}
void setup(){
// Debug console
Serial1.begin(9600);
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
timer.setInterval(1000, measureDistance);
timer.setInterval(1000, IRread);
servo.attach(9);
// Configure LED and timer
pinMode(Light_PIN, OUTPUT);
pinMode(Buzz_PIN, OUTPUT);
t1 = timer.setInterval(500L, alarmBlynk);
timer.disable(t1);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates SimpleTimer
}
//UR Sensor
void measureDistance()
{
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
//Serial.println(distance);
}
void IRread() {
irTemperature = irTemp.getIRTemperature(SCALE);
ambientTemperature = irTemp.getAmbientTemperature(SCALE);
}
void alarmBlynk(){
digitalWrite(Light_PIN, !digitalRead(Light_PIN));
digitalWrite(Buzz_PIN, !digitalRead(Buzz_PIN));
}