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);
}
An overview of the code used in our project:
To simplify comprehension and facilitate customization, especially for beginners, I’ve divided the code into three distinct segments. These three parts serve as building blocks to elucidate their respective roles in achieving the final functionality.
This initial section, often referred to as the declaration or definition phase, involves the allocation of pin numbers for transmitting and receiving signals with various modules.
In addition, at the outset, we specify the particular modules from the library. In our case, this pertains to the servo module.
As you observe, we are designating pins for the echo and Trig terminals and invoking the time duration and distance parameters. These parameters will be utilized in subsequent lines, which are detailed in the following section.
In the concluding section, we configure the lifting angle of the servo horn and the time it takes to respond. If you wish to make adjustments to the angle of rotation or the delay at which the servo operates, you can modify the values within “myservo.write” and “delay.” However, for this project, I recommend keeping these settings unchanged.
Please note that there are two modes available in this project. Mode 1 causes the servo horn to move to a single angle when an obstacle is briefly placed and then removed in front of the sensor. In contrast, mode 2 involves a two-step rotation, which is activated when an obstacle is kept in front of the sensor for more than 2 seconds.
Steps to upload code into Arduino Uno
Here are the steps to set up and upload the code to your Uno board:
1. Connect your Uno board to your computer using the programming cable with the USB side plugged into your computer.
2. Launch the Arduino IDE and copy-paste the provided code into the editor.
3. Before proceeding, ensure you’ve selected the correct board. Navigate to the “Tools” menu, choose “Board,” and select “Arduino Uno.”
4. Double-check the port settings. You can find this under “Tools” and then “Port.”
5. Once all the settings are in order, click the “Upload” button to transfer the code to your Uno board.
6. After a successful upload, disconnect the USB cable from your Uno board.
7. You can now power your Arduino Uno using an external battery. If you’re using a 3.7V battery, there’s no need for a resistor. However, if you’re using a higher-voltage battery, you may need to add a resistor according to the voltage specifications.
8. Finally, to enhance the visual appeal of your project, you can create a simulated road using a piece of cardboard and colored paper to make it look more realistic.
Now, you can arrange all the components neatly as shown below, presenting the finished project, all set to start gathering contributions!
I’ve organized the components in a way that ensures nothing obstructs the movement of the vehicle or any obstacles. In case you encounter issues, such as the servo moving unnecessarily, please adhere to this sequence for efficient component placement.
This marks the conclusion of our project. As always, if you have any questions or concerns, feel free to reach out by using the comments section.
Source: Toll Tax System using Arduino: Ultrasonic Sensor with Servo Motor