Garage Parking Sensor
This is a simple garage parking assistant to help parking in a garage where there might not be a lot of room. I wanted something very simple, I didn't need LED strips, or buzzers, or text, or anything fancy, just a couple of lights, so I came up with this.
As you approach the sensor, it will begin to blink yellow. As you get closer, the frequency of the blinks will increase until the LED turns on, which indicates optimal distance. If you get too close, yellow and red will blink together.
The sensor will turn off after 50s of inactivity once the optimal distance has been reached, or if there is no car in the garage.
Supplies
1x Arduino board - I used an Arduino Pro Micro, you can use whatever you want, they'll all work
2x LED (I used yellow and red)
2x 220ohm resistors
1x HR-SR04 ultrasonic sensor
1x PCB (I used a 40x60mm board - you can use whatever you want, or a breadboard, or no board if you want)
1x micro USB charge/wall brick (this depends on your arduino board, the arduino UNO shown in the diagram uses USB type-B, you can also use a 5V adapter)
Wiring the Board
This is a pretty easy solder project. I soldered the arduino to headers to rise it up a little. I didn't think to take photos as I was building it, because I didn't think to write up an Instructible until after. But you can see from the circuit diagram that there's nothing difficult here.
In the photo, there's only one LED (this was taken before I decided to go with two LEDs), I just soldered the second LED and resistor above.
Code
The code here is pretty simple, and hopefully easy to follow. I'm not a coder, so I'm sure there's a more efficient way of doing this (and I'm open to suggestions).
Everything should be fairly self-explanatory.
#include <Ultrasonic.h> #define OPTIMAL_DIST 110 #define MAX_DIST 300 #define DIST_2 250 #define DIST_3 180 #define DIST_4 150 #define TOO_CLOSE 80 #define LED1 3 // red LED #define LED2 6 // yellow LED #define TIMEOUT 1000 // sensor timeout after inactivity Ultrasonic ultrasonic(5,4); // trig, echo void setup() { pinMode(LED1, OUTPUT); // red LED pinMode(LED2, OUTPUT); // yellow LED int count=0; } void loop() { int distance = ultrasonic.read(CM); count++; // Uncomment the following to test using Serial Monitor //Serial.print("Distance: "); //Serial.println(distance); if ((distance <= OPTIMAL_DIST) && (count > TIMEOUT)) { digitalWrite(LED1,LOW); digitalWrite(LED2, LOW); } else if (distance < TOO_CLOSE ) { digitalWrite(LED1, HIGH); digitalWrite(LED2, HIGH); delay(100); digitalWrite(LED1,LOW); digitalWrite(LED2, LOW); delay(100); count = 0; } else if (distance < OPTIMAL_DIST ) { digitalWrite(LED1, HIGH); } else if(distance < DIST_4 ) { digitalWrite(LED2, HIGH); digitalWrite(LED1,LOW); delay(100); digitalWrite(LED2,LOW); delay(100); count = 0; } else if(distance < DIST_3 ) { digitalWrite(LED2, HIGH); digitalWrite(LED1,LOW); delay(250); digitalWrite(LED2,LOW); delay(250); count = 0; } else if(distance < DIST_2 ) { digitalWrite(LED2, HIGH); digitalWrite(LED1,LOW); delay(500); digitalWrite(LED2,LOW); delay(500); count = 0; } else if(distance < MAX_DIST ) { digitalWrite(LED2, HIGH); digitalWrite(LED1,LOW); delay(1000); digitalWrite(LED2,LOW); delay(1000); count = 0; } else if(distance > MAX_DIST ) { digitalWrite(LED1, LOW); digitalWrite(LED2, LOW); } delay(25); }
Downloads
Mount
I designed and printed a box to mount the sensor to the back of the garage wall. I'm not going to include the STL files I made here, because they were a rush job, and while it does the job, I'm going to redesign it when I have time (it's too thin, the opening for the USB port doesn't line up, it's a little too large, etc). Any box will do, or no box at all if you want.