Contact sales

How to manage building security and access control with the Particle M-SoM

Zalmotek article author avatarZalmotekAugust 23, 2024
How to manage building security and access control with the Particle M-SoM

The Problem

Working in a busy city, we want it to be easy for employees to come into our office, but we don’t want any old stranger from the street to be able to walk in. The usual door security systems work well, but they cost a lot and don’t let us change much about how they work. Also, these systems usually need WiFi to work. So if the WiFi stops working, people can’t get into the office. We’re looking for a better way to control who can come into our office.

The Solution

We decided to build our own access control system using the Particle M-SoM. This board can connect to both WiFi and cellular networks, solving the problems we had with traditional systems. It gives us more flexibility, reliability, and cost-effectiveness. We can customize it to our needs, and it won’t lock people out if the WiFi fails. This approach allows us to create a smarter, more adaptable solution for our office security.

Bill of Materials

  • M524 SoM and M.2 SoM Evaluation Board
  • Gravity: UART & I2C NFC Module
  • 12V PIR sensor
  • 12V Electronic Lock with 3V3 logic
  • Optocoupler 
  • 12V power supply
  • Colored 24 AWG wire – Red, Black, Green, Blue, White
  • Enclosure for the M-SoM

Skills and Tools Needed

Skills

  • Arduino Programming
  • Crimping, Soldering and Connector assembly
  • Basic mechanical assembly skills

Tools

  • PC
  • Crimping tool
  • Soldering iron
  • Multimeter
  • Set of screwdrivers

Where does IoT come into play?

Smart devices are making it easier and cheaper to manage buildings. When people enter or leave, the security system can automatically adjust the lights. It turns off power in areas that aren’t being used and changes settings to fit different people’s needs. It also keeps track of how spaces are used.

This technology keeps the building safe while using less energy. It’s like having a clever helper that knows exactly when to turn things on and off. This saves money and energy without making the building less comfortable or safe.
The system also collects information that helps make smart money decisions. For example, it might show that some spaces aren’t being used much, so the company could decide to give them up and save money.

Developing a security and access control system based on the M-SoM

System design

To facilitate and secure building access, we propose a system leveraging the M524 SoM’s connectivity and a combination of electromagnetic locks and NFC readers. This system uses motion sensors to detect people in front of the door. Additionally, NFC readers at entry points authenticate users via their NFC tags, granting or denying access based on permissions stored in the cloud.

Hardware Selection

The M524 SoM + M.2 SoM Evaluation Board

The Particle M-SoM is an excellent choice for creating Proof of Concepts (PoCs) for IoT devices due to its versatile connectivity options, including cellular and Wi-Fi. While having multiple connectivity options might seem like an overkill, it sure does feel great to have a fallback ensuring that the monitoring system does not go down.

While the Evaluation kit is much larger than the M-SoM in itself, keep in mind that it exposes every functionality of the module. Once a technology readiness level is reached and the device features are locked down, a much smaller, more efficient device can be built around the M-SoM exposing only the needed functionalities. 

Also, when picking an M-SoM, make sure to get the one designed to work in your geographic region (M524 for Europe or M404 for USA).

NFC Reader & NFC Cards

The first electronic component that greets you when trying to enter a room is the NFC reader. This component uses short-range wireless signals to communicate with NFC tags. When an NFC tag is near, the reader powers it and exchanges data. 

Systems based on NFC cards became the industry standard for access control in Smart Buildings due to their innate security features, ease of use, and the very simple management of access permissions. 

PIR sensor

To detect human presence in front of the door we have opted for a PIR sensor. A PIR (Passive Infrared) sensor detects motion by sensing infrared radiation changes. It has two IR-sensitive slots that measure the ambient IR levels. When a warm object, like a person, moves across its field of view, the IR levels change between the slots and this variation is converted into an electrical signal, which the sensor processes to detect motion. Additionally, they are very robust and easy to integrate in IoT systems as they have a single digital output. 

The M524 uses 3v3 logic, the PIR sensor uses 12V logic. Issue? Not when you know about the existence of optocouplers. 

This electronic component consists of two main components: an LED that emits infrared light and a photosensitive device that detects this light, enabling the transfer of signals without direct electrical connection, both of them stuck together inside a single isolated package. This enables the transfer of signals between high voltage and low voltage circuits without direct electrical connection. 

Electromagnetic Lock

For this application, we have chosen a fail-safe electronic lock that stays in the locked position in case of a power outage in the building. This model was selected because it operates at a 3.3V logic level and is powered by a 12V supply. It features a door sensor that allows us to assess if the door is in front of the lock and a lock sensor that tells us if the bolt is retracted or in neutral position.

Hardware Setup

Wiring

While the diagram might look complicated, just make sure to follow each step carefully and double-check your connections. Ensure all components are correctly placed, and use the color-coded wires to keep track of connections. Label wires on both ends, and measure everything with a multimeter before powering the system.

 

The diagram has been created using WireViz, a tool used in professional environments to easily document cables, wiring harnesses and connector pinouts and present them in a human readable format.

 

