Tải bản đầy đủ (.pdf) (18 trang)

Project Iot102 Bluetooth-Controlled Traffic Light.pdf

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.08 MB, 18 trang )

<span class="text_page_counter">Trang 1</span><div class="page_container" data-page="1">

<b>PROJECT IOT102</b>

<b>Bluetooth-controlled traffic light</b>

<b>Group member</b>

<i><b>Trương Nhật AnhSE184905Trần Lệnh Quốc HuySE183878</b></i>

</div><span class="text_page_counter">Trang 2</span><div class="page_container" data-page="2">

<b>I. Introduction about this project... 3</b>

<b>II. About hardware... 5</b>

</div><span class="text_page_counter">Trang 3</span><div class="page_container" data-page="3">

<b>I.Introduction about this project</b>

The Bluetooth-controlled traffic light for junction and pedestrianproject is an innovative solution that leverages Internet of Things (IoT)technology to enhance traffic management and improve pedestriansafety at intersections. With the rapid urbanization and increasingvehicular traffic, there is a growing need for efficient traffic controlsystems that can adapt to changing conditions in real-time.Traditionally, traffic lights operate on fixed timers, resulting ininefficient traffic flow and potentially hazardous situations forpedestrians. This project aims to address these challenges byimplementing a smart traffic light system that utilizes Bluetoothtechnology for communication and control.

The main objective of this project is to design and develop a trafficlight system that can dynamically adjust signal timings based on trafficconditions and prioritize pedestrian safety. By incorporating Bluetoothconnectivity, the system enables real-time communication betweenvehicles and traffic lights, allowing for efficient coordination andtraffic flow optimization.

The Bluetooth-controlled traffic light system consists of three maincomponents: the traffic light controller, the Bluetooth module, and themobile application. The traffic light controller is responsible formanaging the signal timings and coordinating the flow of vehicles andpedestrians. The Bluetooth module facilitates wireless communicationbetween the traffic light controller and the mobile application, whichserves as a user interface for monitoring and controlling the trafficlights.

The mobile application provides a user-friendly interface whereauthorized personnel, such as traffic operators or city officials, can

</div><span class="text_page_counter">Trang 4</span><div class="page_container" data-page="4">

remotely monitor the traffic conditions and manually control the signaltimings if necessary.

Overall, this project aims to improve traffic management efficiency,reduce congestion, and enhance pedestrian safety by implementing aBluetooth-controlled traffic light system. By leveraging IoTtechnology, this solution has the potential to revolutionize the waytraffic is controlled at junctions and provide a safer and more efficienttransportation experience for both drivers and pedestrians.

<b>II.About hardware</b>

1. Components

● Arduino UNO board● Red, yellow and green LEDs● Breadboard

● Module bluetooth HC-05● Smartphone

● Ressitor

2. Properties of components

a. Arduino UNO board:

● Microcontroller: ATmega328P● Operating Voltage: 5V

● Digital I/O Pins: 14 (of which 6 can provide PWMoutput)

● Analog Input Pins: 6

● Flash Memory: 32KB (ATmega328P), of which 0.5KBis used by the bootloader

● SRAM: 2KB● EEPROM: 1KB● Clock Speed: 16 MHz

● Interface: USB, I2C, SPI, UART

</div><span class="text_page_counter">Trang 5</span><div class="page_container" data-page="5">

● Quantity: 1

b. LEDs (Light Emitting Diodes):

● Emit light when a current flows through them● Different colors available ( red, green, white, yellow)● Voltage drop across an LED typically around 1.8-3.3V● Current requirement varies based on the specific LED● Quantity: 2 red, 2 green, 2 white, 2 yellow

● Communication interface: UART (UniversalAsynchronous Receiver-Transmitter)● Range: Typically around 10 meters

● Supports Bluetooth serial communication with otherdevices (e.g., smartphones, computers)

● Quantity: 1e. Smartphone:

● A mobile device with advanced computingcapabilities

● Typically runs on iOS (Apple) or Android (Google)operating systems

● Can be used for various purposes, includingcontrolling and monitoring the Bluetooth-controlledtraffic light system through a mobile application● Quantity: 1

</div><span class="text_page_counter">Trang 7</span><div class="page_container" data-page="7">

<b>III.About software</b>

<b>1.</b>

<b>Requirement analysis</b>

<b>A.Functional Requirements:● Traffic Light Control:</b>

<b>- The system control two sets of traffic lights, each with red, yellow,</b>

<b>and green lights.</b>

Traffic lights for each set are controlled<b>independently</b>.The system switch between different states (red, yellow, green)according to a predefined sequence in source code.

</div><span class="text_page_counter">Trang 8</span><div class="page_container" data-page="8">

The system have a manual mode accessible via Bluetoothcommands.

Manual mode allow users to override automatic control and set thestate of each traffic light individually.

<b>B.Non-Functional Requirements:● Reliability:</b>

The system operate reliably under normal conditions.

</div><span class="text_page_counter">Trang 12</span><div class="page_container" data-page="12">

<small>// Khai báo chân được sử dụng cho LED báo hiệu cho người đi bộconst int pedes1Pin = 7;</small>

<small>const int pedes2Pin = 6;</small>

<small>char incomingByte; // Biến lưu trữ dữ liệu nhận được từ Bluetooth// Khai báo địa chỉ Bluetooth</small>

<small>SoftwareSerial bt(0, 1); // RX, TXvoid setup() {</small>

<small>// Thiết lập chân là OUTPUTpinMode(red1Pin, OUTPUT);pinMode(yellow1Pin, OUTPUT);pinMode(green1Pin, OUTPUT);pinMode(red2Pin, OUTPUT);pinMode(yellow2Pin, OUTPUT);pinMode(green2Pin, OUTPUT);pinMode(pedes1Pin, OUTPUT);pinMode(pedes2Pin, OUTPUT);Serial.begin(9600);</small>

<small>// Bắt đầu giao tiếp Bluetoothbt.begin(9600);</small>

<small>void autoTrafficLight() {digitalWrite(green1Pin, LOW);digitalWrite(yellow1Pin, HIGH);digitalWrite(red1Pin, LOW);digitalWrite(green2Pin, LOW);digitalWrite(yellow2Pin, HIGH);digitalWrite(red2Pin, LOW);digitalWrite(white1Pin, LOW);</small>

</div><span class="text_page_counter">Trang 13</span><div class="page_container" data-page="13">

<small>digitalWrite(white2Pin, LOW);delay(3000);</small>

<small>// Đèn red1 và green2 sáng, đèn white2 sáng, đèn yellow1 và yellow2 tắt,đèn white1 tắt</small>

<small>digitalWrite(green1Pin, LOW);digitalWrite(yellow1Pin, LOW);digitalWrite(red1Pin, HIGH);digitalWrite(white1Pin, LOW);digitalWrite(green2Pin, HIGH);digitalWrite(yellow2Pin, LOW);digitalWrite(red2Pin, LOW);digitalWrite(white2Pin, HIGH);delay(3000);</small>

<small>// Đèn green1 sáng, đèn white1 sáng, đèn red2 tắt, đèn white2 tắtdigitalWrite(green1Pin, HIGH);</small>

<small>digitalWrite(yellow1Pin, LOW);digitalWrite(red1Pin, LOW);digitalWrite(white1Pin, HIGH);digitalWrite(green2Pin, LOW);digitalWrite(yellow2Pin, LOW);digitalWrite(red2Pin, HIGH);digitalWrite(white2Pin, LOW);delay(3000);</small>

<small>}void loop() {</small>

<small>// Bật đèn xanh và tắt các đèn khác cho đèn giao thông thứ haidigitalWrite(red2Pin, LOW);</small>

<small>digitalWrite(yellow2Pin, LOW);digitalWrite(green2Pin, HIGH);digitalWrite(pedes1Pin, HIGH);</small>

</div><span class="text_page_counter">Trang 14</span><div class="page_container" data-page="14">

<small>digitalWrite(pedes2Pin, LOW);} else if (incomingByte == '2') {</small>

<small>// Bật đèn vàng và tắt các đèn khác cho đèn giao thông thứ nhấtdigitalWrite(red1Pin, LOW);</small>

<small>digitalWrite(yellow1Pin, HIGH);digitalWrite(green1Pin, LOW);</small>

<small>// Bật đèn vàng và tắt các đèn khác cho đèn giao thông thứ haidigitalWrite(red2Pin, LOW);</small>

<small>digitalWrite(yellow2Pin, HIGH);digitalWrite(green2Pin, LOW);</small>

<small>// Tắt đèn pedes1Pin cho người đi bộ và bật đèn pedes2PindigitalWrite(pedes1Pin, HIGH);</small>

<small>digitalWrite(pedes2Pin, HIGH);</small>

<small>} else if (incomingByte == '3') {</small>

<small>// Bật đèn pedes1Pin cho người đi bộ và tắt đèn pedes2Pin// Tắt đèn vàng và tắt các đèn khác cho đèn giao thông thứ nhấtdigitalWrite(red1Pin, LOW);</small>

<small>digitalWrite(yellow1Pin, LOW);digitalWrite(green1Pin, HIGH);</small>

<small>// Bật đèn đỏ và tắt các đèn khác cho đèn giao thông thứ haidigitalWrite(red2Pin, HIGH);</small>

<small>digitalWrite(yellow2Pin, LOW);digitalWrite(green2Pin, LOW);</small>

<small>// Bật đèn pedes1Pin cho người đi bộ và tắt đèn pedes2PindigitalWrite(pedes1Pin, LOW);</small>

<small>digitalWrite(pedes2Pin, HIGH);}</small>

