Introduction: How to Build a Parking Sensor to Solve the Pain of Finding a Free Spot

About: Community manager @Ubidots, a startup empowering makers and hardware engineers to create applications for the Internet of Things #IoT

In this project we'll build a simple parking sensor using a Raspberry Pi. It turns out that every morning I have to face this question: is the ONLY parking spot in front of my office already taken? Because when it actually is, I have to go around the block and use at least 10 more minutes to park and walk to the office.

So I thought it would be cool to know whether the spot is free or not, before even trying to get there. At the end, the result was a nice widget that I could check from my Ipod or mobile phone

Step 1: Materials

1. Raspberry Pi Model B:

2. USB WiFi Dongle

3. Motion sensor by Parallax

4. Three female to female wires

5. Ubidots account - or - STEM License

Step 2: Wiring

The motion sensor is very easy to install as it only has three pins: GND, VCC (+5v) and OUT (digital signal “1” or “0”). If there's movement around it, it will output a "1", if there isn't, a "0".

You can see the connection in the diagram below, the cables are plugged directly to the GPIO pins of the Raspberry Pi. If you need more information about GPIO pins you can visit this guide from; it's a good source to become familiar with the Raspberry Pi pins.

Step 3: Setup Your Ubidots Account and Variables

If you're new to Ubidots, create an account here.

  • Navigate to the "Sources" tab and add a new source.

Step 4: Select Raspberry Pi As Your New Data Source and Fill the Form.

Step 5: Now Click on the New Source "My Raspberry Pi"

Step 6: Add a New Variable Called "free or Busy" and Don't Forget to Complete the Fields Name and Unit.

Step 7: Take Note of Your Variable's Id

Step 8: Coding Your Raspberry Pi

You should've already configured your Raspberry Pi, having Internet access from it. If not,follow this guide, or check this blog post about setting up WiFi.

When ready, access your Raspberry Pi through a terminal (LxTerminal if you're accessing your Pi directly through it GUI), navigate to a folder where you want to store this project and create a new file called ""

<p>$ sudo nano</p>

Now paste the following code:

import RPi.GPIO as GPIO ##GPIO library
from ubidots import ApiClient ##Ubidots Library import time ##time library for delays GPIO.setmode(GPIO.BCM)##set up BCM as numbering system for inputs GPIO.setup(7,GPIO.IN)##Declaring GPIO7 as input for the sensor

try: api=ApiClient("75617caf2933588b7fd0da531155d16035138535")##put your own apikey people= api.get_variable("53b9f8ff76254274effbbace")##put your own variable's id except: print "cant connect"##if this happens check your internet conection while(1): presence=GPIO.input(7)#)# saving the value of the sensor if(presence==0):##if presence is zero that means the other car is still there :( people.save_value({'value':presence})##sending value to ubidots time.sleep(1)##check every 5 seconds if the other car moves print "cero" if(presence): people.save_value({'value':presence})##the other car left so is empty now :) time.sleep(1) print "uno" GPIO.cleanup()##reset the status of the GPIO pins

Run your program:

<p>$ sudo python</p>

Step 9: Creating an Indicator in the Ubidots Dashboard

Now that we're getting the live data from the device, we need to create a custom widget that tells us whether the parking spot is taken or not. Click on the dashboard tab, then add a new widget:

Step 10: Choose "Indicator" Widget and Follow the Steps:

Step 11: Now You Have Your Indicator

Great! now you should see a live widget indicating the state of the parking spot. Btw you can embed this widget in any web or mobile app:

Step 12: Conclusion

That's all for this project! We learned how to plug a motion sensor to the Ubidots cloud using a Raspberry Pi and display its data in a live widget. The project could be improved by using a presence sensor and not exactly a motion sensor (which goes back to "0" after the movement is gone). It can also be extended by setting up SMS or Email alerts, which can be created in the "Events" tab in your Ubidots account.

Have a question? feel free to comment below or leave a ticket in our support page.

Here's another cool project using Raspberry Pi and a motion sensor: