Police Car



For my Engineering Final Evaluation, I created a Police Car. This Police Car would begin by playing the sound of a regular Police Car. When the sound has ended, the car starts to move forward while its blue and red lights flash. Until an object comes in contact or is near the car, it will continue to move forward. If in the situation of an object being close to the car, the lights of the car would stop, the car would then move backwards, turn left or right, then continue driving straight with the lights flashing again.
Supplies

The component's/supplies needed to make this Police car would consist of:
- Arduino
- 9 volt Battery
- Passive Piezo Buzzer
- Distance Sensor
- Potentiometer
- Car chassis
- H-Bridge (L293D)
- Breadboard
- Screws
- Screw Driver
- LEDs x2
- 330 ohm resistor x2
- Wires
- Male/Female Wires
- Brass Spacers
Mount Arduino


Mount/attach the Arduino to your Car Chassis as needed, using screws, a screwdriver, and brass spacers that are suitable for your chassis.
Add/Connect the H-Bridge


Begin by connecting power and ground from the opposite ends of the breadboard. In addition, begin connecting the H-Bridge (L293D) as required; these connections, apart from the pins connected to ground and the motors, can be connected to any pin on the Arduino as desired using wires. This step should also include the motors being connected to the H-Bridge.
Connect the Potentiometer


Connect the potentiometer by connecting the left side to power and right side to ground. The center pin should be connected to one of the Arduino's pins numbered A0 to A5 using wires.
Attach the Distance Sensor


Connect the Distance Sensor's first pin to power and the last pin to ground. Connect Trig and Echo to any of the Arduino's pins using male/female wires. Try to put the Distance Sensor at the front of the Car Chassis to make it easier for it to calculate inches.
Add the Piezo Buzzer



Connect the shorter end of the Piezo Buzzer to ground, and the longer end (positive side) to any of the Arduino pins using wires.
Connect Both the LEDs


Make sure there is enough space on the Arduino for the LEDs, but to connect them, connect the 330 ohm resistor from the LED's negative end (shorter side) to ground. Connect the LED's positive end (longer side) to which ever of the pins you choose.
Part 1 of Coding

Begin naming and declaring the components with their designated pin numbers at the top of the code.
Part 2 of Coding

Create a group named void setup, and start each line with "pinMode" before adding each of the components you declared before. Determine whether they are "input" or "output" and put them in brackets with the component. To print the code, add a line "Serial.begin(9600);" at the end of the other lines in void setup.
Part 3 of Coding

To ensure that the car moves like a regular car, it can identify and avoid crashes with obstacles. Start by identifying groups known as a direction (for example, void forward) and declaring what each of the controlled pins should be doing at that time.
Part 4 of Coding

In order to code the LEDs to work in a blinking motion, create a new group called void flash (name it whatever you would like), in this group you would add the commands to the LEDs to blink back and forth from each other.
Part 5 of Coding

The Piezo Buzzer is coded by creating a group called void siren (name it whatever you would like), in this group you would add the commands in order for the buzzer to make a specific type of sound when needed. The code shown is the code utilized to create some sort of a police car sound.
Part 6 of Coding

For controlling the car's speed using the potentiometer, add a group named void motorEnable and add the lines of code accordingly.
Part 7 of Coding

In the last stage of coding, set up a group named void loop; this is where whatever functions you want the car to perform (e.g., buzzer, flashing lights) will play in a loop.
Final Code
(image of full code)