ARDUINO - Police Car

by 4IR in Circuits > Arduino

19 Views, 0 Favorites, 0 Comments

ARDUINO - Police Car

IMG_1886.JPG

Hello! My name is Aarav, and I built a police car with the help of electrical components and of course, the ARDUINO UNO. The idea behind this car came from my love of high-tech cars with advanced features. As you explore this Instructable, you will see how my car differs from regular Arduino Uno cars. That being said, welcome to my Arduino Police Car Instructable!

Supplies

IMG_1887.jpg

For this project, I used:

  1. Arduino Uno - $27.60
  2. Small Breadboard - $10.99
  3. Breadboard - $8.09
  4. H-Bridge - $12.85
  5. Two Motors - $7.29
  6. Distance Sensor - $2.00
  7. Capacitors (I used 100uf & 10uf ) - $10.69
  8. Resistors - $16.64
  9. 555 Timers - $15.54
  10. IR Remote & Receiver - $2.23
  11. Buzzer - $0.57
  12. LEDs (Mostly red and blue LEDs) - $0.20

And of course:

  1. Appropriate length wires
  2. Cardboard
  3. Arduino Software
  4. Car Chasis - Custom Build


Before you continue, place your arduino and breadboard on your car chasis. Ensure they are in place and do not move around, otherwise, wiring will be a complete mess.

Flashing Police Lights

Screenshot 2025-01-20 162901.png
555 Timer.png

What differs a normal car from a police car (that's not the large text reading "POLICE" on the side)? That's right! The Flashing Police Lights.

For this step you will need:

  1. 2x 555 Timers
  2. 3x Red LEDs
  3. 3x Blue LEDs
  4. Wires
  5. 2x 330 Ohm Resistors
  6. 2x 1M (Million) Ohm Resistors
  7. 10uf Capacitor
  8. 100nf Capacitor

How it Works:

This circuit may seem complicated at first, but is very simple. The heart of these police lights are the two 555 timers. Essentially, I built two identical astable circuits, but both configured at a different frequency. The first 555 timer IC, uses a bigger capacitor and so it takes more time to toggle the output. The second 555 timer IC uses a smaller capacitor and so it toggles the output very fast. Whenever the red LEDs turn on, the blue LEDs are off, and vice versa. This pattern occurs very fast, which is what causes the rapid visual.

Refer to schematic


Setting Up IR Sensor

Screenshot 2025-01-20 165305.png
ir-receiver.jpg

Each and every remote outputs a different infared signal. This is why it is extremely important to understand which signals to configure in order to properly control your car. For my project, I used a TV Remote.


For this step, you will need:

  1. IR Remote
  2. IR Receiver
  3. Arduino Uno & Softawre (Sketch)
  4. Breadboard

ENSURE YOUR ARDUINO SOFTWARE HAS THE IR LIBRARY.


Firstly, refer to the first image, the set up on a breadboard for this step is temporary and fairly simple. Once you are done wiring the sensor, you can check which buttons send out which signal using the inbuilt code in the IR Receiver Library. Simply go to New >> Examples >> IR-SetUp.

This step will help you build your if-statements in step 5.

Don't Forget to have enough buttons for functions such as forwards, backwards, left & right


You can move on to the next step once you know which signals correspond with the buttons you wish to use.

Turn Signals

Screenshot 2025-01-20 172824.png
Screenshot 2025-01-20 172117.png
10uf Capacitor.png
Screenshot 2025-01-20 175812.png

As I mentioned before, I built this car to have as many modern car features as possible. What better than to add turn signals with a functioning version of its infamous "tick-tock" sound.


For this step you will need:

  1. 2x 10uf Capacitors
  2. 555 timer
  3. Buzzer


In this circuit, 555 timer IC is configured to work in astable / bistable mode. It means that voltage at the output of 555 IC continuously toggles between 0V and Vs (The supply voltage, in our case its 5V). Each time there is a transition in the output voltage from 0V to Vs or from Vs to 0V, the diaphragm of the speaker moves rapidly. This movement generates a tick or tock sound depending on whether the diaphragm is moving up or down.


This step also includes LEDs which are the visual indicators. Avoid just placing the LED on your breadboard, and find MALE/FEMALE wires to extend the legs of the LED. This will allow you to properly place the LEDs when it comes to the final step.


The code for this is simple:

if (irSignal == 0x1A2B) { // Replace 0x1A2B with your desired hexadecimal signal
digitalWrite(ledPin, HIGH); // Turn the LED on
delay(1000); // Keep the LED on for 1 second
digitalWrite(ledPin, LOW); // Turn the LED off
}
}

