Intelligent Traffic Congestion Control System using Machine Learning and Wireless Network

Mohammed Abdulmaged Faraj1,2*, Najmadin Wahid Boskany2

1University of Human Development, College of Science and Technology, Department of Computer Science, Sulaymaniyah, Iraq; 2College of Science, Department of computer, University of Sulaimani, Sulaymaniyah, Iraq

Corresponding author’s e-mail: Mohammed Abdulmaged Faraj, University of Human Development, College of Science and Technology, Department of Computer Science, Sulaymaniyah, Iraq; College of Science, Department of computer, University of Sulaimani, Sulaymaniyah, Iraq. E-mail:
Received: 11-09-2020 Accepted: 30-11-2020 Published: 10-12-2020
DOI: 10.21928/uhdjst.v4n2y2020.pp123-131


Traffic congestion has become a big problem for most people because it increases noise, air pollution, and wasting time. Current normal traffic light system is not enough to manage the traffic problematic congestions because they operate on a fixed-time length plan. In recent years, internet of things led to introducing new models of intelligent traffic light systems; by utilizing different techniques such as predictive-based model, radiofrequency identification, and ultrasonic-based model. The most essential one of these techniques is depends of image processing and microcontroller communications. In this paper, we propose an intelligent, low cost, and efficient microcontroller circuit-based system for controlling cars in traffic light. This system can manage car traffics smarter than traditional approaches, it is capable to dynamically adjust timings of traffic signal. It can rapidly respond to traffic conditions to reduce traffic congestion. For implementing this system, a server, microcontroller board, cameras, as hardware and wireless network between traffic lights as infrastructure for communication are used. The system uses machine learning technique (i.e.,Yolov3 model and OpenCV) for decision depending on existence of emergency cars and number of cars. The experiment results show higher accuracy in managing traffic lights and recognizing the emergency cars.

Index Terms: Machine Learning, Intelligent Traffic Control, Yolov3, Wireless Communication, Internet of Things


Transportation is one of the basic human activities for the development of societies. Ground transportation is done by all types of vehicles such as cars, motorcycles, bicycles, or public transportation. These regulations or rules set by government institutions. Traffic systems are designed to uphold the lives and safety of people, whether they are drivers or walkers as well as regulate and monitor pedestrian traffic. Traffic lights are tradition system used to manage the flow of traffic, also the walkers pass streets in safe way. However, the traditional traffic lights are not that good and it may cause additional traffic delays [1].

Different road traffic problems have appeared around the world as a result of population growth and increasing the number of cars in traffic lights, especially in large urbanized areas. Road safety mainly depends on drivers’ decisions, and these depend only on what drivers see and hear [2]. People also face other problems like traffic jam which is becoming riskier every day and led to traffic accidents. Traffic jam is a very serious problem, for that many researchers have paid attention to intelligent transportation system, for example, predicting traffic flow according to monitoring the traffic light. This mission stays as a challenge for computer vision, several methods have been implemented in previous years with some drawbacks such as difficulties in implementation due to using large number of hardware and high cost [3].

There are many ways of detecting vehicles and emergencies cars on road such as motion detection, installing lasers sensors. On both sides of the road, etc. [3], smart traffic light system is an essential part in smart cities to decrease traffic congestion [4].

There are some simple traffic management systems that have uses Global Positioning System and infrared (IR) for detecting the ambulance and can also count cars and detect the real-time density of traffic light, and some other technologies have been used radiofrequency identification tags to identify emergency vehicles and loop inductive methods to determine the number of vehicles [5].

In this paper, an intelligent system is proposed for managing traffic light. This system has capability of managing traffic light in smart way using image processing and machine learning to detect number of vehicles in the traffic light and ambulance as emergency car. The proposed system mainly uses Yolov3 as a perfect algorithm for car detection, it is faster than other algorithm for detecting objects in real time and the accuracy is high, for example, the accuracy of faster Region-based Convolutional Neural Network algorithm is high, but it is slow for detecting objects in real time.