In the diagram, boxes are used to describe electronic components like connectors, evaluation boards, sensors and cables, while using colored lines to describe the wires used to connect them. Electronic components are named using lower case letters, for example: ”msom_eval_boards” , “nfc_reader”, and “pir_sensor”, while upper case is used for naming cables like “PIR_SENSOR_POWER”, “POWER_CABLE”, ”ELECTRONIC_LOCK” . 

The 12V supply (12v_supply) is connected to a power plug (power_plug) via a 3-wire cable (POWER_CABLE). From the 12V supply, two wires come out: one red and one black. These wires each split into three additional wires. One pair of red and black wires runs through the PIR_SENSOR_POWER cable to power the PIR sensor, another pair runs through the ELECTRONIC_LOCK cable to power the electronic lock, and the final pair goes to a cable ending in a barrel jack to power the M-SoM board.

The NFC reader is connected via a grove cable to the I2C grove connector. The electronic lock is connected through the ELECTRONIC_LOCK cable to GPIO pins 1, 2 and 3. The first pin of the optocoupler is connected to the Normally Open pin of the PIR sensor, the second pin is connected to the COM pin of the evaluation board, the third pin is connected to GPIO 4 of the M-SoM, and the fourth pin is connected to the 3.3V pin of the M-SoM.

Deploying the hardware

Software Setup

Initial Configuration

Go to https://setup.particle.io/ and follow the guide to set up and claim your device. Now that the device shows up on the My Devices tab inside the Particle Console we can focus on how to program it.

The Particle Workbench extension for Visual Studio Code is the best way to program Particle devices This great article goes in depth explaining all its features and how to use them.

Automation rules

The M-SoM has some great features that make it really useful. It has several antennas on the outside and a SIM card. These work together with cloud features to let us send update messages to the Events tab in the Particle Console. This means we can keep track of what’s happening easily.
We’ve created a sample program that shows how useful this is. It does three main things:

  1. It checks if people are around using motion sensors.
  2. It handles security by checking NFC tags (like the ones in some keycards).
  3. It controls a smart lock.

While it’s doing all this, it sends alerts to the cloud. This way, you can always know what’s going on with your system, even if you’re not there.

void loop() {

  // Check the PIR sensor
  currPirStatus = digitalRead(PIR_PIN);
  if (currPirStatus != pirStatus) {
    if (currPirStatus == HIGH) {
  Particle.publish("Human presence detected");
    }
    pirStatus = currPirStatus;
  }



  // Reads data from different types of NFC cards
  if (nfc.scan()) {
    memset(dataRead, 0, DATA_LEN);

    NFCcard = nfc.getInformation();
    if (NFCcard.AQTA[1] == 0x44 && memcmp(NFCcard.cardType, "Ultralight", 10) != 0) {
      NTAGRead(dataRead);
    }
    else if ((NFCcard.AQTA[1] == 0x02 || NFCcard.AQTA[1] == 0x04)) {
  MifareClassicRead(dataRead);
    }
    else if (NFCcard.AQTA[1] == 0x44 && memcmp(NFCcard.cardType, "Ultralight", 10) == 0) {
      UltralightRead(dataRead);
    }



    // Checks the key read from the card and opens the door
    if (CheckPassword(dataRead)) {
  digitalWrite(CMD_PIN, HIGH);
  doorEventTime = Time.now();
  doorStatus = UNLOCKED_CLOSED;
    }
    else {
  Particle.publish("Entry attempt");
    }
  }



  // Door logic
  if (digitalRead(DOOR_PIN) == HIGH && doorStatus == WAITING_CLOSE) {
    doorStatus = UNLOCKED_OPEN;
    doorEventTime = Time.now();
  }
  else if (digitalRead(DOOR_PIN) == LOW && doorStatus == WAITING_CLOSE && Time.now() - doorEventTime > lockWait) {
    digitalWrite(CMD_PIN, LOW);
    doorStatus = LOCKED;
  }

  if (digitalRead(DOOR_PIN) == HIGH && doorStatus != LOCKED && doorStatus != WAITING_CLOSE) {
    doorStatus = UNLOCKED_OPEN;
  }
  else if (digitalRead(DOOR_PIN) == LOW && doorStatus != LOCKED && doorStatus != WAITING_CLOSE) {
    doorStatus = UNLOCKED_CLOSED;
  }

  if (Time.now() - doorEventTime > doorDebounce && doorStatus == UNLOCKED_CLOSED) {
    doorStatus = WAITING_CLOSE;

    doorEventTime = Time.now();
  }
}

 

Cloud integration

The cloud integration facilitates real-time updates by transmitting events indicating the status of the rooms. This setup allows for continuous monitoring, enhancing security by sending alerts in case of failed entry attempts or human presence inside the room.

Conclusion

As our world becomes more connected, smart devices are playing a bigger role in how we manage buildings. The M524 SoM is a new tool that helps make buildings smarter. It can make buildings run more smoothly, keep them safer, and help them change to meet what building owners and people using the buildings need. This is becoming more and more important as we try to make our buildings work better for everyone.

 

Comments are not currently available for this post.