Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Jeremy
#59951 Hi there,

I have what I had hoped would be a simple project, but it hasn't worked out that way. I could really use some advice. If I have come to the wrong forum, please direct me where I should be asking this.

I am designing a simple house alarm with four door/window inputs and a chime, siren and strobe output. I threw together a PCB and I am having several problems. I have attached the schematic and code.

1st: Adafruit Huzzah Feather keeps locking up. I can only program it off of the PCB as it doesn't want to program at all on the PCB. It seems to be locking up during the main "else" statement.

2nd: I am getting weird results from the Blynk portion of the code. Maybe I am not understanding how it all works although I think I have a pretty good idea.

Please don't laugh at my code, but if you see any serious mistakes please let me know.

Code: Select all/**************************************************************
   Blynk is a platform with iOS and Android apps to control
   Arduino, Raspberry Pi and the likes over the Internet.
   You can easily build graphic interfaces for all your
   projects by simply dragging and dropping widgets.

     Downloads, docs, tutorials: http://www.blynk.cc
     Blynk community:            http://community.blynk.cc
     Social networks:            http://www.fb.com/blynkapp
                                 http://twitter.com/blynk_app

   Blynk library is licensed under MIT license
   This example code is in public domain.

 **************************************************************
   This example runs directly on ESP8266 chip.

   Note: This requires ESP8266 support package:
     https://github.com/esp8266/Arduino

   Please be sure to select the right ESP8266 module
   in the Tools -> Board menu!

   Change WiFi ssid, pass, and Blynk auth token to run :)

 **************************************************************/

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

//--------------------------------------------------------------------------------
//variables and WIFI credentials


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "4d422895f8bc4f2294b79edc93fa0e02";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Sid";
char pass[] = "password";

//unchanging variables
const int alarmPin1 = 15; //reed switches for the doors
const int alarmPin2 = 13;
const int alarmPin3 = 12;
const int alarmPin4 = 14;
const int chimePin = 4; //chime beeps when door is opened
const int sirenPin = 5; //siren screams when door is opened

//variables
int armState = 0;
int chimeState = 1; //state of the chime pin
int sirenState = 0; //state of the siren pin
int buttonState1 = 0; //State of the reed switches
int buttonState2 = 1;
int buttonState3 = 1;
int buttonState4 = 1;
int chimedOnce = 0; //activate/deactivate the chime pin

//--------------------------------------------------------------------------------
// Main setup

void setup()
{
  Serial.begin(57600);
  Blynk.begin(auth, ssid, pass);
  pinMode(alarmPin1, INPUT); //sets alarmPin1 as an input pin
  pinMode(alarmPin2, INPUT); //sets alarmPin2 as an input pin
  pinMode(alarmPin3, INPUT); //sets alarmPin3 as an input pin
  pinMode(alarmPin4, INPUT); //sets alarmPin4 as an input pin
  pinMode(chimePin, OUTPUT); //sets chimePin as output
  //pinMode(sirenPin, OUTPUT); //sets sirenPin as output
}

//---------------------------------------------------------------------------------
//Blynk Functions (virtual pins)

BLYNK_WRITE(V10) { // reads state of virtual arming button on app
  armState = param.asInt(); // sets the variable = to that state
}

BLYNK_WRITE(V0) { // reads state of virtual chime switch on app
  chimeState = param.asInt(); // sets the variable = to that
}

BLYNK_WRITE(V7) { // reads state of virtual siren switch on app
  sirenState = param.asInt(); // sets the variable = to that
}

//-----------------------------------------------------------------------------------
// Main Loop


void loop() {
  Blynk.run();
  Serial.println(armState);
  buttonState1 = digitalRead(alarmPin1); // check state of reed switch
  //buttonState2 = digitalRead(alarmPin2); // check state of reed switch
  //buttonState3 = digitalRead(alarmPin3); // check state of reed switch
  //buttonState4 = digitalRead(alarmPin4); // check state of reed switch
  if (armState == 0) { //alarm not armed
    sirenState = 0;
    if (buttonState1 == HIGH) { //closed door #1
      Blynk.virtualWrite(V1, 0); //turns virtual LED off in app
      chimedOnce = 0;
    }
    else { //open door
      Blynk.virtualWrite(V1, 1023); //turns virtual LED on in app
      if (chimedOnce == 0) {
        if (chimeState == 1) {
          chimeBeeps();
        }
        chimedOnce = 1;
      }
    }
    /*if (buttonState2 == HIGH) { //closed door #2
      Blynk.virtualWrite(V2, 0); //turns virtual LED off in app
      chimedOnce = 0;
      }
      else { //open door
      Blynk.virtualWrite(V2, 1023); //turns virtual LED on in app
      if (chimedOnce == 0) {
        if (chimeState == 1) {
          chimeBeeps();
        }
        chimedOnce = 1;
      }
      }
      if (buttonState3 == HIGH) { //closed door #3
      Blynk.virtualWrite(V3, 0); //turns virtual LED off in app
      chimedOnce = 0;
      }
      else { //open door
      Blynk.virtualWrite(V3, 1023); //turns virtual LED on in app
      if (chimedOnce == 0) {
        if (chimeState == 1) {
          chimeBeeps();
        }
        chimedOnce = 1;
      }
      }
      if (buttonState4 == HIGH) { //closed door #4
      Blynk.virtualWrite(V4, 0); //turns virtual LED off in app
      chimedOnce = 0;
      }
      else { //open door
      Blynk.virtualWrite(V4, 1023); //turns virtual LED on in app
      if (chimedOnce == 0) {
        if (chimeState == 1) {
          chimeBeeps();
        }
        chimedOnce = 1;
      }
      }*/
  }
  else {
    if (armState == 1) {
      if (buttonState1 == HIGH) { //closed door #1
        Blynk.virtualWrite(V1, 0); //turns virtual LED off in app
        chimedOnce = 0;
      }
      else { //open door
        Blynk.virtualWrite(V1, 1023); //turns virtual LED on in app
        do {
          sirenScream(); //alarm screams
        } while (sirenState == 1);
        if (chimedOnce == 0) {
          if (chimeState == 1) {
            chimeBeeps();
          }
          chimedOnce = 1;
        }
      }
      /*if (buttonState2 == HIGH) { //closed door #2
        Blynk.virtualWrite(V2, 0); //turns virtual LED off in app
        chimedOnce = 0;
        }
        else { //open door
        Blynk.virtualWrite(V2, 1023); //turns virtual LED on in app
        if (chimedOnce == 0) {
          if (chimeState == 1) {
            chimeBeeps();
          }
          chimedOnce = 1;
        }
        }
        if (buttonState3 == HIGH) { //closed door #3
        Blynk.virtualWrite(V3, 0); //turns virtual LED off in app
        chimedOnce = 0;
        }
        else { //open door
        Blynk.virtualWrite(V3, 1023); //turns virtual LED on in app
        if (chimedOnce == 0) {
          if (chimeState == 1) {
            chimeBeeps();
          }
          chimedOnce = 1;
        }
        }
        if (buttonState4 == HIGH) { //closed door #4
        Blynk.virtualWrite(V4, 0); //turns virtual LED off in app
        chimedOnce = 0;
        }
        else { //open door
        Blynk.virtualWrite(V4, 1023); //turns virtual LED on in app
        if (chimedOnce == 0) {
          if (chimeState == 1) {
            chimeBeeps();
          }
          chimedOnce = 1;
        }
        }*/
    }
  }
}
//-----------------------------------------------------------------------------
//user defined functions

void chimeBeeps() {
  digitalWrite (chimePin, HIGH);
  delay (100);
  digitalWrite (chimePin, LOW);
  delay (100);
  digitalWrite (chimePin, HIGH);
  delay (100);
  digitalWrite (chimePin, LOW);
  delay (100);
  digitalWrite (chimePin, HIGH);
  delay (100);
  digitalWrite (chimePin, LOW);
  delay (100);
}



void sirenScream() {
  digitalWrite (chimePin, HIGH);
  delay (500);
  digitalWrite (chimePin, LOW);
  delay (100);

}
You do not have the required permissions to view the files attached to this post.
User avatar
By mrburnette
#59998 I believe that this section of ESP8266 is likely OK for your question since using the ESP8266 under Arduino is addressed here; however both Adafruit and Blynk have hardware and software forums specific to your situation. You may wish to post your inquiry to both.

I did a google on "Huzzah Feather Blynk" and a number of projects have been posted. I suggest you take a known good example and load it to your Huzzah to determine if hardware issues continue... You have a warranty on the Adafruit product which is part of the overall cost. Also, you have email tech support forum.

Blynk has their own forum to help with coding, so once you know your hardware is good (test sketch) then hopefully you can get some coding advice.

Ray