Police Car

by 880400 in Circuits > Arduino

108 Views, 1 Favorites, 0 Comments

Police Car

IMG_5828.jpg
IMG_5829.jpg
IMG_5830.jpg

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

Web capture_22-1-2024_183423_docs.google.com.jpeg

The component's/supplies needed to make this Police car would consist of:

Mount Arduino

IMG_5767.jpg
IMG_5768.jpg

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

download.png
IMG_5772.jpg

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

download.png
IMG_5769.jpg

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

download.png
IMG_5773.jpg

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

download.png
IMG_5823.jpg
IMG_5824.jpg

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

download.png
IMG_5822.jpg

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

IMG_5831.jpg

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

Part 2 of Coding

IMG_5832.jpg

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

IMG_5833.jpg

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

IMG_5835.jpg

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

IMG_5836.jpg

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

IMG_5834.jpg

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

IMG_5837.jpg

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)

Final Prodct