Step 1: Logic

The project has 3 phases
Phase 1: Waiting for the car In this phase the device keeps looking for a moving object within the sensors proximity. If an object enters the proximity then one of the three LEDs turns on based on how far the moving object is. If the object is way too close, then a noise is made to make the moving object aware of the distance.
Phase 2: No car in the garage If there is no object in the proximity then turn off all the LEDs.
Phase 3: The car has stopped moving (Parked in the right spot) If the object has stopped moving and is still in the proximity wait for 20 CPU cycles and then turn off the LEDs.

Step 2: Hardware Requirement


For this very simple project we need:
- A Perfboard
- An Arduino nano/uno (whatever is handy)
- A Red, Green and a Yellow LED (Light Emitting Diode)
- 3 x 220ohm resistor for the LEDs
- One HC-SRO4 Ultrasonic Sensor
- A Buzzer shield or A buzzer and a 100 ohm resistor
- A 220v AC to 5v DC Buck step-down module
- One Female Pin Header Strip
- An Ethernet cable
- Some connecting cables
- A USB cable to upload the code to the Arduino
- and general soldering equipments

Step 3: Assembly


Let start by connecting the LEDs to the board.
Connect the Red LED to pin D2, Yellow LED to D3 and the Green LED to D4 of the Arduino by putting in a 220ohm resistor between the Arduino board and the LEDs. Now lets connect the Buzzer to analogue pin A0. Next, connect the Trig pin of the Ultrasonic Sensor to D5 and the Echo pin to D6 of the Arduino. Once all the modules are connected to the Arduino board, its time for us to connect all the positive and negative pins together. Connect all the positive pins of the modules to the +5v supplied by the Buck Step-Down Module and the negative pins to the -ve terminal of the Module. That's it, we can now upload our sketch to the board.
In this assembly I am using 3 LEDs to display the distance, however you can replace the 3 LEDs with a RGB LED, or you can also use an array of LEDs like an audio level indicator to display the movement of the car.

Step 4: My Setup

Picture of My Setup

OK now lets see what I have made.
I have installed the Arduino, buzzer, the ultrasonic sensor and the three 220 ohms resistors on one Perfboard. The 3 LEDs and the power module is installed on a second Perfboard. I will be covering the LEDs with a translucent cover to give it a nice look.
The 220v power supply will be connected to the screw terminal block. The base unit will then be connected to the LEDs and the power supply with an Ethernet cable.

Step 5: The Code

int trigPin = PD5; // Sensor Trip pin connected to Arduino pin D5
int echoPin = PD6; // Sensor Echo pin connected to Arduino pin D6
int redLED = PD2; // Red LED connected to pin D2
int yellowLED = PD3; // Yellow LED connected to pin D3
int greenLED = PD4; // Green LED connected to pin D4
int buzzer = A0; // Buzzer connected to Analogue pin A0
long TempDistance = 0; // A variable to store the temporary distance
int counter = 0; // Counter value to check if the object has stopped moving

void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(yellowLED, OUTPUT);
pinMode(buzzer, OUTPUT);
}

void loop() {
long duration, Distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
Distance = (duration/2) / 74; // Distance in Inches

if(counter < 20){ // Do the rest if the car is still moving
if (Distance > 200) { // Nothing in the garrage
turnThemAllOff();
}

if ((Distance > 55) && (Distance <= 200)) { // Turn on Green LED
digitalWrite(greenLED, HIGH);
digitalWrite(yellowLED, LOW);
digitalWrite(redLED, LOW);
noTone(buzzer);
}

if ((Distance > 15) && (Distance <= 55)) { // Turn on Yellow LED
digitalWrite(yellowLED, HIGH);
digitalWrite(redLED, LOW);
digitalWrite(greenLED,LOW);
noTone(buzzer);
}

if (Distance <= 15) { // Turn on Red LED
digitalWrite(redLED, HIGH);
digitalWrite(greenLED,LOW);...

Read more »