The remainder of this paper is organized as follows. Related works are illustrated in section 2. System description explained in section 3. The detail of the proposed system is presented in section 4. System algorithm and flowchart are illustrated in section 5. Experiment result is explained in section 6. Finally, conclusions are presented in last section.


There have been many researches in developing intelligent traffic lights algorithms by researchers using different methods. Some of them are presented below:

M. M. Elkhatib and A. S. Alsamna (2019), designed a system consists of two part of implementation; first, to control traffic light more effective using embedded system and image processing and second used wireless and Bluetooth connection from android application to control traffic light signals, using image processing and embedded system, the system capable to detect the number of vehicles simultaneously in each lane, the green light will be longer where there are more cars in one lane than the other, in this method as a system controller, they used Arduino and for detection and counting cars used C++ environment and OpenCV library [6].

El. H. Imad (2019), proposed some solutions such as machine learning, internet of things, and closed-circuit television system, the first step is determined the number of outgoing and incoming cars in the traffic light by installing sensors in the roads and collecting data from them, also there are other sensors installed on the roads to determine emergency cars (for example, ambulances, polices, etc.) also an agent installed at each traffic light, which collect data from sensors that installed in the roads of an traffic light a pan–tilt–zoom camera installed at each traffic light it takes images of that roads and send them to the agent [7].

L. F. P. Oliveira et al. (2019), in their work developed a controller of traffic light and centralized it, able to communicate with other traffic lights through wireless network, it has been used magnetic IR sensors and digital camera to determine number of vehicles in that lane of intersection, also several wireless sensors installed, it allows creating strategic plans to control traffic and synchronizes it and prioritizes certain traffic that has more vehicles and maintains stability, vehicle speed. Two control circuits designed, one for direct current lamps and the other for alternating current lamps, are designed to control the different types of traffic lights. Control the traffic light period, collect data from sensors, and communicate with the RF module for that microcontroller circuit have been used [8].

T. A. Kareem and M. K. Jabbar (2018), proposed the system which is consists of hardware and software part. The first circular hardware part is a model which includes four lanes of a traffic light, also it has Global System for Mobile Communications (GSM) system. The lamps of the traffic light and GSM are connected to Arduino UNO. All signals that are coming from the GSM to software and converted to lamps of traffic lights are controlled by Arduino, second circular hardware part is same model of the first part except GSM it replaced with IR remote. The goal of their paper is to open the traffic light in the emergence cases, using GSM system and IR it control the closing and opening of the traffic light, designed for emergency vehicles, especially with ambulances by opening the traffic light in the lane which the ambulance came using IR system or GSM [9].

M. B. Natafgi et al. (2019), have used reinforcement learning to implement traffic light system and Lebanese traffic used as a real data for testing. It used a software simulation tool for testing and training. This tool can simulate the traffic lane and interact with neural network. On the roads, the sensors installed to detect cars. The controller have used the data of sensors to calculate the number of vehicles and time delays in those traffic lights it saves that data every hour in the database. Q-learning has been used to train the network. The proposed system tested using the traffic simulator SUMO [10].

M. Z. Ismail et al. (2019), developed a system for traffic light for emergency cars to pass the traffic intersection where the traffic road jammed with long queue of cars and change traffic light from red to green. The main tools have been used are Arduino and sensors through Bluetooth. Sensors with Bluetooth are located at emergency car and at the traffic light the Arduino and Bluetooth are located. The controller is Arduino mega and Bluetooth module is HC-05. The advantage of this system is saving time when emergency car comes to the traffic then the traffic light will change the light to green [11].

N. Diaz et al. (2018), developed an autonomous traffic light system using PIR sensor and Raspberry Pi, based on the PIR sensor (passive infrared sensor) the microcontroller control lighting of the traffic intersection based on the times that programmed with Python code which sends a signal to the microcontroller when in the traffic light the PIR sensors detect IR radiation. The Raspberry pi was programmed using the Python, the structure built with several parts: Python Code, Circuit Schematic, simple design of the traffic light, and printed circuit board [1].

