Make it Fun!! Door Alarm System with NODE32S Aiyarafun Board

Learn how to use Node32s and cloud Anto.io to protect your house or apartment from break-ins and thefts

IntermediateFull instructions provided3 hours1,942
Make it Fun!! Door Alarm System with NODE32S Aiyarafun Board

Things used in this project

Hardware components

NODE32s
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Speaker: 0.25W, 8 ohms
Speaker: 0.25W, 8 ohms
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Door Alarm system with NODE32s and DFPlayer mini mp3 module

Code

Door alarm system with NODE32s connect DFPlayer mini mp3 and Anto.io

C/C++
#include <AntoIO.h>


const char *ssid = "WIFI Name";
const char *pass = "Password WIFI";
const char *user = "your-username";
const char *token = "token";
const char *thing = "thing";

const int play1 =  16;      // Play identify yourself
const int play2 =  17;      // Play Alert
int ledPin = 2 ;    // the number of the LED pin

const int threshold =  20;      // the number of the LED pin

int ledState = LOW;             // ledState used to set the LED
unsigned long laststamp;
unsigned long alert_timestamp,alert_laststamp;
boolean alert_tick;

AntoIO anto(user, token, thing);
uint8_t count = 0; //count time
uint8_t n = 0;  //state for input Anto.io
uint8_t first = 0;  //initial variable

String text1= "Identify yourself";
String text2= "Your room is safe";
String text3= "Someone hack your room";
String text4= "Password is incorrect";


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Serial.print("\nTrying to connect ");
  Serial.print(ssid);
  Serial.println("...");
  while (!anto.wifi.begin(ssid, pass));
  Serial.println("\nConnected, trying to connect to broker...");
  while (!anto.mqtt.connect(user, token, true));
  Serial.println("\nConnected");
  
  
  
  pinMode(ledPin, OUTPUT);
  //mp3_set_volume (50);
  Serial.begin(115200);
  touchAttachInterrupt(T0 , play , threshold );
  pinMode(play1, OUTPUT);
  digitalWrite(play1,HIGH);
  pinMode(play2, OUTPUT);
  digitalWrite(play2,HIGH);
}

void loop() {  
  anto.mqtt.loop();
  delay(10);
  //Serial.println( touchRead(T0) );
  if (alert_tick == HIGH) {
   
    // send data
    if(first==0){
       Serial.print("n condition1= ");
       Serial.println(n);  
       // send signal to mp3
        digitalWrite(play1,LOW);
        delay(100);
        digitalWrite(play1,HIGH);    
        alert_tick = LOW;
        alert_timestamp = millis();
        Serial.println("Identify yourself");
  
        anto.mqtt.sub("password");
        first=1;
              }
              
    else  if(n==1){
          count++; //default was sent and wait for change  vaule
          Serial.print("count= ");
          Serial.println(count);
          
             if(count==10){
                Serial.println("default value not change"); 
                digitalWrite(ledPin,HIGH); 
                anto.mqtt.pub("LEDdoor","1");
                anto.mqtt.pub("Message",text3); //Someone hack your room
                digitalWrite(play2,LOW);
                delay(100);
                digitalWrite(play2,HIGH);    
                alert_tick = LOW;
                alert_timestamp = millis();
                Serial.println("Some one hack your room");
                delay(10000);
                }
              }
          }
      


  if ( (millis()-alert_timestamp) > 10.0*1000) {
    // send turn off
    anto.mqtt.pub("Message",text2);
    delay(1000);
    digitalWrite(ledPin,LOW); 
    anto.mqtt.pub("LEDdoor","0");
//    Serial.println("safe");
    
  }
  
  
}

void play () {
  Serial.println("   click!") ;

  unsigned long timestamp = millis();
  if ( (timestamp-laststamp) > 5000) {
   laststamp = timestamp;
   alert_tick = HIGH;   
   count=0;
  }

}


void messageReceived(String topic, String payload, char * bytes, unsigned int length) {
  Serial.print("incoming: ");
  Serial.print(topic);
  Serial.print(" - ");
  Serial.print(payload);
  Serial.println();

  if (payload.toInt() == 0) {
    Serial.println("waiting for change value");
    n=1;
    Serial.print("n payload1= ");
    Serial.println(n);
    anto.mqtt.pub("Message",text1); //Wait for identify yourself and change default value
    delay(100);
    
   }

   else if (payload.toInt() == 1)
   {
      Serial.println("password is correct");
      n=2;
      Serial.print("n payload2= ");
      Serial.println(n);
      anto.mqtt.pub("Message",text2); //your room is safe Password is incorrect
      delay(100);
  
    }
    else{
      Serial.println("password is incorrect"); // if it not 0,1 but type password wrong 
      anto.mqtt.pub("Message",text4);
    }
    
   }

Credits

Thanasornsawan Ploy Varathanamongkolchai

Thanasornsawan Ploy Varathanamongkolchai

0 projects • 1 follower
I share my knowledge on Youtube channel "wisdomgood" and I love to invent as my hobby.I'm girl maker in Thailand.

Comments