The components

Before we start looking at the coding for this project, we should take a step back and look at the overall concept and the various components used.

Above you will see a simple layout of the various components being utilized to solve the use-case as proposed in this tutorial. Let’s brake them down one by one before moving on to the code.

Ultrasonic Sensor

The ultrasonic sensor is used to detect when a vehicle is entering or exiting the parking lot. An ultrasonic sensor measure distance by generating and receiving sound pulses. So its basically just a speaker and microphone with some additional electronics combined into one unit. By measuring the time from when a pulse was sent by the speaker, to the time the pulse was received by the microphone, we calculate the distance (as we know the speed of sound) to the object (in this case the vehicle) that reflected the pulse.

The ultrasonic sensor i used for this project is the popular HC-SR04. You should be able to get one of these off ebay for a couple of bucks.

Use the following circuit diagram to hook up the HC-SR04 to your Raspberry PI.

Warning!

Notice the two resistors placed in the circuit. The resistors are used to lower the voltage from the 5V output pin of the HC-SR04 to the 3.5 V input pin on the PI. Not having the voltage resistors in the circuit could damage your Raspberry PI.

Note!

There are of course various technologies you could use to detect when a vehicle enters or exits the parking lot. The only reason i’m using an ultrasonic sensor for this project was that i already had one laying around from a previous project.

Note!

Notice that the sound pulses generated by the sensor is in a frequency range not detectable by the human ear, so you will not hear any sound when the sensor is active.

Camera

The camera is used to take a picture of the vehicle license plate as it enters the parking lot area. I’m using the Raspberry PI camera module V2 for this project, but you could basically use any camera that can be controlled from a Python script. You should be able to get this camera module off ebay or from your local PI shop. On ebay you can also get fully functional Chinese knock-offs for only a few bucks.

OpenALPR

OpenALPR is an Automatic License Plate Recognition (ALPR) software used to identify license plate numbers from a picture or image. You have the option of installing the OpenALPR SDK on-premise, or use there cloud service to perform the ALPR. For this tutorial we will be using the cloud service. Notice that OpenALPR is licensed software, but you may sign up for a free account that allows you to perform up to 1000 ALPR’s a month for free.

To sign up for a free OpenALPR account, go to https://www.openalpr.com/

After login in to OpenALPR, select Cloud API

On the Cloud API page you will find a secret key that will be used in our python script when uploading images to the OpenALPR cloud service.

The Plate/SEED DB

The “Plate/SEED DB” is a reference to some type of centralized storage where each license plate number is pared with the IOTA SEED that will be used as sender of the IOTA value transaction. In this tutorial i’m using a simple comma separated text file (or CSV) file stored locally on the Raspberry PI. However, in any real life scenario where security is a priority, the SEED’s should probably be stored in some type of encrypted database with restricted access.

The Car

We also need some object representing the car itself. As you can see from the images in this tutorial, i’m using a toy car that i found at a flea market near by. For building and testing you only need a simple box with a printed license plate on one side as shown below. Or even cooler, setting up the system in its intended environment, using real cars and license plates.

Note!

Make sure you draw a border around the license plate number as shown above. Otherwise the OpenALPR algorithms will have problems identifying where the license plate located within the picture.