Little-project

In last years of STI2D we have avons make a littre project befort the project of 70h for the BAC. By group of 2 we were to create one system thanks to Arduino card.


An alarm

We were to create an alarm with specification below.

Use case diagram

Use case diagram

I worked on the detection of open doors. I have use a ultra sound sensor then hall effect sensor.
My colleague worked on sending email. He has use the library Gsender.h

Standards

A2P
Low security.
Adapted to individuals, for scare the amateur burglars.
A2P 2
Medium security.
Adapted to individuals exposed or little store.
A2P 3
High security.
Adapted to individuals possessing a great values object or medium store.

Sensor choice

We have choice into two sensor for the detection of open doors. The ultra sound sensor or the hall effect sensor.

The ultra sound sensor

The ultra sound sensor allows to measure the distance.
If the sensor is beside the door, when the door is close, the sensor take the distence between him and the wall, when the door is open, he take the distance between him ans the door which give a lower ditance.

Shema

We use the gap of distance for detect the opening of door.

This solution is not perfect. If a person go forward the sensor the system detect a oppening door.

The hall effect sensor

The hall effect sensor is a sensor of magnétique fields.
Putting the sensor in the jamb of door ans a magnet on the door, we can detect a oppening and closing of the door even if person go forward.
Moreover the hall effect sensor works in 3.3v in contrary of the ultra sound sensor. Given that the esp8266 works in 3.3v this simplifies the use of the sensor.


Setting up

To make the alarm we need of :
  • One micro controler witch wifi chip
  • One hall effect sensor
  • One switch
  • One pushbutton
  • One resistance 200Ω
  • Cables

oppening doors detection

To use the sensor we read his input.
the sensor works on digital.


// ------======== oppening doors detection ========------
  Serial.print("state os sensor :  ");
  Serial.println(digitalRead(Capteur));

  if (digitalRead(Capteur) == 1){
  /* flaching led to show if the door is oppening */
  digitalWrite(LED, LOW);
  delay(100);
  digitalWrite(LED, HIGH);
  delay(100);
  digitalWrite(LED, LOW);
  delay(100);
  digitalWrite(LED, HIGH);
          

Complete code

For send mail, we use the library Gsender.h


#include < ESP8266WiFi.h >
#include "Gsender.h"


// ------======== Pin composant ========------


/* switch on off and stop button */

const int BP_MA = 5;          //Switch on pin D0
const int BP_HERE = 14;       //Button on pin D5
int CH = 0;                   //State of button on off
int ETAT_BP_HERE;             //State of pushbutton
int CODE_BP_HERE;             //compteur bouton poussoir
int temps;                    //timer before sending mail

/* LED */
const int LED = 0;            //LED on pin D3

/* Buzzeur */
int MusiquePin = 2;           //Buzzeur on pin D4

/* capteur a effet hall */
int Capteur = 16 ;


// ------======== Wi-Fi Settings ========------

const char* ssid = "SSID";      // WI-FI name
char* password = "PASSWORD";       // Password



// ==============================================================================================================
void setup() {

  /* Initialise le port série */
  Serial.begin(115200);

  // ------======== Initalise le wifi ========-----

   WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
  }
  Serial.println("connecté au wifi");

  // -------======== Initialise la LED ========------

  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);

  Serial.println("LED initialisé");

  // -------======== Initialise des boutons ========------
  pinMode(BP_MA, OUTPUT);
  pinMode(BP_HERE, OUTPUT);

  Serial.println("boutons initialisé");
  // ------======== Initialise les broches ========------

  pinMode(Capteur, INPUT);

  Serial.println("capteur initialisé");


  // ------======== clignottement led pour monter que le set up est fini ========------

        digitalWrite(LED, LOW);
        delay(500);
        digitalWrite(LED, HIGH);
        delay(500);
        digitalWrite(LED, LOW);
        delay(500);
        digitalWrite(LED, HIGH);

}

// ==============================================================================================================


void loop() {

  if(digitalRead (BP_MA) == 1){                            //Button on/off in on
    if(CH == 0){
      Serial.println("interupteur sur on");
      Serial.println("on attend 30s");                     //Wait 30 secon to close the door
      delay(30000);
      CH = 1;
    }
    if(digitalRead (BP_MA) == 1){                          //Button on/off in on
    digitalWrite(LED, HIGH);                //Led in on to  La led s'allume pour indiqué que le système est sous tention

  // ------======== Détection Porte ========------
       Serial.print("état du capteur :  ");
       Serial.println(digitalRead(Capteur));

       if (digitalRead(Capteur) == 1){
    /* clignottement led pour monter que la porte c'est ouverte */
        digitalWrite(LED, LOW);
        delay(100);
        digitalWrite(LED, HIGH);
        delay(100);
        digitalWrite(LED, LOW);
        delay(100);
        digitalWrite(LED, HIGH);



    // ------======== envoie mail ========-----

/* voleur ou propriétaire ? */


    /* Timer */
    temps = 0;
    ETAT_BP_HERE = 0;
    while( temps <= 20 ){
      if(digitalRead(BP_HERE) == 1){
        ETAT_BP_HERE = 1;
        Serial.println("ah? c'est vous?");

        /* signial de detection de bouton */
          digitalWrite(LED, LOW);
          delay(200);
          digitalWrite(LED, HIGH);
          delay(200);
          digitalWrite(LED, LOW);
          delay(200);
          digitalWrite(LED, HIGH);

          temps = 30;
      }
      delay(1000);
      temps++;  //ajoute +1 à "temps", tant que "temps" est inférieur à 30
      Serial.println("on attend");
    }

    Serial.println("temps de battement depassé");


/* envoie du mail */
    if(ETAT_BP_HERE == 0){
     /* envoie du mail */
        Gsender *gsender = Gsender::Instance();     // Getting pointer to class instance
    String subject = "Alerte intrusion";
    if(gsender->Subject(subject)->Send("tatoup779@gmail.com", "Une personne est rentrer chez vous !")) {
        Serial.println("Message send.");
    }
    /* si il na pas reussi a envoyé le mail */
    else {
        Serial.print("Error sending message: ");
        Serial.println(gsender->getError());
    }


      }      // fin si ce n'es pas le proprietaire
    }        // fin si la porte est ouverte
  }          // fin si le bouton marche arret est sur on après les 30s
}            // fin si le boutons marche arret est sur on

else{                                         // si l'interupteur n'est pas sur on
  if(CH == 1){
    CH = 0;
  }
  Serial.println("interupteur sur off");
  digitalWrite(LED, LOW);                     // on eteins la led

}         // fin si interupteur sur off


}         // fin loop