<small>while (incomingByte == '4') {while (true) {</small>

<small>int incomingByte2 = Serial.read();</small>

<small>//Doc them 1 lan lenh tu button de dung vong lap, neu ko an gi thi giatri mac dinh incomingByte2 = -1, neu chon lenh khac -> incomingByte2khac -1 -> chay het lenh 1 vong while, vong lap nay se dung</small>

<small>if (incomingByte2 != -1) break;//auto</small>

<small>//dung` vong lap to khi vong lap nho dung` de nhan lenh khac</small>

</div><span class="text_page_counter">Trang 15</span><div class="page_container" data-page="15">

<b>IV.Implementation and Inspection</b>

<b>● Header and Libraries:</b>

The program starts by including the SoftwareSerial.h library forsoftware serial communication.

<b>● Pin Declarations:</b>

Pins for traffic lights and pedestrian signals are declared as constants.

SoftwareSerial is initialized for Bluetooth communication.

<b>● Setup:</b>

Sets the pins as outputs for LEDs.

Begins serial communication for debugging and initializes Bluetooth.

<b>● Auto Traffic Light Function:</b>

Defines a function to run the traffic light sequence automatically.

It sets different combinations of pins to control the traffic lights andpedestrian signals, simulating a traffic light sequence.

</div><span class="text_page_counter">Trang 16</span><div class="page_container" data-page="16">

'1' sets one set of traffic lights for vehicle traffic.

'2' sets another set of traffic lights for vehicle traffic and activatespedestrian signal.

'3' activates pedestrian signal for crossing.'4' initiates an automatic traffic light sequence.

It exits the automatic sequence loop when receiving any othercommand.

<b>● Bluetooth Communication:</b>

The program uses SoftwareSerial for Bluetooth communication, whichis suitable for Arduino boards lacking hardware serial ports.

<b>● Traffic Light Logic:</b>

The logic for controlling the traffic lights straightforward andunderstandable.

The sequence is controlled based on incoming commands fromBluetooth.

<b>● Code Organization:</b>

The code could be organized into more functions to improvereadability and maintainability.

</div><span class="text_page_counter">Trang 17</span><div class="page_container" data-page="17">

<b>● Comments and Documentation:</b>

The program contains comments, which help in understanding thefunctionality of different parts.

<b>● Hardware Considerations:</b>

The program assumes the hardware setup matches the pin

configurations defined. Ensure that the physical connections align withthe pin assignments in The program.

automatically adjust traffic signals based on real-time data andother parameters, reducing waiting times and saving energy byactivating lights only when necessary.

Furthermore, the collected data from the traffic lights can beutilized for traffic analysis, pattern recognition, and traffic flowoptimization, leading to improved traffic efficiency andcongestion reduction. The use of Bluetooth connectivitysimplifies the installation process and facilitates system

</div><span class="text_page_counter">Trang 18</span><div class="page_container" data-page="18">

expansion without the need for complex wiring. Overall, theBluetooth-controlled traffic light project presents a promisingsolution for traffic management. Continued research anddevelopment efforts are necessary to realize the project andensure the compatibility and safety of the system.

</div>

×