Description
For this assignment, I wanted to create a physical demonstration of a "smart" parking spot accompanied by a graphical user interface that shows the status of the parking. I placed 3 photocells that measure the level of light in the ground along the middle length of the parking spot. As a car pulls into the parking spot, it will cover the photocells in the ground, decreasing the amount of light that reaches the sensors. The sum of the light of the three photocells was sent through the serial port to the Processing program. Depending on how much light is received through the photocells, the number of green bars indicating how much the parking spot has being pulled into will light up on the computer display. This helps the user visualize how much of the parking spot he or she has pulled into and at what rate, giving the user guiding information on the parking status. Also, a text status is displayed at the top of the parking spot visualization and changes depending on how far the car has pulled into the spot.
In addition, a pen cap was used to illustrate the idea of a bumper on the wall that tells the user when he or she should stop pulling into the parking spot. When the force resistive sensor that the pen cap is attached to detects a force from a vehicle nudging into it, it will light the green LED, indicating to the user that he or she has successfully pulled into the parking spot and should turn off the vehicle.
Video Demonstration:
http://www.youtube.com/watch?v= j32QEA2K9Jc
VIDEO
Components Used
1 - Arduino Uno
4 - 10K ohm resistors
1 - 220 ohm resistor
3 - photocells
1 - force sensitive resistor
1 - green LED
1 - breadboard
1 - pen cap
Code
Arduino Code:
/*
* Lab 4: Sensing - Force Sensors and Photocells
* Arduino
* Modified version of AnalogInput
* by DojoDave <http://www.0j0.org>
* http://www.arduino.cc/en/Tutorial/AnalogInput
*
* Modified by Brian McRae
* 2.24.13
*/
int photo_Pin0 = A0; // select the input pin for the photocells
int photo_Pin1 = A1;
int photo_Pin2 = A2;
int force_Pin3 = A3; // select the input pin for the FSR
int green_led = 13; // select the pin for the green LED
int light_val0 = 0; // variable to store the brightness value coming from the photocell sensor
int light_val1 = 0;
int light_val2 = 0;
int force_val3 = 0; // variable to store the force value from the FSR
int total_lightval = 0; // variable to store the total light value from the 3 photocells
void setup() {
Serial.begin(9600);
}
void loop() {
light_val0 = analogRead(photo_Pin0); // read the value from the photocell sensor, between 0 - 1024
light_val1 = analogRead(photo_Pin1);
light_val2 = analogRead(photo_Pin2);
total_lightval = light_val0 + light_val1 + light_val2; // sum of photocell values
force_val3 = analogRead(force_Pin3); // read the value from the FSR sensor
Serial.println(total_lightval); // print the total_lightval to Serial
if (force_val3 > 0) { // if there is a force felt by FSR, light up green LED
analogWrite(green_led, 255);
delay(2500);
}
else {
analogWrite(green_led, 0); // otherwise, green LED is off
}
}
Processing Code:
// Lab 4
// Processing
// 2.24.13
// Brian McRae
import processing.serial.*;
Serial myPort;
PFont f;
void setup() {
size(640, 640);
frameRate(50);
smooth();
noStroke();
f = createFont("Arial", 16, true);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('\n');
background(255, 255, 255);
}
void draw() {
}
void serialEvent(Serial myPort) {
rectMode(CENTER); // Create parking space
fill(0,0,102);
rect(320, 160, 255, 20); // Top rectangle
fill(0,0,102);
rect(185, 350, 20, 400); // Left side rectangle
fill(0,0,102);
rect(455, 350, 20, 400); // Right side rectangle
textFont(f, 38); // Create title
fill(0);
text("Perfect Parking", 10, 50);
textFont(f, 14);
fill(0);
text("By Brian McRae", 530, 630);
textFont(f, 30);
fill(0);
text("Status:", 180, 127);
String inString = myPort.readStringUntil('\n');
if (inString != null) {
inString = trim(inString);
float value = float(inString);
// Empty parking spot
if (value > 1400) {
rectMode(CENTER); // Erase Status Bar 1
fill(255, 255, 255);
rect(320, 525, 250, 50);
rectMode(CENTER); // Erase Status Bar 2
fill(255, 255, 255);
rect(320, 460, 250, 50);
rectMode(CENTER); // Erase Status Bar 3
fill(255, 255, 255);
rect(320, 395, 250, 50);
rectMode(CENTER); // Erase Status Bar 4
fill(255, 255, 255);
rect(320, 330, 250, 50);
rectMode(CENTER); // Erase Status Bar 5
fill(255, 255, 255);
rect(320, 265, 250, 50);
rectMode(CENTER); // Erase Status Bar 6
fill(255, 255, 255);
rect(320, 200, 250, 50);
rectMode(CENTER); // Erase Status Text
fill(255, 255, 255);
rect(380, 120, 200, 50);
// Display when parking spot is empty
textFont(f, 30);
fill(0, 0, 150);
text("Empty Spot", 290, 127);
}
if (value < 1400) {
rectMode(CENTER); // Status Bar 1
fill(0, 255, 0);
rect(320, 525, 250, 50);
rectMode(CENTER); // Erase Status Bar 2
fill(255, 255, 255);
rect(320, 460, 250, 50);
rectMode(CENTER); // Erase Status Bar 3
fill(255, 255, 255);
rect(320, 395, 250, 50);
rectMode(CENTER); // Erase Status Bar 4
fill(255, 255, 255);
rect(320, 330, 250, 50);
rectMode(CENTER); // Erase Status Bar 5
fill(255, 255, 255);
rect(320, 265, 250, 50);
rectMode(CENTER); // Erase Status Bar 6
fill(255, 255, 255);
rect(320, 200, 250, 50);
rectMode(CENTER); // Erase Status Text
fill(255, 255, 255);
rect(380, 120, 200, 50);
// Display when parking spot is being parked in
textFont(f, 30);
fill(255, 0, 0);
text("Keep Going!", 290, 127);
}
if (value < 1300) {
rectMode(CENTER); // Status Bar 2
fill(0, 255, 0);
rect(320, 460, 250, 50);
rectMode(CENTER); // Erase Status Bar 3
fill(255, 255, 255);
rect(320, 395, 250, 50);
rectMode(CENTER); // Erase Status Bar 4
fill(255, 255, 255);
rect(320, 330, 250, 50);
rectMode(CENTER); // Erase Status Bar 5
fill(255, 255, 255);
rect(320, 265, 250, 50);
rectMode(CENTER); // Erase Status Bar 6
fill(255, 255, 255);
rect(320, 200, 250, 50);
rectMode(CENTER); // Erase Status Text
fill(255, 255, 255);
rect(380, 120, 200, 50);
// Display when parking spot is being parked in
textFont(f, 30);
fill(255, 0, 0);
text("Keep Going!", 290, 127);
}
if (value < 1200) {
rectMode(CENTER); // Status Bar 3
fill(0, 255, 0);
rect(320, 395, 250, 50);
rectMode(CENTER); // Erase Status Bar 4
fill(255, 255, 255);
rect(320, 330, 250, 50);
rectMode(CENTER); // Erase Status Bar 5
fill(255, 255, 255);
rect(320, 265, 250, 50);
rectMode(CENTER); // Erase Status Bar 6
fill(255, 255, 255);
rect(320, 200, 250, 50);
rectMode(CENTER); // Erase Status Text
fill(255, 255, 255);
rect(380, 120, 200, 50);
// Display when parking spot is being parked in
textFont(f, 30);
fill(255, 0, 0);
text("Keep Going!", 290, 127);
}
if (value < 1100) {
rectMode(CENTER); // Status Bar 4
fill(0, 255, 0);
rect(320, 330, 250, 50);
rectMode(CENTER); // Erase Status Bar 5
fill(255, 255, 255);
rect(320, 265, 250, 50);
rectMode(CENTER); // Erase Status Bar 6
fill(255, 255, 255);
rect(320, 200, 250, 50);
rectMode(CENTER); // Erase Status Text
fill(255, 255, 255);
rect(380, 120, 200, 50);
// Display when parking spot is being parked in
textFont(f, 30);
fill(255, 0, 0);
text("Keep Going!", 290, 127);
}
if (value < 1000) {
rectMode(CENTER); // Status Bar 5
fill(0, 255, 0);
rect(320, 265, 250, 50);
rectMode(CENTER); // Erase Status Bar 6
fill(255, 255, 255);
rect(320, 200, 250, 50);
rectMode(CENTER); // Erase Status Text
fill(255, 255, 255);
rect(380, 120, 200, 50);
// Display when parking spot is being parked in
textFont(f, 30);
fill(255, 0, 0);
text("Keep Going!", 290, 127);
}
if (value < 900) {
rectMode(CENTER); // Status Bar 6
fill(0, 255, 0);
rect(320, 200, 250, 50);
rectMode(CENTER); // Erase Status Text
fill(255, 255, 255);
rect(380, 120, 200, 50);
// Display when parking is complete
textFont(f, 30);
fill(0, 102, 51);
text("Spot Taken", 290, 127);
}
}
}