What if your house was on fire and you waited for the fire truck to arrive, only to be informed that it was stuck in traffic? Traffic congestion in major cities is a bane for commuters, but as a daily affair we have all gotten used to it.

When congestion meets an emergency situation, can lead to loss of lives and property. That is where an intelligent transportation system (ITS) kicks in. A citywide ITS based infrastructure keeps tab of city traffic and controls the traffic control signals to manage traffic pile up. In this post, we will witness how an ITS can be automated to facilitate seamless movement of emergency vehicles, like ambulances and fire trucks.

Intelligent Transportation Systems: Bridging the Gap with IoT

Internet of Things has been around for a few years now, and its novelty has already given way to practicality across various industries. Technologies such as GSM and more recently LPWAN have enabled us to connect device which are either on the move or accessible only remotely. And with GPS, it is quite easy to track vehicles as well. For managing emergency vehicles on the move, we can employ a set of these technologies to make a smart and intelligent transportation system.



That leads to our use case today. We want to build an ITS that can sense an approaching emergency vehicle at a traffic signal, and then direct the traffic signal to turn green. Once the vehicle crosses the intersection, the ITS redirects the traffic signal to roll back to its normal operation.

We are going to build a model ITS system which is capable of sensing emergency vehicles and controlling the approaching traffic lights. As this system will comprise both hardware and software components, let’s dive in to get a closer look at each of system components.

Hardware Components of The System

In a real world application, the best way to track the location and direction of a moving vehicle is through a GPS device. We also have another device that can be attached to the traffic signal equipment to control the operation on the traffic lights. Both these devices need to be connected to the Internet.

However, the Raspberry Pi 3 can be used for both purposes in one device.

Software for a Demo ITS

The GPS device component of the emergency vehicle is simulated in software for today’s demo. It will replicate the movement of the vehicle along a predefined route. It sends the GPS location along that route and gives an impression of the vehicle in motion by sending GPS data periodically.

Assuming that we have the traffic signals and emergency vehicles hooked up to the internet, how do we connect them in such a way that the traffic signal is aware of the approaching emergency vehicles location?

That’s where Twilio Sync comes in and plays the role of an orchestrator.

Twilio Sync is a cloud based service that make it super easy to share information between multiple devices connected to the internet. It is a serverless way of sharing your application state between multiple connected components. Think of it as a memoryless way of storing and syncing variables and state information between two application components connected to the internet, akin to the serverless way of deploying applications on cloud.

To use Sync, first register for a Twilio account and then request an invite to Twilio Sync early access.

Using Sync for an ITS Backend

For our model ITS, we are going to use Twilio Sync to build our ITS backend. Both the emergency vehicle and the traffic signal will be synced up via some form of connectivity, as you can see in the diagram below.



To provide some amount of resilience to the system (considering the fact that it is used for managing emergency vehicles!) we will use LoRa radio-based point to point connectivity.

Building the Working Setup for ITS

Let’s look at how we can assemble the hardware and software pieces of this system together to build a functional setup.

Before we process, here is a quick recap on our model setup. We are going to use the Raspberry Pi3 as the traffic signal and a laptop/computer for simulating the GPS device of the emergency vehicle.

Hardware

As we are using Raspberry Pi 3 to represent the traffic signal hardware, we have connected three LEDs to emulate the red, amber and green signal color of a typical traffic signal. These are interfaced via GPIO with the Raspberry Pi 3. Since we are including communications redundancy, we have also added the LoRa interface as a USB serial device.

Here is the final schematic representation of the Raspberry Pi 3 with the LEDs.

The LoRa module used here is the Microchip RN 2483 and its pinout and the schematic is as follows.



We will use this specific design. You can also purchase the LoRa evaluation kit from Microchip site but their external pinout will be different.

Note: LoRa operates in the ISM radio band which varies from country to country. The RN 2483 module used in this demo is meant for Europe and Asia. If you are in North America then you must check out RN 2903. All the Microchip’s LoRa products are listed here.

We need to connect the LoRa breakout module to a serial to usb converter so that it can be attached to the USB port of the Raspberry Pi as well as the laptop.

Onboard Software

The entire source code of the software components, written in Python, is available through this GitHub repository.

There are three independent pieces of software that are required to make this system work.

Traffic Signal Software

The traffic signal software runs on the traffic signal for toggling the LEDs and also for setting up the passage for emergency vehicle.