A. H. Akoum (2017), designed a system in which filter method was used, this method filter the image only show the vehicles and separate all waste, after that display the number of cars in the image. According to the number of boxes that detected around the vehicles it gives the number of vehicles, the web browser used as a graphical user interface, many future improvements can be used to the counting vehicles, tracking and detection system can be expanded to real-time live video [3].


In this section, required hardware and software components are described briefly.

3.1. System Hardware

System hardware parts are packaged to be embedded with normal traffic light to changed it to intelligent traffic light. Below brief description of required hardware are defined one by one:

3.1.1. Control unit

The controller is based on ESP32 Nodemcu which it is electronic platform and open source. ESP32 Nodemcu is a microcontroller board module Chip with built-in WiFi: Standard 802.11 B/G/N, operating in the range of 2.4–2.5GHz, modes of operation: Client, access point, station + access point, dual core microprocessor, operating voltage: 3.3 VDC. It has 36 GPIOs. It has Bluetooth v4.2 BR/EDR and BLE, implemented in C. It can get power through micro-USB port and also it connected and programmed from computer through the on-board micro-USB connector, as shown in Fig. 1 [12]. In this research, ESP32 Nodemcu has been used to control the traffic light based on the data received from the server (i.e., number of cars and detecting ambulance). Moreover, it is used to communicate with next traffic light through wireless communication.


Fig. 1. On-board micro-USB connector.

3.1.2. LED

For traffic lights LED with three colors, red, green, and yellow are used for this purpose. LED that collects the three color in one are designed for traffic light, it has 3 pins connected with control unit (ESP32 Nodemcu) to receive high voltage to turn on the lights and 1 pin for ground connected to ground pin of Arduino, as shown in Fig. 2.


Fig. 2. LED traffic light.

Connection between ESP32 and traffic light is depicted by Fritzing open-source software, as shown in Fig. 3.


Fig. 3. Connection between ESP32 and traffic light.

3.1.3. Powerful server

For this work fast server computer required, the important part is GPU, whenever GPU is increased the training and testing will be faster. The minimum requirements are RAM 16GB, GPU Nvidia Geforce 1060 6GB. Fast and high-quality computer is important for training available dataset. Furthermore, it is used for process the video that received from cameras for detecting the cars and ambulance. Received data then send to microcontroller to make decision to open the lane or no.

3.1.4. Camera

Many cameras (i.e., IP camera or webcam camera) installed on each lane of traffic light to record video and send real live of traffic light to server in this research, webcam camera (i.e., resolution 800×600, frame rate up to 15 frame/s (VGA), automatic white balance and manual balance) has been used which is connected to computer through USB, as shown in Fig. 4.


Fig. 4. USB camera.

3.1.5. Benchmark board

Instead of real traffic light and to avoid some difficulties in real-life traffic light environment, simulated board is used for tests which is very close to real one. All required components exist, roads and intersections build on the board dimension which is 120×60 cm (Fig. 5).


Fig. 5. Benchmark board.

3.2. System Software

System software consists of different parts which are combined together, below a brief description of required software is defined one by one:

3.2.1. Yolo

Yolov3 “You Only Look Once” is an algorithm that uses CNN for object detection. YOLO is one of the fastest object detection algorithms. This algorithm applies a single neural network to the full image, it is accurate as SSD but 3 times faster it can be installed on Windows and Linux [13]. YOLOv3 as an algorithm that is a single convolutional neural network that predicts the bounding boxes with the class probabilities from the single check. This sort of algorithm is used mainly within the real-time application, this algorithm has been used because of it is faster algorithm for detecting objects in real time and the accuracy is high.

YOLO is made up of 24 convolutional layers, with two fully connected layers. Moreover, the input image is separated into M×M grid cells. Grid cell that includes the midpoint of the object is responsible for predicting the object. The output tensors of YOLO model will be a vector of N*N*(M*5 + C) in which M indicates the predicted bounding boxes with the confidence score by each grid cell. C is the class probabilities for the predicting bounding boxes. Every bounding box M has five components within which are x, y, w, and h and the confidence score C. The coordinate (x, y) represents the object’s midpoint with regard to grid cell location and offsets (w, h) represents the bounding box’s width and height concerning image dimensions. YOLOv3 foresees multiple bounding boxes per grid cell. However, those bounding boxes have highest Intersection over Union and ground truth to this which is known as non-maxima suppression [14].

An example of detection using YOLO is license plate detection for non-helmeted motorcyclist [15] and there are more examples for detecting different objects using YOLO.

3.2.2. Esp-now

For network communication among traffic light ESP-NOW used), ESP-NOW is developed by Espressif that allows various devices to communicate with each other. The protocol is like the low-power 2.4GHz. It needs before their communication to pairing between devices. Once the matching is complete, in a straight line it managed to communicate up to 165.47 m, the connection is secure and peer to peer. It used the MAC address of the microcontroller for linking for the purpose of joining in the right direction [16].


A brief description of the entire system is given in this section. The proposed model consists of hardware entities and software entities. The whole system (as one package) should be embedded to any traffic light to be changed from normal traffic light to intelligent traffic light.

The proposed system mainly works based on relation between a server computer and ESP32 ModeMcu open-source microcontroller. The server receives car videos through attached cameras, to be used for car identification and counting car numbers in each lane at the same time. The microcontroller side controls all the operations of the electronic circuits connected to its digital input and output pins.

Video cameras are used for inputting real-time video to the server, image processing starts by car identification, feature extraction, matching with available dataset images, and detecting ambulance car. The microcontroller, in turn, reacts depending on emergency car existence on the road sides by changing light sign to green and send command to next neighbor traffic light via wireless communication to change it to green sign.

Yolov3 in turn starts to do fast image processing on already prepared dataset which consist of 2000 images of normal car and 2000 images of ambulance.

The decision will be trigger in two cases: First, in case, if ambulance is detected on a side, the system automatically decides to open this side (i.e., change the light from red to green) to let it pass the traffic light soon and it communicates with next traffic light through wireless network to change the light to green too. Second, also in case, if the amount of waiting cars in one side exceeded 10 cars and other sides are empty automatically change this side light to green. Fig. 6 shows general description of the proposed system.


Fig. 6. General description of the proposed system.

5. SYSTEM Algorithm

In this section, an algorithm for managing the system is described in steps as follows: First step, the model sets its parameters. Then, continually images sent to the server through attached camera and image processing in the server side will start. Later, image detection begins by distinguishing emergency car from normal car, if received image was for emergency car (i.e., ambulance) or number of cars at a lane reached 10 then the server notifies the microcontroller to change the traffic light to green. In the same time, it communicates with next traffic light to change light to green to let the emergency car pass overall interactions. Otherwise, the system continues in a loop and gets new images. All steps are explained in Fig. 7 using below flowchart.


Fig. 7. Flowchart of system algorithm.


Experiment steps start with downloading images and selecting object in each image one by one that we want to recognize it. Then making an XML file for each image that contain coordination of that object in the image to be ready for YOLOv3 this done by python code, to be ready for training. For training this model, GPU used for around 1 day duration with graphics card NVIDIA GTX 1060.

After the model has been implemented and tested many times, possible results were obtained. As it appears, the system works normally and continues getting images from camera that installed in the traffic light, as shown in Fig. 8.


Fig. 8. Simulated system.

It tested with different in number of images for training, and it tested with the image, the accuracy and time of training were different. As shown in Table 1 and Fig. 9 dataset for training, 4000 images have been used (2000 normal cars and 2000 ambulance).

TABLE 1 Accuracy with different dataset


Fig. 9. Accuracy with different dataset.

As its clear from Table 1, we have 500 images for car with duration of 40 min the result is 97%, if we increase training time to 6 h and number of images to 4000 the system accuracy reaches maximum value 100% to detect normal cars and ambulance, while when the training time is short and number of images lesser the accuracy of detecting the ambulance starts from 65%.

As shown in Fig. 10 in the second test, the system implemented on a video for detecting ambulance the results shows different accuracy and time of training, as shown in Table 2 and Fig. 11.


Fig. 10. Different takes of video for detecting ambulance.

TABLE 2 Accuracy of ambulance with different dataset (Video)


Fig. 11. Accuracy of ambulance with different dataset (Video).


