IoT using Raspberry Pi

Hasan Derawan
Aleph Publications
Published in
4 min readSep 24, 2020

Introduction

IoT (Internet of Things) has evolved rapidly in the last few years, especially when talking about integrating with the cloud providers like AWS, GCP and Azure. There are many cloud services to manage IoT devices such as AWS IoT Greengrass and Azure IOT Hub, which makes it possible to collect data from different sources (IoT devices) and aggregate that data into one platform.

AWS Greengrass and Azure IoT Hub

IoT is used in many sectors, like Big Data, AI (Artificial Intelligence), blockchain, logistics and even agriculture. It usually uses the concept of WSN (Wireless Sensor Network) as a basis of its applications. Home Automation, Healthcare, Surveillance and Environment monitoring are good examples where Wireless Sensor Networks are used.

The magical tool

One of the most interesting devices that can be used in Wireless Sensor Networks is Raspberry Pi. This is a magical tool that you can use to get started with IoT applications, even if you no experience in the subject.

Image Credit: Wikipedia

Raspberry Pi or RPi is a small credit-card sized computer developed in the United Kingdom and it runs on Raspberry Pi OS(a Linux based operating system). It can be considered as an IoT hub by connecting other less-capable devices wirelessly to its WI-FI adapter, or an IoT end device by connecting sensors and cameras to its board directly. It’s cheap, efficient and can be used for applications such as image processing and even AI. One of its famous applications is the “Magic Mirror”.

Let’s connect

In the following sections, I’ll explain how to form a wireless network of RPis that can be used in many IoT applications. Then we will implement a small application that takes photos with the RPi camera, extracts featured data from the photos and sends it to a destination node over a network of nodes using Socket Programming.

To establish a WSN using RPis, we need to follow these steps:

  1. Obtain an RPi and a MicroSD card
  2. Setup a “headless” version of the Raspberry Pi OS on the MicroSD card and turn on the RPi.
  3. Configure the network WLAN interface to work in “ad-hoc mode” and give it a private IP.
  4. Repeat the previous steps for each RPi you want to connect to your WSN. Give each RPi a different IP but on the same subnet.
  5. Make sure all the RPi devices are turned on. They will connect to each other wirelessly on the same network.
  6. Connect your workstation to this network wirelessly using the same mode “Ad-Hoc”. This workstation will receive the data from the nodes.

Let’s get a bit smarter

After we have this network-ready, it’s time to develop a smart application over it. We will build a solution to make a node capture a photo of a car, extract the plate number from the photo and send the number to your workstation over multiple hops (the nodes between the source node and your workstation, also known as middle nodes). The source node which captures the photo sends the data to the next node, and so on until the data reaches your workstation. Finally, you can print the plate number on your workstation console.

Car plate detecting WSN. Icon credit: Car, Camera, Wifi, Workstation.

To implement that, we need to connect a camera to the source node. Then we install a python library for object detection (OpenCV TenserFlow, YOLO). Once it recognises a car, it will capture a photo.

After that, it will apply a plate number recognition algorithm (ALPR) to extract the plate number from the captured photo. Then it will send the extracted data to the next node of which the IP has been defined previously. That can be implemented using Socket Programming, by considering the receiver as the server and the sender as the client. The receiver node receives the data and sends it again to the next node, and so on until the data reaches the workstation. The workstation will receive it like any node and print this value. Using these basic WSN principles and a few low-cost RPi devices, we can do many other interesting smart applications.

What’s Next?

Edge Computing is a hot research topic right now and Raspberry Pi has the potential to play a key role in edge computing applications. Watch out for this space!

--

--