Introduction: Updated People Counter With Raspberry Pi
This is an updated version of UbiMaker's Open Source People Counter with new scripts.
Where I have made mistakes, I will note them, in the hopes that you don't have to do the same!
People Counters are an especially useful tool for libraries, and one that many cannot afford. The total cost for my build was under $100.
This tutorial assumes that your Pi is already set up (I recommend using Raspbian) and you've already configured your WiFi dongle.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Gather Your Materials
- Raspberry Pi B+
- A Micro SD Card (at least 8 GB)
- A PIR Sensor (Note: The one I have pictured and purchased is from SparkFun and is more useful for Ardunio projects, If you buy the Parallax option listed in the original tutorial you'll save yourself a step and some jumper wires)
- 3 Male-to-male jumper wires (Note: Not necessary if you buy the PIR sensor linked above)
- 3 Female-to-female jumper wires
- A USB WiFi Dongle (Note: Only purchase if it explicitly says it will work with Raspberry Pi
- Optional: USB Charger/Battery Pack if you want to go Wireless (helpful to have this pre-charged)
- Optional but helpful: Some kind of casing (not pictured)
Step 2: Sign Up for an Ubidots Account and Grab Info
- Create an account with Ubidots or sign into your pre-existing account
- Grab your account specific API (found in your profile)
- Create a new data source titled "People Counter" and retrieve the variable ID
- Click "Sources" in the top navigation menu
- Click "Add a Data Source"
- Choose "Raspberry Pi" as source type
- Title this "People Counter" or something similar
- Your variable ID will be displayed on the left column
Step 3: Wire It Up!
Even though the Raspberry Pi B+ has added ports, the schematics from the previous tutorial are still usable and the ports are the same.
- V+ to 5 volt power source (Pin 2)
- Ground to ground (Pin 6)
- Signal to GPIO07 (Pin 26)
Because I bought a PIR sensor that had the leads pre-soldered and combined, I had to use male-to-male jump wires to connect the sensor to female-to-female jump wires and then to the board itself. If you are clever and bought the Parallax sensor, you can connect your female-to-female wires directly from the sensor to the board.
Step 4: Coding Time!
If you're running the GUI (graphical user interface) on your Raspberry Pi, open a command window.
First call up the necessary libraries:
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install python-setuptools
$ sudo easy_install pip
$ pip install ubidots==1.6.1
Create a new file called "peoplecounter.py":
$ sudo nano peoplecounter.py
Then enter the following code (Note: Enter your personal API and variable ID that we pulled from your ubidots account earlier) NOTE: This code is not properly formatted because the basic plain text editor will not allow tabs to show nesting. Correctly formatted code can be accessed via this Drive doc.
from ubidots import ApiClient
import RPi.GPIO as GPIO
api = ApiClient("04856548e100d631985d3e9bd9d112c1846ff8da")
people = api.get_variable("55b2b19376254219c59334c0")
print("Couldn't connect to the API, check your Internet connection")
counter = 0
peoplecount = 0
presence = GPIO.input(7)
peoplecount += 1
presence = 0
counter += 1
counter = 0
peoplecount = 0
Step 5: Run the Script
Enter into your command line:
$ sudo python2 peoplecounter.py
If you run your hand over the sensor, you should start seeing numbers generated. If you've entered in your Ubidots information correctly, the same data should be generated into your Ubidots account.
Collect all your data and use the Ubidots platform to generate fabulous reports!