Car Gate

Original Credits and Idea go to The Neo Studios - https://www.youtube.com/watch?v=O7yoa-hwnkI
This project is a slightly modified version of The Neo Studio's car gate circuit.
Supplies

330ohm Resistors(2)
LED(2)
Ultrasonic Distance Sensor(1)
Servo Motor(1)
Arduino Uno(1)
Wires
Breadboard(1)
Assembling the Circuit on Breadboard

Wire the components onto the Arduino and Breadboard.
- LEDS - 330ohm resistors connected to cathode and ground, pin 10 and 11 are connected to anode.
- Distance Sensor - trig connected to pin 6 and echo connected to pin 7. Also connected to power and ground on the Breadboard.
- Servo Motor - Connect to power and ground on the breadboard. After connect the signal to pin 9 on Arduino.
Code

Create the variables you will use within your code.
Distance Sensor Funciton

This function will allow you to use the distance sensor easier within the loop of your code.
Setup

Within the setup you pinMode the LEDS and the servo motor.
Loop of Code

Within this loop you make the equation "cm = 0.01723 * readUltrasonicDistance(6, 7);" to allow the unit to be in centimeters.
Afterwards you make the if loop where the distance sensor will only activate the servomotor once the distance is less than 5 cm.
The two For loops after that which include pos(the position of the servo motor) will adjust accordingly to make the gate move up and down. As this happens the two LEDS will also turn on and off accordingly when the gate opens and closes.
Final Product
This is a video of the final product of this project working. Although it doesnt look too good it still works.