Smart city and safety first

Idea inspiration: when sitting at a traffic light and there are no other cars on the road, I can’t help but get impatient and wonder why, in a world of hyper-connectivity and sensorization, is this something that still happens? The technology exists to make cities smart, but getting all of this technology to work together cohesively is another story.

Why nio


Typically with sensor-based projects, Raspberry Pis require custom Python scripts to get the project up and running. As a non-developer, I don’t enjoy nor do I have the time, to Google the appropriate Python module and syntax required to read from a sensor. The nio System Designer solves this problem. I can create a service and quickly add functionality by simply dragging and dropping blocks into the canvas without an example project or code-base to reference. Additionally, with logging enabled by Pubkeeper, I can instantly verify functionality and troubleshoot issues by looking at the streaming logs and make changes to the block configurations as needed. Typically, I’d have to open up a text editor, find the correct line, check my syntax, and rerun the Python script. But in less than 15 minutes, with the help of nio, my service was built and fully functional.

How nio is integrated into this solution

While the System Designer acts as an easy-to-use interface, it is not what solely makes nio special. nio itself allows for zero-latency streaming between many interconnected devices. Also, nio doesn’t require any database or cloud connectivity, which in a service like a smart traffic signal, is vital to the success of the system. This is due to network latency or a crowded database could bog down response times and cause the light to be green when it should have been red. With nio on a Raspberry Pi, I can easily create a service that reads from multiple sensors with unlike data.


Using the office as a testing ground


After multiple near miss collisions with peeps and doggos at a busy hallway intersection, I decided that a safe and efficient way to establish the right of way was necessary.

The test

Using nio, a Raspberry Pi, IR motion sensors, a relay, and a stack light -- I decided to create a smart traffic light for use in our office hallways as a quick proof of concept to model nio’s role in building smarter cities. If someone is walking down the hallway to or from the break room, the light turns from green to red so that cross traffic is notified that an unseen obstacle (human, dog, etc.) is coming down the hall. Now, the office is equipped with everything necessary to eliminate future coffee infused collisions.


Traffic Light Service


The service for this proof of concept is pretty simple. Once the service starts, one signal is generated from the CounterIntervalSimulator (1Time) block to turn on the stack light by writing to a GPIO attached to the relay.

To operate the traffic light, the other CounterIntervalSimulator (DriveSensorRead) block generates a signal every half second, which then flows to both of the motion sensor GPIOs. If motion is detected, the motion sensor value goes from false to true.

The two modifier blocks (FormatNorth and FormatSouth) rename each of the sensor signals (from the default $value to $north and $south respectively) for better troubleshooting.

The signal streams from both sensors are combined together in a MergeStream (MergeSensors) block. If either sensor detects motion, the GPIOWrite (ToggleGreenRed) block, sends a signal from a GPIO pin to change the traffic light to red with the relay.

Build it yourself

Step by step tutorial


Want to build this yourself? Follow along with Scott as he walks you through his entire process.

Difficulty Level:

Easy (service build)
Hard (hardware integration)

Build Time:

Beginner
30 minutes for service building
4 hours of hardware integration

Experienced
15 minutes for service building
2 hours of hardware integration

Build List:

  • Raspberry Pi
  • 2 Channel Relay
  • Breadboard or Hackaday Perma-Proto Black Hat
  • Stacklight
  • IR Motion Sensors x 2
  • Wire to connect the sensors to the Raspberry Pi
  • Enclosure for Pi and Relay

Interested in partnering with niolabs?

We are in the process of building out our partner ecosystem. Visit our partner page and learn how we can help you deliver digital transformation.