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

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

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 makezine.com; 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 "presence.py"

<p>$ sudo nano presence.py</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 presence.py</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:

Comments

author
apikaman19 (author)2016-10-23

what OS for raspberry pi

author
apikaman19 (author)2016-10-13

Hai, i have a question. Can i make 2 sensor for this project. Can or no ?

author
MateoV10 (author)apikaman192016-10-14

Yes you can do it with 2 sensors

author
apikaman19 (author)MateoV102016-10-18

Oh...i need to buys 2 sensors and 6 female cable, right but...what about coding raspberry pi and can i use same app for 2 sensors ?

author
apikaman19 (author)2016-10-13

Hai, i have a questions...can i use two sensor for this project...can or no ?

author
MateoV10 (author)apikaman192016-10-14

yes you can

author
coderbcn (author)2015-11-07

Hi , Nice article. Is it possible to make it wireless, so I install multiple sensors in multiple parking places in a garage and they remit the information to the raspberry pi wirelessly instead of using one raspberrypi for each space ?

author
shaun.v.vuuren (author)2015-03-06

does the sensor have to be in range of a wifi connection?

author
UbiMaker (author)shaun.v.vuuren2015-06-24

Hi there, sorry for the late reply -no comment notification was received-. Yes the board has to have wifi connectivity.

About This Instructable

8,310views

40favorites

License:

Bio: Community manager @Ubidots, a startup empowering makers and hardware engineers to create applications for the Internet of Things #IoT
More by UbiMaker:Test You Internet Speed Using a Raspberry Pi + UbidotsConnect Your Thinxtra Xkit Using SigfoxConnect Your Pycom Boards With Ubidots Over Wi-Fi
Add instructable to: