Contact sales

How to build a parking management system with the Particle M-SoM

This tutorial walks you through creating a parking management system with the Particle M-SoM.

Zalmotek article author avatarZalmotekSeptember 06, 2024
How to build a parking management system with the Particle M-SoM

The problem

Few things in life are more annoying than trying and failing to find a parking spot, especially in a parking garage. Nobody wants to spend their time circling the garage waiting for someone to leave. It’s dreadfully boring and bad for the environment to boot! Parking management is essential in Smart Buildings for enhancing efficiency, convenience, and sustainability. However, most parking management systems are clunky, outdated and expensive. 

The solution

In this project, we will build our own smart parking systems using sensors and IoT technology to reduce the time it takes to find a parking spot. Monitoring the occupancy rating and the related patterns, we will optimize space usage and improve the overall experience for employees or tenants in using the available parking space.

Bill of materials

  • M524 SoM and M.2 SoM Evaluation Board
  • 12V Optical Distance Sensor
  • 12V LED Beacon
  • SX1509 16 Output I/O Expander
  • 12V Power Supply
  • Optocouplers
  • Colored 24 AWG wire – Red, Black, Green, Blue, White
  • Enclosure for the M-SoM
  • Various mechanical components to mount the enclosure in the designated place

Required skills and tools

Skills

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

Tools

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

 

Developing a parking management system based on the M-SoM

System design

Our parking system uses the M524 SoM and the M.2 SoM Evaluation Board to create a smart, efficient solution. Here’s how it works:

We place sensors in each parking spot to detect when a car is parked there. The M524 SoM collects this data from all the sensors. It then sends this information to the Particle cloud, which is a secure online platform designed for IoT devices.

The Particle cloud processes and stores this data, making it easily accessible from anywhere. This means parking lot managers can see real-time occupancy data on their phones or computers.

Each parking spot also has an LED beacon. When a car parks in a spot, the M524 SoM sends a signal through the Particle cloud to turn on that spot’s LED beacon.

 

Using the Particle cloud offers several advantages. It allows for remote monitoring and control of the entire system. We can easily update the software on all devices at once. It also enables integration with other services, like mobile apps that could guide drivers to open spots.

 

This system makes finding empty parking spots easier for drivers and helps parking lot managers use their space more effectively. It’s a great example of how the Particle ecosystem can solve real-world problems.

 

Hardware Selection

The M524 SoM + M.2 SoM evaluation board

The Particle M-SoM is a great starting point for developing IoT (Internet of Things) prototypes, especially when you’re building systems that need reliable connectivity. One of its standout features is its flexibility—it supports both cellular and Wi-Fi connections. Having multiple connectivity options ensures that the system stays functional even if one method fails. In critical applications, this level of redundancy can be crucial, offering peace of mind that the system will stay online no matter what.

It’s important to remember that there are different versions of the M-SoM for different parts of the world. If you’re in Europe, you should use the M524. If you’re in the USA, you should use the M404. This is because different countries use different cell phone networks, and you need to make sure your device will work with the right one.

Optical distance sensor

An optical distance sensor works by sending out an invisible infrared beam from an emitter. When this beam hits an object, like a car, it bounces back to the sensor’s receiver (called a photodiode). The angle at which the beam returns changes based on how far away the object is, and the sensor processes this change in angle into a voltage signal. That signal is then used to calculate the distance to the object.

 

The accuracy and range of these sensors can vary depending on the model and how they’re designed. Different sensors are made for different purposes. In this case, we’ve chosen a sensor specifically suited for detecting cars. It can measure distances up to 6 meters, which makes it a good fit for monitoring parking spots. Additionally, this sensor is built to withstand outdoor conditions, thanks to its durable, weather-resistant enclosure. This ensures it can keep working reliably even in harsh environments, making it a practical choice for parking management systems.

 

Light indicator

As the name implies, the light indicator turns on to signal when a parking spot is available and switches off when the spot is taken. This makes it easy for drivers to quickly spot open spaces. Additionally, the light indicator can also serve another purpose: helping drivers park more accurately. By using it to gauge how close a car is to a wall or another obstacle, it can signal when you’ve reached the optimal distance for parking. This adds an extra layer of convenience, especially in tight or crowded spaces where precise parking is important.

16 Output I/O Expander Breakout – SX1509

The 16 Output I/O Expander Breakout (SX1509) is a key component in making our parking system scalable. While the evaluation board already provides a good number of GPIO (General Purpose Input/Output) pins, it’s not enough when you’re dealing with a large parking lot that could have hundreds of spaces. To address this, we’ve chosen to use an I/O expander like the SX1509.

The I/O expander allows us to significantly increase the number of devices (like sensors and lights) that can be controlled from the same system without needing to add more complex wiring or extra hardware. This makes it possible to manage larger parking areas while keeping the system’s design simple and efficient. By using this approach, we ensure that the system can grow and adapt as needed without losing performance, making it suitable for everything from small parking lots to large-scale implementations.

Optocoupler

The optocoupler is a handy solution for bridging the gap between the different voltage levels used by the M524 module and the optical distance sensor. The M524 operates with 3.3V logic, but the optical distance sensor outputs a higher voltage. While this might seem like an issue, it’s manageable because the sensor’s output is just a simple on/off (digital high or low) signal.

 

The optocoupler resolves this by isolating the two circuits. It works with two main components: an LED and a photosensitive device, both housed together in a single package. When the LED inside the optocoupler lights up, it sends an infrared signal that is detected by the photosensitive part. This setup allows the signal to pass between the high-voltage and low-voltage circuits without any direct electrical connection between them. Essentially, it enables safe communication between parts of the system operating at different voltages, ensuring the system works smoothly without risking damage to sensitive components.

Hardware Setup

Wiring

When wiring the system, it’s important to take your time and ensure everything is connected properly. Use color-coded wires to keep track of where each connection goes, and label both ends of the wires for clarity. Before powering anything on, double-check all connections with a multimeter to avoid mistakes.

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. 

The diagram uses boxes 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_board” , “optocoupler_1”, and “12v_supply”, while upper case is used for naming cables like “OPTOCOUPLER_OUTPUT_1” and “POWER_CABLE”. 

The 12V supply(12v_supply) is connected to a power plug(power_plug) through a 3 wired cable(POWER_CABLE). From the 12V supply, there are two wires coming out, a red one and a black one, both of them splitting in 3. A red and black pair used to power the optical distance sensor, a pair used to power the M-SoM through a wire ending in a barrel jack, the remaining red wire is connected to the third pin of the second optocoupler and the remaining black wire is connected to the GND pin of the LED beacon. 

The SX1509 is connected through the I2C Grove connector to the M-SoM evaluation board.

Due to the fact that they are using 12V logic, both the optical distance sensor and the LED beacon are interfaced with the SX1509 through optocouplers. To make it easier to understand, consider optocoupler_1 an “input” optocoupler, and optocoupler_2 an “output” optocoupler. The first optocoupler receives a signal from the D_OUT pin on the distance sensor on it’s first pin and outputs 3.3V(provided on its 3rd pin) to the D0 pin of the SX1509, while the second optocoupler waits for a 3V3 signal on it’s 1st pin from the D1 pin of the SX1509 and outputs 12V(provided on its 4th pin from the power supply) from its 3rd pin to the LED beacon. 

Deploying the hardware

This system can be adapted for two main use cases:

 

Large Parking Areas (e.g., commercial garages):

In a large parking area, such as a multi-level garage or commercial lot, the system can use green lights to indicate available spots. These lights will help drivers quickly find an empty parking space without having to circle around. This can significantly reduce time spent searching for a spot and improve the flow of traffic in busy parking areas.

 

Smaller or Residential Parking Areas:

In a smaller parking lot, like in a residential building where parking spots are already assigned, the system can serve a different purpose. Instead of signaling availability, the red light could be used to help drivers park more precisely. The light would turn on as the car approaches the wall or a designated boundary, helping the driver gauge when they’ve reached an optimal parking position. This is especially helpful in tighter parking spaces where precision matters.

 

In both of these cases, the system doesn’t just operate locally. It also sends real-time data about the overall parking lot’s occupancy to the cloud. This allows for centralized monitoring and management of parking spaces, offering valuable insights into space usage and helping improve operational efficiency. Whether it’s for a large commercial lot or a smaller residential setup, this system can adapt to meet different needs while keeping everything connected to the cloud for tracking and analysis.

 

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.

There are two methods to flash applications on the M-SoM. The easiest method that requires almost no setup is to use their excellent Web IDE where you can find official and community developed libraries, as detailed in the following article. However, we’ve opted for the second option, the Particle Workbench extension for Visual Studio Code. This great article goes in depth explaining all its features and how to use them.

Automation rules

One of the biggest advantages of the M-SoM is its array of external antennas coupled with its SIM card. This together with the seamless integration of cloud functionalities enables us to send update messages to the Events tab of the Particle Console. The following sample sets up the I/O extender to work with an array of optical distance sensors and LEDs. The M-SoM constantly queries the sensors for updates, if such an update is detected the state of the corresponding LED is changed indicating that the parking space is available or occupied. The board also sends a message to the cloud indicating the parking space number and its current state change. 

const byte SX1509_ADDRESS = 0x3E; // SX1509 I2C address
SX1509 expander;
int space_nr[PARKING_SPOTS] = {0}, state;

void setup() {
  Serial.begin(115200);
  if (expander.begin(SX1509_ADDRESS) == false) {
    Serial.println("Failed to communicate. Check wiring and address of SX1509.");
    while (1);
  }
  for (int pin = 0; pin < 2 * PARKING_SPOTS; pin += 2) {
    expander.pinMode(pin, INPUT); //Optical sensors
    expander.pinMode(pin + 1, OUTPUT); //Light indicators
  }
}