CAS (Crash Avoidance System)

download.png
IMG_1841.JPG
Screenshot 2025-01-20 175339.png

If you refer to the main code attached to this instructables, you will see multiple custom built functions which control how the wheels on the car move. The Crash Avoidance System (CAS) utilizes the stop(); function. This function turns off all the motors, to restrict movement.

For this step, you will need:

  1. Distance Sensor
  2. Arduino Sketch


The code for these fuctions look like:

// Function to move forward
void forward() {
digitalWrite(controlPin2, HIGH);
digitalWrite(controlPin3, LOW);
digitalWrite(controlPin4, HIGH);
digitalWrite(controlPin5, LOW);
}

// Function to move backward
void backward() {
digitalWrite(controlPin2, LOW);
digitalWrite(controlPin3, HIGH);
digitalWrite(controlPin4, LOW);
digitalWrite(controlPin5, HIGH);
}

// Function to stop the motors
void stop() {
digitalWrite(controlPin2, LOW);
digitalWrite(controlPin3, LOW);
digitalWrite(controlPin4, LOW);
digitalWrite(controlPin5, LOW);
}

// Function to turn left
void left() {
digitalWrite(controlPin2, LOW);
digitalWrite(controlPin3, HIGH);
digitalWrite(controlPin4, HIGH);
digitalWrite(controlPin5, LOW);
}


Firstly, wire the distance sensor correctly, and ensure you are using as little space as possible on your breadboard. Once you have the appropriate ECHO and TRIG pins, you can use this code to get your CAS working:


// Inside loop(), directly measure and calculate distance

digitalWrite(TRIG_PIN, LOW);

delayMicroseconds(2);

digitalWrite(TRIG_PIN, HIGH);

delayMicroseconds(10);

digitalWrite(TRIG_PIN, LOW);

long duration = pulseIn(ECHO_PIN, HIGH);

float distance = duration / 148.0;

if (distance <= 1.0) {
stop();
}


This code uses an ultrasonic sensor to measure distance. The TRIG_PIN sends an ultrasonic pulse, and the ECHO_PIN measures the time it takes for the echo to return using pulseIn(). The duration is converted to distance (in inches) with duration / 148.0. If the distance is 1 inch or less, the stop() function is called to halt the system.

H-bridge & Code

Screenshot 2025-01-21 083217.png
Screenshot 2025-01-21 083725.png
Screenshot 2025-01-21 084619.png
Screenshot 2025-01-21 085028.png
Screenshot 2025-01-21 085225.png
Screenshot 2025-01-21 085603.png

Now that we've explored the fuctions, you can start building your own code!

Firstly, It is essentially you include the IR library in your sketch, otherwise, none of the IR related functions will work. When you wire your H-bridge to the Arduino, refer to the H-bridge schematic. Essentially, you're H-bridge has two VCC, and four GND pins. The other pins are for Analog and Digital Inputs. In this case, I want the speed to me at max no matter what function is called. So, the analong inputs can be connected directly to power. The other remaining pins are the control pin. When you wire the control pins, remember what Arduino pin you connect it to. You will need it for your code! While you're at it, also see which pins your Distance Sensor, LEDs, buzzer, and Police lights connects to, you will need it in order for the previous steps to work.


Refer to the first image to see how to initilize these variables.


Secondly, you must complete the void setup(). This step declared whether the pin you connected your components to should output power, or input data.

Thirdly, the first part of the void loop should look like the fourth image. I used a modified version of the indicators in my code. The fifth image contains all the seperate if and else-if statements in order to correctly call on my movement functions. Remember, my IR Signals would e different from yours.

Final Step

Police Car
Screenshot 2025-01-20 181043.png

All that's left for this step is to build your desired frame!

For this step, you will need:

  1. Cardboard (optional)
  2. & whatever you want to add


I chose to build a frame using cardboard. I made a small cut out in the front for my distance sensor, as well as one in the top for my police lights.


For the police lights, I had two seperate wires, one going into a different GND pin, and one going in to PIN 8.


That's all! Have fun building your Arduino Police Car!