Parking Assisting Device
My family has been struggling with bumping into the garage wall while attempting to park. For this reason I made a sensor that can relay to the driver of a car using LEDs how close they are to the wall of our garage.
Supplies
Materials:
- Breadboard
- Argon
- 4 LEDs
- At least 12 wires (8 need to be around 1 - 3 ft long for LEDs and ideally solid core)
- 4 breakers
- Ultrasonic sensor(HC_SR04)
- Power supply and USBC to connect to argon
Tools:
- soldering iron and solder wire
- wire stripper
- Tape
- Phone to connect to Argon
- Computer to code inside the particle website
Setting Up Argon Wiring
For now ignore wiring the LEDs(Orange and cream).
- Place the argon on the breadboard so that there are no open holes left(being the side of j1) of the Argon.
- Wire the Breakers(yellow) according to the diagram (the breaker farthest to the right is redundant; I just forgot to remove it for the photo).
- Place the sensor(purple) into the breadboard according to the diagram.
- Now just copy all the wiring using the diagram(Green, red and blue).
Make Extended LEDs
You will have to solder wire onto a standard led so that they can be seen from the seat of a car.
- Cut 8 equal length wires for all the LEDs. The length of wire that needs to be attached to the LEDs depends on your garage-car situation so its best to use longer than likely needed wire and experiment later. I cut my wire to a length of around 50in. Additionally it is best to use a different color wire for both the + and - side of the led(+ = long side of led and - = short side). I used red wire for the + side and black for the - side.
- Strip each side of all the wires about half an inch.
- Next solder the LEDs to the wires. I used a load bearing connection but that is not necessary.
Connect the Now Longer LEDs to the Breadboard
Attach the LEDs(Orange and cream) to the breadboard according to the diagram.
Code
- Set up a particle account.
- Connect the Argon to your internet.
- Create a new app and name it.
- Go to the libraries tab and search for "HC_SR04".
- Click "Include in project" and select your project.
- Copy and paste the code below into your project.
- Now flash the code to the argon
- Look at the comments below to see the specific values and how to change them.
Copy code inside lines
-------------------------------------------------
#include "HC_SR04.h"
double cm = 0.0;
double inches = 0.0;
int trigPin = D5;
int echoPin = D4;
int led1 = 2;
int led2 = 3;
int led3 = 6;
int led4 = 7;
int led5 = 8;
/*
Connect an HC-SR04 Range finder as follows:
Spark HC-SR04
GND GND
5V VCC
D4 Trig
D5 Voltage divider output - see below
Echo --|
>
< 470 ohm resistor
>
------ D5 on Spark
>
< 470 ohm resistor
>
GND ---|
Test it using curl like this:
curl https://api.spark.io/v1/devices/<deviceid>/cm?access_token=<accesstoken>
The default usable rangefinder is 10cm to 250cm. Outside of that range -1 is returned as the distance.
You can change this range by supplying two extra parameters to the constructor of minCM and maxCM, like this:
HC_SR04 rangefinder = HC_SR04(trigPin, echoPin, 5.0, 300.0);
*/
HC_SR04 rangefinder = HC_SR04(trigPin, echoPin);
void setup()
{
Serial.begin(9600);
Spark.variable("cm", &cm, DOUBLE);
Spark.variable("inches", &inches, DOUBLE);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
}
void loop()
{
cm = rangefinder.getDistanceCM();
inches = rangefinder.getDistanceInch();
Serial.println(inches);
delay(150);
//If the object is to far to be detected then that equals -1 so all leds will be turned off. Don't edit this one.
if (inches == -1)
{
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
}
else if(inches < 11) //If detects object less then 11in then turn on all LEDS.
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
}
else if(inches < 21) //If detects object less then 21in then turn on 3 LEDS.
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
}
else if(inches < 31) //If detects object less then 31in then turn on 2 LEDS.
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
}
//If detects object less then 41in then turn on 1 LEDS. If you want to adjust when the LEDs are activated just change the value next to the "x" comment. This logic is the same for the other three if/ else if statements.
else if(inches < 41) //x
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
}
}
-------------------------------------------------
Test
Before you set up the device in your garage test the device by moving an object closer and farther from the ultrasonic sensor. If it works then more LEDs should turn on the closer the object gets to the sensor(some objects will reflect better or worse so if the lights flicker excessively then use a more flat smooth object like cardboard to test).
Set Up in Your Garage
- tape the LEDs to the wall so that it can be seen by the driver of a car.
- then place the breadboard on an object so that it can sense your car. If the sensor is not stable then tape it to the object your placing it on.
- Drive the car up to the sensor and see if the lights turn on as intended(also have another person watching to make sure you don't drive into the wall or the device while testing).
- If the LEDs are not turning on properly then the device will require more adjusting. For example, as seen in the images above I had the device on the ground but it was not sensing the car properly so I put it on top of a box and the LEDs lit up perfectly.
- Congrats now you can park with ease.