Problem in merging in code with blynk code

  1. Add details :
    • Arduino UNO with USB
    • Smartphone OS : Android + version:Android 7
    • local server
    • Blynk Library version:0.5.1
    • Add your sketch code. :point_up:Code should be formatted as example below.

Simply paste your code between ``` If you don’t format your code, your topic can be deleted by moderators.

#include <SoftwareSerial.h>
#include <BlynkSimpleStream.h>
SoftwareSerial mySerial(9, 10);
SoftwareSerial DebugSerial(0, 1); // RX, TX

char auth[] = "b8b680f1b42f482691b00cb8fcc1bfb6";
#define PIEZO 13
#define LED 12
#define IR 4
#define SOUND 7
#define FIRE 2



int hasObstacle = HIGH;
int hasFire = HIGH;
int detectSound = HIGH;

void setup() {
  // put your setup code here, to run once:

  // Debug console
  DebugSerial.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(PIEZO, OUTPUT);
  pinMode(LED, OUTPUT);
  pinMode(IR, INPUT);
  pinMode(SOUND, INPUT);
  pinMode(FIRE, INPUT);
  Serial.begin(9600);
  mySerial.begin(9600);
  delay(1000); 
}

void loop() {
  
  hasObstacle = digitalRead(IR);  
  hasFire = digitalRead(FIRE);
  detectSound = digitalRead(SOUND);
   
  if(hasObstacle == HIGH) {
    Serial.println("Someone just entered your house.");
    digitalWrite(LED, HIGH);
    digitalWrite(PIEZO, HIGH);
    SendMessage("Someone just entered your house.");
    delay(1000);
  }
  else {
    Serial.println("No one is in the house");
    digitalWrite(LED, LOW);
    digitalWrite(PIEZO, LOW);
  }

  if(hasFire == LOW) {
    Serial.println("Your house just catched fire.");
    digitalWrite(LED, HIGH);
    digitalWrite(PIEZO, HIGH);
    SendMessage("Your house just catched fire.");
    delay(1000);
      
  }
  else {
    Serial.println("Your house is safe");
    digitalWrite(LED, LOW);
    digitalWrite(PIEZO, LOW);
  }

  if(detectSound == HIGH) {
    Serial.println("Someone just started speaking in your house.");
    digitalWrite(LED, HIGH);
    digitalWrite(PIEZO, HIGH);
    SendMessage("Someone just started speaking in your house.");
    delay(1000);
         
  }
  else {
    Serial.println("Your house is safe");
    digitalWrite(LED, LOW);
    digitalWrite(PIEZO, LOW);
  }
  delay(100);
  Blynk.run();
}

void SendMessage(String msg)
{
  Serial.println("Sending SMS");
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+917205722046\"\r"); // Replace x with mobile number
  delay(1000);
  mySerial.println(msg);// The SMS text you want to send
  delay(100);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}

although I see a lot of things ‘wrong’ with your code, you haven’t actually told us what the problem is? Perhaps you can give a description of what is going wrong?

To get you on the way with blynk implementation:

  1. move everything out of the void loop() except for the Blynk.run()
  2. put that in a separate function e.g. void detect()
  3. remove ALL delays in that code
  4. initiate detect in a timer; e.g. timer.setInterval(1000L, detect);
  5. put the timer.run() function in the loop as well.