IoT Vehicle Detection Sensor for Parking Spaces in Smart Parking System
Team Name: Team PullUp
Team Members: Sebastian Jara Garay, Brian Mull
Purpose: The purpose of this page is to discuss an application of the LPC1768 Mbed development board used in Embedded Systems Design (ECE 4180) at GA Tech. Specifically, design and construction of vehicle detection sensor nodes and a cluster head reception module will be shown.
Relevant Parts List:
- 2x - LPC1764 Mbed https://os.mbed.com/platforms/mbed-LPC1768/
- 2x - HC-SR04 SONAR https://os.mbed.com/users/4180_1/notebook/using-the-hc-sr04-sonar-sensor/
- 3x - Xbee S1 https://www.sparkfun.com/products/11215
- 2x - Xbee Breakouts https://www.sparkfun.com/products/8276
- 1x - Xbee USB Explorer Dongle https://www.sparkfun.com/products/11697
- 1x - Pi 3 https://www.raspberrypi.org/products/raspberry-pi-3-model-b/#buy-now-modal
- 2x - Low Mode 5V Power Regulator (optional) https://www.digikey.com/product-detail/en/texas-instruments/LM340AT-5.0-NOPB/LM340AT-5.0-NOPB-ND/148173
- 2x - 6V battery pack w/ Barrel Jack connector (optional)
- 2x - Female Barrel Jack bread board connector (optional)
Nodes
The nodes purpose will be to lie within or in front of a parking spot to detect if a car is present. It uses a HC-SR04 SONAR sensor to detect the vehicle. It then sends that data to the cluster head using an Xbee RF module. Xbee uses the Zigbee protocal which follows the IEEE 802.15.4 RF standard http://www.zigbee.org/zigbee-for-developers/zigbee-3-0/. These devices can be configured using the USB Dongle and the XCTU https://www.digi.com/products/xbee-rf-solutions/xctu-software/xctu configuration software (see below). Press default button at the top. Ensure that the Pan ID and Scan Channel fields are the same for all three modules.
The following code should be downloaded to each Mbed, ensuring to change the SPOTID variable for each node created. The commented code explains where to wire each Mbed port to each device. Use the Xbee Breakout to connect the Xbee to a standard breadboard. The Xbee uses 3.3V. Ensure it is not wired to Vu when connecting to the Mbed.
Node Code
// Team Pull-Up // ECE 4180 Final Project // Written by: Sebastian Jara Garay and Brian Mull // Last Update: 04/25/2018 // // Purpose: Collects detection data using SONAR sensor and relays to cluster head using // Xbee RF communication moodule // Includes - PowerControl is used to power down unused modules on mbed board #include "mbed.h" #include "ultrasonic.h" #include "PowerControl/PowerControl.h" #include "PowerControl/EthernetPowerControl.h" // Declarations int SPOTID = 1; // spot ID - should be changed for every new node DigitalOut led1(LED1); // currently unused DigitalOut Xbee_wake(p21); // currently unused wakes up the Xbee if in sleep mode int dista; // currently unused int available; // global variable used in distance check Serial xbee1(p28,p27); // declaration of Xbee module - p28 to DIN, p27 to DOUT Serial pc(USBTX,USBRX); // serial port for debugging DigitalOut rst1(p30); // Xbee reset pin - p30 to RST // distance calculation callback // if distance is less than 1000, available is 1, else it is 0 void calc_dist(int distance) { if(distance<1000){ available = 0; }else{ available =1; } } //Set the trigger pin to D8 and the echo pin to D9 //have updates every .1 seconds and a timeout after 1 //second, and call dist when the distance changes ultrasonic mu1(p6, p7, .1, 1, &calc_dist); int main() { // reset the xbees (at least 200ns) rst1 = 0; wait_ms(1); rst1 = 1; wait(.1); ////////Power Management/////// PHY_PowerDown(); Peripheral_PowerDown(LPC1768_PCONP_PCI2C2);//Turn off I2c0 interface 2 PWR/CLK(7) Peripheral_PowerDown(LPC1768_PCONP_PCI2C1);//Turn off I2c0 interface 1 PWR/CLK(7) Peripheral_PowerDown(LPC1768_PCONP_PCI2C0);//Turn off I2c0 Interface 0 Peripheral_PowerDown(LPC1768_PCONP_PCPWM1);//Trun off PWM1 Power/Clock (6) Peripheral_PowerDown(LPC1768_PCONP_PCSPI);//Turn off SPI interfaces Peripheral_PowerDown(LPC1768_PCONP_PCADC);//Turn off A/D conv Peripheral_PowerDown(LPC1768_PCONP_PCMCPWM);// Turn off PWM Peripheral_PowerDown(LPC1768_PCONP_PCENET); ///////////////////////////////// mu1.startUpdates(); //start measuring the distance int holdAvailable=0; // variable to detemine if state has changed while(1) { mu1.checkDistance(); // calls back to calc_dist if(available!= holdAvailable){ // only print to xbee if state has changed to reduce power usage of Xbee xbee1.printf("%d%d\r\n", SPOTID, available); holdAvailable =available; } wait(1); } }
The SONAR uses 5V. In this design, we choose to use a 6V battery pack with barrel jack adapter to power the Mbed. However, Vu does not operate when the Mbed is not being powered by USB port. If not using a USB power bank, a Low Mode 5V regulator must be used to power the SONAR sensor. The left most pin of the regulator should be connected to the battery pack output, the center pin is GND and the right-most pin should be connected to VCC on the SONAR. This regulator ensures a constant 5V is feed to the SONAR. Below is a complete listing of each component's wiring and pictures of our final build.
SONAR:
Mbed | SONAR | Regulator(if used) |
---|---|---|
GND | GND | Center |
p6 | Trigger | |
p7 | Echo | |
Vu(if USB Power) | VCC | Right |
+ Battery Pack |
Xbee:
Mbed | Xbee |
---|---|
GND | GND |
p27 | DOUT |
p28 | DIN |
p30 | RST |
Vout | VCC |
Cluster Head
For the cluster head, we used the Raspberry Pi 3 B to collect the sensor data using the third Xbee connected to the USB Dongle and send it to a server. We used a python code to process the incoming serial data and used a node.js script to set up the sever and send the processed data. Both of these scripts should be run from the same directory, as the python script writes a text file from which the node.js script reads. The code can be seen below.
Python Processing Script
#!/usr/bin/env python3 import time import serial ser = serial.Serial( port='/dev/ttyUSB0', baudrate = 9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1 ) counter=0 while 1: x = ser.readline() x = str(x.decode('utf-8')) if x is not '': with open('test.txt', 'r') as file: lines = file.readlines() if x[0] is '1': if x[1] is '1': lines[0] = "SpotID:" + x[0] + " Available: Yes\n" else: lines[0] = "SpotID:" + x[0] + " Available: No\n" if x[0] is '2': if x[1] is '1': lines[1] = "SpotID:" + x[0] + " Available: Yes\n" else: lines[1] = "SpotID:" + x[0] + " Available: No\n" with open('test.txt', 'w') as file: file.writelines( lines ) print(x)
Node.js Server Script
var app = require('express')(); app.get('/',function(request,response){ response.sendFile(__dirname+'/test.txt'); }); app.listen('8000');
Image of Raspberry Pi3 with Xbee & USB Dongle
Below is a video showing the sensors in action. The current server code requires a manual refresh to update the information.
Next Steps
Some suggested upgrades include:
- more power management inside the Mbed
- employing sleep mode in node Xbee modules
- creating shatterproof case for nodes
- using higher Ah battery
- auto run the scripts after booting the Pi
- employing auto-refresh to web-page
- use html to enhance web-page display
Please log in to post comments.