How to make simple automatic car parking toll gate system 4K using Arduino and UltraSonic Sensor

3 min read 1 year ago
Published on Aug 11, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

In this tutorial, you'll learn how to create a simple automatic car parking toll gate system using an Arduino and an ultrasonic sensor. This project is ideal for beginners looking to explore Arduino applications and understand the fundamentals of sensor integration and motor control.

Step 1: Gather the Components

Before starting the project, ensure you have all the necessary components:

  • Arduino board (e.g., Arduino Uno)
  • Ultrasonic sensor (HC-SR04)
  • Servo motor
  • Breadboard
  • Jumper wires
  • Power supply (USB or battery)

Step 2: Set Up the Circuit

Follow these instructions to connect the components correctly:

Ultrasonic Sensor Connections

  1. Connect the Trigger pin to Digital pin 6 on the Arduino.
  2. Connect the Echo pin to Digital pin 7 on the Arduino.
  3. Connect the Vcc pin to the 5V on the Arduino.
  4. Connect the Gnd pin to the Gnd on the Arduino.

Servo Motor Connections

  1. Connect the Control signal (Orange wire) of the servo motor to Digital pin 9 of the Arduino.
  2. Connect the Vcc (Red wire) of the servo motor to the 5V on the Arduino.
  3. Connect the GND (Black wire) of the servo motor to the Gnd on the Arduino.

Step 3: Write the Arduino Code

The code is essential for controlling the ultrasonic sensor and the servo motor. Below is a simplified version of the code you'll need:

#include <Servo.h>

Servo myServo; // Create a servo object
int trigPin = 6; // Trigger pin for ultrasonic sensor
int echoPin = 7; // Echo pin for ultrasonic sensor
long duration;
int distance;

void setup() {
  myServo.attach(9); // Attach the servo to pin 9
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  // Clear the trigger
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  
  // Set the trigger high for 10 microseconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  
  // Read the echo pin
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2; // Calculate distance in cm

  Serial.print("Distance: ");
  Serial.println(distance);
  
  // Control the servo based on distance
  if (distance < 10) { // If the distance is less than 10 cm
    myServo.write(90); // Open the gate
  } else {
    myServo.write(0); // Close the gate
  }
  
  delay(1000); // Wait for a second before next reading
}

Step 4: Upload the Code

  • Connect your Arduino to your computer using a USB cable.
  • Open the Arduino IDE, copy the code above, and paste it into a new sketch.
  • Select your Arduino board and port from the Tools menu.
  • Click on the upload button to transfer the code to your Arduino.

Step 5: Test the System

  1. Power your Arduino and observe the servo motor's behavior.
  2. Place an object in front of the ultrasonic sensor to simulate a car.
  3. Verify that the servo motor opens the gate when the object is detected within 10 cm and closes it when the object is far away.

Conclusion

You've successfully created an automatic car parking toll gate system using Arduino and an ultrasonic sensor. This project demonstrates the principles of distance measurement and motor control. For further exploration, consider adding features like a display panel for toll fees or integrating a card reader for payment processing. Happy tinkering!