In this paper, we developed an intelligent approach to solve traffic lights congestion problems using machine learning with image processing models. The system mainly depends on Yolov3 model and OpenCV for decision. The traffic information is received from cars and vehicles in traffic light intersections. The system can recognize two types of car information, one of them is car type and the other is number of cars. Car type is used for distinguishing emergency car from normal car and number of cars is used for comparison among cars in each lane. In both cases, the system uses gathered information and gives priority to emergency cars over normal car and crowded lane to empty lane. To handle the complex traffic cases in our problem, the system uses image processing and Yolov3 algorithm. Another feature of this system is that the traffic lights communicate together through wireless medium to gives priority to emergency car. Tests experiments presented that the system can reduce over 55% of the average waiting timing for cars in traffic intersection and process emergency car as soon as possible. The above capabilities have good impact and effect in smart city’s traffic lights.


[1]. N. Diaz, J. Guerra, and J. Nicola. “Smart Traffic Light Control System“. In:2018 IEEE 3rd Ecuador Tech. Chapters Meet, ETCM 2018, 2018.

[2]. I. Santos-González, P. Caballero-Gil, A. Rivero-García, and C. Caballero-Gil. “Priority and collision avoidance system for traffic lights“. Ad Hoc Networks, vol. 94, pp. 101931, 2019.

[3]. A. H. Akoum. “Automatic traffic using image processing.“Journal of Software Engineering and Applications, vol. 10, no. 9, pp. 765-776, 2017.

[4]. H. Joo, S. H. Ahmed and Y. Lim. “Traffic signal control for smart cities using reinforcement learning“. Computer Communications, vol. 154, pp. 324-330, 2020.

[5]. A. Dumka and A. Sah. Smart Ambulance Traffic Management System (SATMS)-a Support for Wearable and Implantable Medical Devices. Elsevier Inc., Amsterdam, 2020.

[6]. M. M. Elkhatib and A. S. Alsamna. “Smart Traffic Lights using Image Processing Algorithms“. In:2019 IEEE 7th Palestinian International Conference on Electrical and Computer Engineering, pp. 1-6, 2019.

[7]. E. L. H. Imad. “Proposed Solutions for Smart Traffic Lights using Machine Learninig and Internet of Thing“. In:2019 International Conference on Wireless Networks and Mobile Communications, pp. 1-6, 2019.

[8]. L. F. P. Oliveira, L. T. Manera and P. D. G. Luz. “Smart Traffic Light Controller System“. In:2019 Sixth International Conference on Internet of Things:Systems, Management and Security, pp. 155-160, 2019.

[9]. T. A. Kareem and M. K. Jabbar. Design and Implementation Smart Traffic Light Using GSM and IR. pp. 1-5, 2018.

[10]. M. B. Natafgi, M. Osman, A. S. Haidar and L. Hamandi. Smart Traffic Light System Using Machine Learning“. In:2018 IEEE International Multidisciplinary Conference on Engineering Technology, pp. 1-6, 2019.

[11]. M. Z. Ismail, A. Z. A. Lutfi and M. A. M. Roslan. “Smart traffic light for emergency vehicle by using arduiono“. AIP Conference Proceedings, vol. 2129, pp. 1-6, 2019.

[12]. Andreas, C. R. Aldawira, H. W. Putra, N. Hanafiah, S. Surjarwo and A. Wibisurya. “Door security system for home monitoring based on ESp32“. Procedia Computer Science, vol. 157, pp. 673-682, 2019.

[13]. J. Redmon and A. Farhadi. YOLOv3:An Incremental Improvement, 2018.

[14]. Y. Jamtsho, P. Riyamongkol and R. Waranusast. “Real-time Bhutanese license plate localization using YOLO“. ICT Express, vol. 6, no. 2, pp. 121-124, 2019.

[15]. Y. Jamtsho, P. Riyamongkol and R. Waranusast. Real-time License Plate Detection for Non-helmeted Motorcyclist using YOLO. ICT Express, Amsterdam, 2020.

[16]. F. Koyanagi. ESP32 With ESP-Now Protocol, 2019.