Toll Tax System using Arduino: Ultrasonic Sensor with Servo Motor

Toll Tax System Project:

Creating an Arduino-Based Toll Tax System with Ultrasonic Sensor and Servo Motor: Greetings, dear readers! In this article, we will guide you through the process of constructing an automated toll tax system using an Arduino Uno. We provide clear, step-by-step instructions, along with comprehensive explanations of the code and circuit diagram. This project is an excellent choice if you’re considering a science fair project.

While I’ve been primarily focused on intermediate and advanced-level projects, many individuals, both beginners and enthusiasts, have expressed interest in simpler undertakings. Thus, I’ve devised this straightforward concept. Ultrasonic sensors and Servo motors are widely favored, especially by novices.

Through this project, you’ll acquire fundamental skills such as car detection using an ultrasonic sensor and controlling a Servo motor to open a barrier.

Before delving into the construction phase of our project, let’s take a moment to familiarize ourselves with the toll tax system, sometimes referred to as the toll plaza stopping system.

Do you recall your initial visit to a toll plaza? The remarkable way they employed to halt vehicles for fund collection? Well, we are here to replicate that very mechanism on a miniature scale.

This project entails creating a precise replica of the vehicle-stopping system commonly found at toll plaza centers. The inspiration for this project was drawn from the real-world toll systems, where vehicles are automatically halted using a stopper triggered either by a sensor when a vehicle passes by or sometimes by a manual button.

In our case, we are utilizing an HC-SR04, also known as an ultrasonic distance sensor, to detect obstacles (vehicles). To raise the barrier, we are employing a micro servo. This is the essence of the project. Now, let’s venture into the construction phase.

Materials required to build automated toll system

Components and Materials Used:

1. Arduino Uno featuring the ATmega328P microcontroller.
2. HC-SR04 Ultrasonic Sensor.
3. Plastic Geared Micro Servo.
4. Single Strand Wire (substituting jumper wires).
5. Mini Breadboard.
6. Lithium Ion Battery with a protective case.
7. A few drops of superglue.
8. Arduino Programming Cable.
9. Arduino Integrated Development Environment (IDE).
10. A piece of popsicle stick.

Additional Tools and Components:

– Top Arduino Sensors.
– Super Starter Kit for Beginners.
– Digital Oscilloscopes.
– Variable Power Supply.
– Digital Multimeter.
– Soldering Iron Kits.
– Portable PCB Drill Machines.

Please be aware that these are affiliate links, and I may receive a commission if you choose to purchase these components via these links. Your support is greatly appreciated!

Circuit Diagram of toll system:

The circuit diagram for the Toll System is straightforward, with all connections easily visible.

Micro servo connections:

For those who are new to this, take a look at the plastic geared micro servo, as depicted in the image above. It features plastic gears, and the servo horns are equipped with a holder/barrier crafted from a popsicle stick.

Regarding the connections, we are utilizing the D9 pin on the Arduino Uno board, which is a PWM (Pulse Width Modulation) pin. This means that signals for the micro servo are transmitted in the form of pulses from the D9 pin.

Since we have linked the D9 pin to the signal input of the micro servo, we will employ the other two pins, namely Gnd and Positive, to connect to the positive and negative pins on the breadboard power rails.

This completes the servo connections. Now, let’s delve into the fundamental functions and connections of the ultrasonic sensor.

The HC-SR04, often referred to as the ultrasonic sensor or ultrasonic distance sensor, comes with four pins. These pins are labeled as Vcc, Trig, Echo, and Gnd. As usual, we will connect the Vcc and Gnd pins to the positive and negative rails of the breadboard, while the Trig and Echo pins are connected to the D5 and D3 pins on the Arduino board.

Functions of Ultrasonic sensor

The HC-SR04 sensor’s physical appearance is illustrated in the image below. From this visual representation, two circular structures are evident.

These circles serve as the transmitter and receiver components. When power is supplied to the sensor, one end emits ultrasonic signals that travel a precise distance of up to 15 centimeters. If any obstacles are encountered along this path, the signals strike the object and return to the receiver.

This small module has a wide range of applications, and one of them pertains to our project.

In our project, we employ vehicles as obstacles. When the sensor detects signals from these obstacles, it sends a signal to the micro servo to raise and hold for a specific duration (as specified in the code) before returning to its default position.

If you observe closely, you will notice the letters “T” and “R” at the sensor’s corners, signifying the transmitter and receiver sections.

Our circuit setup for this project is now finished.

Pro Tip: For a tidier and neater appearance of both the circuit and the project, I highly recommend using single-strand wires instead of jumper wires to prevent unnecessary wire clutter.

Here’s a visual representation of the ultrasonic sensor assembly.

You’ll notice that most of the wires are cleverly concealed within the enclosure. Specifically, the power input wires for the ultrasonic sensor are discreetly routed behind the Arduino Uno. To affix the Arduino Uno to the breadboard, I employed small pieces of double-sided adhesive tape.

Once the micro servo is integrated into this setup, the resulting configuration will resemble the visual representation below.

It’s important to highlight that since we’re not drawing power from a USB connection, we require a lithium-ion battery that can provide a stable 3.7V DC power supply for our project.

For this purpose, I utilized a battery holder that already featured two wires for easy connection. To simplify matters further, I attached the ends of jumper wires to these battery leads, allowing for convenient attachment and detachment of the power supply to the breadboard power rails.

Please exercise caution and refrain from supplying power to your project until you’ve added the necessary code to the Arduino board.

Code for Arduino automatic barrier for toll

#include<Servo.h>
Servo myservo;
const int trigPin=3;
const int echoPin=5;
long tmeduration;
int distance;
void setup() {
myservo.attach(9);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
Serial.begin(9600);

}

void loop() {
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
tmeduration=pulseIn(echoPin,HIGH);
distance=(0.034*tmeduration)/2;
if(distance<=10){
myservo.write(90);
}
else{
myservo.write(0);}
Serial.print(“distance:”);
Serial.println(distance);
delay(1);
}


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top