void loop() {
  for (int pin = 0; pin < 2 * PARKING_SPOTS; pin += 2) {
    state = expander.digitalRead(pin); //Read Optical sensor
    if (state != space_nr[pin]) {
      if (state == HIGH) {
      Particle.publish("busy", String::format("space nr. %d", space_nr));
      expander.digitalWrite(pin + 1, LOW); //Turn off light
  }
  else {
      Particle.publish("free", String::format("space nr. %d", space_nr));
      expander.digitalWrite(pin + 1, HIGH); //Turn on light
  }
    }
    space_nr[pin] = expander.digitalRead(pin);
  }
}

Let’s dive into how this code works.

1. Define the SX1509 I/O Expander

const byte SX1509_ADDRESS = 0x3E; // SX1509 I2C address

SX1509 expander;

int space_nr[PARKING_SPOTS] = {0}, state;

 

  • SX1509_ADDRESS: This is the address used to communicate with the SX1509 I/O expander over a protocol called I2C. It’s like giving the expander a phone number so the M-SoM can talk to it.
  • space_nr: An array to keep track of each parking space’s status (whether it’s occupied or not).
  • state: This variable will store the current reading from the sensors for each parking spot.

2. Setup Function (Runs Once at Startup)

void setup() {

  Serial.begin(115200);

  if (expander.begin(SX1509_ADDRESS) == false) {

    Serial.println("Failed to communicate. Check wiring and address of SX1509.");

    while (1);

  }

  for (int pin = 0; pin < 2 * PARKING_SPOTS; pin += 2) {

    expander.pinMode(pin, INPUT); //Optical sensors

    expander.pinMode(pin + 1, OUTPUT); //Light indicators

  }

}

 

  • Serial.begin(115200): This initializes the serial communication, which is useful for debugging by allowing messages to be sent to your computer.
  • expander.begin(SX1509_ADDRESS): This starts communication with the SX1509 I/O expander. If it fails to connect, the program will print an error message and stop.
  • for loop: The loop sets up each parking spot. For each spot:
    • One pin is configured as an input to read data from the optical sensor.
    • The next pin is set as an output to control the LED light that shows whether the spot is available or not.

3. Loop Function (Runs Continuously)

void loop() {

  for (int pin = 0; pin < 2 * PARKING_SPOTS; pin += 2) {

    state = expander.digitalRead(pin); //Read Optical sensor

    if (state != space_nr[pin]) {

      if (state == HIGH) {

       Particle.publish("busy", String::format("space nr. %d", space_nr));

       expander.digitalWrite(pin + 1, LOW); //Turn off light

   }

   else {

       Particle.publish("free", String::format("space nr. %d", space_nr));

       expander.digitalWrite(pin + 1, HIGH); //Turn on light

   }

    }

    space_nr[pin] = expander.digitalRead(pin);

  }

}

 

  • for loop: This loop continuously checks each parking space. For each spot, it does the following:
    • expander.digitalRead(pin): Reads the status of the optical sensor for that parking space. If the sensor detects a car, the state is HIGH (occupied); otherwise, it is LOW (empty).
    • if (state != space_nr[pin]): This checks if the sensor’s reading has changed since the last time it was checked (for example, if a car has parked or left).
      • If the sensor detects a car (state == HIGH):
        • Particle.publish(“busy”): Sends a message to the cloud saying the spot is occupied.
        • expander.digitalWrite(pin + 1, LOW): Turns off the LED light, signaling that the spot is taken.
      • If the sensor detects the spot is empty (state == LOW):
        • Particle.publish(“free”): Sends a message to the cloud saying the spot is free.
        • expander.digitalWrite(pin + 1, HIGH): Turns on the LED light, indicating the spot is available.
    • space_nr[pin] = expander.digitalRead(pin): Updates the parking space’s current status in the array so the system knows its new state.

 

 

Cloud integration

The cloud integration facilitates real-time updates by transmitting events indicating the status of parking spots. These updates can also be forwarded to a time series database using other means of communication such as MQTT. This setup allows for continuous monitoring and historical analysis of parking spot availability, enabling advanced analytics, predictive maintenance, and optimized parking management strategies. The seamless flow of data ensures efficient and accurate parking solutions, enhancing user experience and operational efficiency.

Conclusion

Effective parking management plays a key role in improving the overall efficiency, convenience, and sustainability of Smart Buildings. By incorporating sensors and IoT technology, smart parking systems make it easier to optimize the use of parking spaces, provide real-time updates on availability, and enhance security. These systems not only improve the parking experience by reducing the time spent searching for a spot but also contribute to environmental sustainability by minimizing unnecessary driving, which reduces emissions.

The benefits extend beyond just convenience. Smart parking systems streamline operations, reduce costs, and allow for better resource management, all while delivering a smoother, more user-friendly experience. This makes smart parking a crucial component in the design and functionality of modern Smart Buildings, where innovation, efficiency, and sustainability are increasingly important.

 

Comments are not currently available for this post.