0% found this document useful (0 votes)
3 views29 pages

Iot Project

The document outlines a project report for a School Bus Tracking System aimed at enhancing the safety of children during school commutes. It details the use of GPS and RFID technology to provide real-time tracking and identification of students, along with features for emergency assistance. The system is designed to alleviate parental concerns regarding children's safety while using school buses and improve overall accountability and reliability in school transportation.

Uploaded by

studentckp7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views29 pages

Iot Project

The document outlines a project report for a School Bus Tracking System aimed at enhancing the safety of children during school commutes. It details the use of GPS and RFID technology to provide real-time tracking and identification of students, along with features for emergency assistance. The system is designed to alleviate parental concerns regarding children's safety while using school buses and improve overall accountability and reliability in school transportation.

Uploaded by

studentckp7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

“SCHOOL BUS TRACKING SYSTEM”

Project Report Submitted To

By

Name (Enrollment No)


Akshar Kevadiya 210090107022
Dhruval Dobariya 210090107004
Disha Lathiya 210090107083

Guided by
Prof. Hemil patel

Prof. Rakesh katariya


1 INTRODUCTION

At the current point in time, due to the increasing number of kidnaps and accident cases,
parents always worry about their children, even their children using a school bus for
transportation. Millions of children require school buses to pick up and drop to the school
on an everyday basis. A means of safe transport for these children is one of the main
concerns that need to be taken care of by the school management. Hence, the need for a
reliable management system of the school bus in today’s world has increased to a greater
extent. So we are developing a smart tracking system for school buses, which is an android
based application for providing remote tracking. GPS is used to track the location of the
school bus in real-time. The RFID technology is used to identify the identity of children.
Parents can see the location of the bus, and they will be notified when the children are
getting into a bus or getting down from a bus. The proposed system will result in providing
the security to children travelling via school bus.

Understanding the importance of transport safety, a few years ago in 2014 in India, the
CBSE made it mandatory for all school buses to install GPS systems to ensure the safe
transportation of children to and from schools.

The paper proposed a bus safety system which was designed to control the entering/exiting
of students from the bus. This system does several tasks, including identifying personal
information (Eg. Name) of each student using RFID tag, which will exchange the data with
the RFID reader via radio waves, and displaying each student name into LCD display.
There is provision for three switch inside the bus which has been deployed for Technical ,
medical and other emergency assistance.

1.1 Aim of the project


 Develop an affordable low cost system for tracking and ensuring safety of school
children.
 Securing the commute of students to and from school.
 Help ensure safe arrival and departure of students.
 Real time tracking
 Improve accountability and reliability of school buses.

1.2 Objectives of the project


The objective of this project is to develop a RFID base access control and proximity
security system that is able to:
 Uniquely identify the authorized student data and store student ID and name.
 Parents can locate their child and also get information about their child’s arrival and
departure.
The proposed system provides a facility to track the exact location of the bus using GPS in
a cost effective way. So this could be implemented even in small scale schools. Such
systems must be installed in order to reduce the number of abduction taking place.
There is provision for three switch inside the bus which has been deployed for Technical ,
medical and other emergency assistance.

1.3 Why All Schools Must Have A GPS Bus Tracking System?
A bus tracking system won’t solve all of your school’s bus-related problems. But the right
solution can ease your school bus-related operations by automating manual processes and
ensure students’ safety and security at the same time. A school bus tracker also goes a long
way in assuring parents that their children are in safe hands.

The following are some issues faced by parents along with students and school
administration while using school buses in traditional ways.
 Parents waiting for School Buses:
For children’s safety and security, unwillingly parents have to wait
for hours at the bus stop until the school bus pick up or drop their children.

 Students waiting alone at bus stops:


Most of the times it is seen that students have to wait for the school
bus at bus stops alone, due to which they meet with mishaps, accidents and in a few
cases, gets kidnapped. Also, it has been noticed that in metro cities where people
are busy in their fast paced lives, they do not have time to wait at bus stops with
their children to get them into school buses. Parents want to drop and pick their
children from their bus stops as quickly as possible.

 Missed school bus:


Students miss their school bus if they get delayed in reaching the bus
stop as there is no option for the parents to get updates on the current location of the
school bus.

 Over speed issue:


We have also seen that the bus driver often exceed the speed limit set
for school buses which is a serious safety risk. Students get injured when an
immediate break is applied or the vehicle is accelerated. Over speed sometimes
leads to unfortunate things like accidents and life loss.

 Stress-Free Parents, Relaxed Admin:


A mobile bus tracker app gives parents timely updates about the
whereabouts and well-being of their child. They save on wait times and monitor
their child’s bus trips in real-time.

1.4 Overview of Contents


The following chapters portray the work that has been accomplished and the impact of
introducing tracking system in the economy. The second chapter gives an overview of the
Literature review of RFID and Tracking system and different technologies that can be used
in tracking system. The third chapter gives specifies the working of the system and Basic
Operating Principle. The fourth chapter gives the details of the hardware components and
software components that we have used. The fifth chapter gives an overview of the ways
we have used to display the result. The sixth chapter gives an overview of the advantages
and limitation of our bus tracking system.
2 Implementation

2.1 Module Specification


The proposed system has two function modules and two user modules:
 Function Modules
1. Location Tracker
2. Student Identification
3. Emergency switches
 User Modules
1. School Administration
2. Parents

Function Modules
Our proposed system gives the real time location of bus and Smart bus tracking technology
is advantageous for tracking and monitoring a college bus.

Figure1.1: Block diagram of transmitter

Figure1.2: Block diagram of receiver

1. Location Tracker
Generally, our system is operated by GPS which is attached with the bus. Firstly,
GPS receives the satellite signals and then the position co-ordinates with latitude
and longitude are determined by it. The location is determined with the help of GPS
and transmission mechanism. After receiving the data, the tracking data can be
transmitted using any wireless communications systems. The GPS module will be
connected to micro controller reader and the real time of vehicles will see the
location continent. Node MCU will receive valid data from GPS module and upload
it on firebase with the help of Wi-Fi. Every 15 to 20 second data of bus will update.
This means that no events is generated, the Bus will be sent to the Server event 30
second by sending the GPS location to NodeMCU which means the last location of
the Bus will allocate be saved on the Server. The mobile application will retrieve
and the show the exact location of bus

2. Student Identification
Information of a subject using radio waves. This information consists of unique
digit number which differentiates various objects. A RFID system is made up of
two different parts viz. RFID tag and RFID reader. There is a microchip antenna
inside tag; This chip consists of useful data in different forms. A study has showed
that, the performance of reader decreases rapidly with increase in a distance.
Children carries a unique RFID card. This RFID card is embedded on his own
smartcard. The RFID tag reader is installed near the bus entrance. It will read all the
passive tags that the students will swipe while entering/leaving the bus. As soon as
a child swipes the card; the reader will identify him based on the unique
identification number associated with the RFID tag. The LCD unit will display the
unique identification number on the display along with the entry timings on the
LCD display. Now the work of GPS module comes into picture. The embedded
GPS module will help to locate the bus by providing the longitude and latitude
coordinates of the location and sends this information to the microcontroller. This
information is then passed to the microcontroller which conveys the same to the
ESP8266 module. The Wi-Fi module will send the information of student and GPS
location on the registered parent’s mobile number. This way parents will be assured
of their kids boarding and leaving the bus and the driver of the bus will also get the
attendance of the students.

3. Emergency switches
There are 3 switches in the Bus for different kind of emergency situation like
technical, medical or police emergency. Switches are connected to the A7 analog
pin of micro controller. When we press switches, pin status will turned 0 & if we
leave them the status is 1. If switch value is less than 770 than the request should
be considered. if value is less than 10 than it should be medical emergency, if value
is between 485 to 550 than it should be technical emergency and if value is between
650 to 700 than it should be police emergency. If any emergency situation will
arrive drive can inform school administration with the help of these 3 switches.

User Modules

1. School Administration Application


 The Bus route can be Seen in the Application
 The location Of the Pickup and drop of all the students be can seen.
 Bus Speed also can be Seen.
 Medical, technically or police help will show in the school Administration
application
2. Parents Application
 Parents can enter the Enrollment number of their child & can see the pickup & drop
location.
 The bus route can be seen in the Application.
 The seed of bus can also be seen in the Application.

2.2 Block Diagram

Figure1.3: Block Diagram

 The IC is inserted in RFID Tag, when the RFID tag is moved closer to the RFID
reader. The electromagnetic field will generated.
 Data will receive by micro controller and students ID number will appear on LCD
display and that information send to node MCU with the help of serial
communication.
 Once data will receive by NodeMCU, and then NodeMCU will give it validation
and if the data will correct than and than only it will take data from GPS and attach
them with string.upload them on server which include student’s name, pick up and
drop location and than these information displayed on application.

2.3 Basic Operating Principle


The working principle of the bus safety system is that since each student carries a card that
contains a unique number with his/her name, so once the students start entering the bus, the
RFID reader will capture their names and display into LCD. Start RFID reader scanning
Sensed RFID signal? Get information from RFID tag Re-send signal Show tag holder
personal information into LCD display Read for next tag.
Flow Chart
3 COMPONENTS

3.1 Hardware Components


3.1.1 RFID
RFID stands for radio frequency identification. RFID tags are small chips that are used in
our day to day life for unlocking hotel rooms, entering into cars etc. This tiny chip along
with an RFID reader forms the RFID system. An RFID system consists of two parts 1)
RFID Reader 2) RFID Tag.

1) RFID reader:
The RFID reader has a radio transmitter and receiver within. The
reader transmits radio frequency signals incessantly upon powering. It is also called
as an interrogator. When an RFID tag is placed within the range area of a reader, it
energizes the tag through electromagnetic induction and collects the data from it.
Data is stored in the RFID tag electronically. Tags can store only a few kilo bytes
of data. This data is retrieved by the reader using electromagnetic waves.

2) RFID tag:
The image given below is that of an RFID tag (smart card shaped tag).
RFID tags are available in different types of shapes and sizes. The Tag contains an
IC for storing the information, an antenna for transmitting and receiving, and also a
modulator. Tags are small in size and they can hold only few bits of data. The
operation of an reader is very much similar to barcode scanning method which uses
Universal Product Codes (UPC) codes. In some applications, RFID Tag and Reader
has advantages over the barcode system.

Types of RFID Tag:


1. Passive
2.Active
1.Passive:
Passive tags are activated only when it receives a signal from the reader. This
signal activates the internal IC of the tag through the antenna. Thus the tag sends required
data which is stored in it to the reader. Any external battery are not use by these tags. Using
the power, they are powered up from RFID reader. The data in these tags is pre written.
One cannot change the information in these tags.

2.Active tag:
While active tags have a power source for their internal circuitries, And for
sending the response to the reader also,it uses its own power supply.

3.1.2 Arduino Nano


 Arduino Nano is a small, compatible, flexible and breadboard friendly
Microcontroller board, developed by Arduino.cc in Italy, based on ATmega328p
(Arduino Nano V3.x) / Atmega168 (Arduino Nano V3.x).
 Arduino Nano is simply a smaller version of Arduino UNO, thus both has almost
same functionalities.
 It comes with an operating voltage of 5V, however, the input voltage can vary
from 7 to 12V.
 Arduino Nano Pinout contains 14 digital pins, 8 analog Pins, 2 Reset Pins & 6
Power Pins.
 Each of these Digital & Analog Pins are assigned with multiple functions but their
main function is to be configured as input or output.
 Functions like pinMode() and digitalWrite() are used to control the operations of
digital pins while analogRead() is used to control analog pins.
 The analog pins come with a total resolution of 10bits which measure the value
from zero to 5V.
 Arduino Nano comes with a crystal oscillator of frequency 16 MHz. It is used to
produce a clock of precise frequency using constant voltage.
 There is one limitation using Arduino Nano i.e. it doesn't come with DC power
jack, means you can not supply external power source through a battery.
 Flash memory is 16KB or 32KB that all depends on the Atmega board i.e
Atmega168 comes with 16KB of flash memory while Atmega328 comes with a
flash memory of 32KB. Flash memory is used for storing code. The 2KB of
memory out of total flash memory is used for a bootloader.
 This board doesn't use standard USB for connection with a computer, instead, it
comes with Mini USB support.

3.1.2.1 Arduino Nano Pinout:


 Following figure shows the pinout of Arduino Nano Board:

Figure1.4: Arduino Nano Pinout

 Each pin on the Nano board comes with a specific function associated with it.
 We can see the analog pins that can be used as an analog to digital converter where
A4 and A5 pins can also be used for I2C communication. Similarly, there are 14
digital pins, out of which 6 pins are used for generating PWM.
 Vin: It is input power supply voltage to the board when using an external power
source of 7 to 12 V.

Figure1.5: Vin pin on Arduino Nano

 5V: It is a regulated power supply voltage of the board that is used to power the
controller and other components placed on the board.

Figure1.6: 5V Pin on Arduino Nano

 3.3V: This is a minimum voltage generated by the voltage regulator on the board.

Figure1.7: 3.3V Pin on Arduino Nano

 GND: These are the ground pins on the board. There are multiple ground pins on
the board that can be interfaced accordingly when more than one ground pin is
required.

Figure1.8: GND Pins on Arduino Nano


 Reset: Reset pin is added on the board that resets the board. It is very helpful when
running program goes too complex and hangs up the board. LOW value to the reset
pin will reset the controller.

Figure1.9: Reset Pins on Arduino Nano

 Analog Pins: There are 8 analog pins on the board marked as A0 - A7. These
pins are used to measure the analog voltage ranging between 0 to 5V.

Figure1.10: Analog Pins on Arduino Nano

 Rx, Tx: These pins are used for serial communication where Tx represents the
transmission of data while Rx represents the data receiver.

Figure1.11: Rx,Tx Pins on Arduino Nano

 13: This pin is used to turn on the built-in LED.


 AREF: This pin is used as a reference voltage for the input voltage.
 PWM: Six pins 3,5,6,9,10, 11 can be used for providing 8-pit PWM (Pulse Width
Modulation) output. It is a method used for getting analog results with digital
sources.
 SPI: Four pins 10(SS),11(MOSI),12(MISO),13(SCK) are used for SPI (Serial
Peripheral Interface). SPI is an interface bus and mainly used to transfer data
between microcontrollers and other peripherals like sensors, registers, and SD
card.
 External Interrupts: Pin 2 and 3 are used as external interrupts which are used in
case of emergency when we need to stop the main program and call important
instructions at that point. The main program resumes once interrupt instruction is
called and executed.
 I2C: I2C communication is developed using A4 and A5 pins where A4 represents
the serial data line (SDA) which carries the data and A5 represents the serial clock
line (SCL) which is a clock signal, generated by the master device, used for data
synchronization between the devices on an I2C bus.

3.1.2.2 Application of Arduino Nano


Arduino Nano is a very useful device that comes with a wide range of applications and
covers less space as compared to other Arduino board. Breadboard friendly nature makes
it stand out from other board. Following are the main applications of Arduino Nano:
 Arduino Metal Detector
 Real-Time Face Detection
 Medical Instruments
 Industrial Automation
 Android Applications
 GSM Based Projects
 Embedded Systems
 Automation and Robotics
 Home Automation and Defense Systems
 Virtual Reality Applications

3.1.3 16*2 LCD


The experiment used 16x2 LCD as it is economical, and easily programmable.16x2 LCD
means that it is able to display 16 characters per line on two lines. This LCD has two
resisters. Liquid Crystal Display(LCD) is an optical device consisting crystals arranged on
a thin surface. LCD has certain features such as; its size is much less than the regular
screen, light and easy to transport, does not need high voltage of electricity like in there
gular screens, comfortable forth eyes compared to regular screen, their shape is much better
than normal screen, and its quality is higher than normal screens in terms of colors.

Figure 1.12: 16*2 LCD


3.1.3.1 LCD 16×2 Pin Diagram
The 16×2 LCD pinout is shown below:
 Pin1 (Ground/Source Pin): This is a GND pin of display, used to connect the GND
terminal of the microcontroller unit or power source.
 Pin2 (VCC/Source Pin): This is the voltage supply pin of the display, used to
connect the supply pin of the power source.
 Pin3 (V0/VEE/Control Pin): This pin regulates the difference of the display, used
to connect a changeable POT that can supply 0 to 5V.
 Pin4 (Register Select/Control Pin): This pin toggles among command or data
register, used to connect a microcontroller unit pin and obtains either 0 or 1(0 = data
mode, and 1 = command mode).
 Pin5 (Read/Write/Control Pin): This pin toggles the display among the read or
writes operation, and it is connected to a microcontroller unit pin to get either 0 or
1 (0 = Write Operation, and 1 = Read Operation).
 Pin 6 (Enable/Control Pin): This pin should be held high to execute Read/Write
process, and it is connected to the microcontroller unit & constantly held high.
 Pins 7-14 (Data Pins): These pins are used to send data to the display. These pins
are connected in two-wire modes like 4-wire mode and 8-wire mode. In 4-wire
mode, only four pins are connected to the microcontroller unit like 0 to 3, whereas
in 8-wire mode, 8-pins are connected to microcontroller unit like 0 to 7.
 Pin15 (+ve pin of the LED): This pin is connected to +5V
 Pin 16 (-ve pin of the LED): This pin is connected to GND.

Figure1.13: 16*2 LCD Pinout

3.1.3.2 Features of LCD16x2


The features of this LCD mainly include the following:
 The operating voltage of this LCD is 4.7V-5.3V
 It includes two rows where each row can produce 16-characters.
 The utilization of current is 1mA with no backlight
 Every character can be built with a 5×8 pixel box
 The alphanumeric LCDs alphabets & numbers
 Is display can work on two modes like 4-bit & 8-bit
 These are obtainable in Blue & Green Backlight
 It displays a few custom generated characters

3.1.4 GPS
GPS, which stands for Global Positioning System. It is a radio navigation system that
allows land, sea, and airborne users to determine their exact location, velocity, and time 24
hours a day. It works in all weather conditions, anywhere in the world.

The Global Positioning System (GPS) has been developed in order to allow accurate
determination of geographical locations by military and civil users. It is based on the use
of satellites in Earth orbit that transmit information which allow to measure the distance
between the satellites and the user. If the signals from three or more satellites are received,
simple triangulation will make it possible to determine unambiguously the location of the
user.

The three main components are the GPS satellites, the GPS receivers, and the complex
computer software needed to decode the signals and compute the geographical position of
the user.

Figure1.14: GPS

3.1.5 NodeMCU ESP8266


The NodeMCU ESP8266 development board comes with the ESP-12E module containing
ESP8266 chip having Tensilica Xtensa 32-bit LX106 RISC microprocessor. This
microprocessor supports RTOS and operates at 80MHz to 160 MHz adjustable clock
frequency. NodeMCU has 128 KB RAM and 4MB of Flash memory to store data and
programs. Its high processing power with in-built Wi-Fi / Bluetooth and Deep Sleep
Operating features make it ideal for IoT projects. NodeMCU can be powered using Micro
USB jack and VIN pin (External Supply Pin). It supports UART, SPI, and I2C interface.

Figure1.15: NodeMCU ESP8266 Pinout

3.1.5.1 NodeMCU ESP8266 Specifications & Features


 Microcontroller: Tensilica 32-bit RISC CPU Xtensa LX106
 Operating Voltage: 3.3V
 Input Voltage: 7-12V

 Digital I/O Pins (DIO): 16
 Analog Input Pins (ADC): 1
 UARTs: 1
 SPIs: 1
 I2Cs: 1
 Flash Memory: 4 MB
 SRAM: 64 KB
 Clock Speed: 80 MHz
 USB-TTL based on CP2102 is included onboard, Enabling Plug n Play
 PCB Antenna
 Small Sized module to fit smartly inside your IoT projects

3.1.5.2 Applications of NodeMCU


 Prototyping of IoT devices
 Low power battery operated applications
 Network projects
 Projects requiring multiple I/O interfaces with Wi-Fi and Bluetooth
functionalities

3.1.6 LM2596 Buck Converter Module


DC-DC Buck Converter Step Down Module LM2596 Power Supply is a step-down(buck)
switching regulator, capable of driving a 3-A load with excellent line and load regulation.
These devices are available in fixed output voltages of 3.3 V, 5 V, 12 V, and an adjustable
output version. The LM2596 series operates at a switching frequency of 150kHz, thus
allowing smaller sized filter components than what would be required with lower frequency
switching regulators.

Figure1.16: LM2596 Buck Converter Module

This is an LM2596 DC-DC buck converter step-down power module with the high-
precision potentiometer, capable of driving a load up to 3A with high efficiency, which can
work with Freeduino UNO, other mainboards, and basic modules. When the output current
keeps greater than 2.5A (or output power greater than 10W).
This device is internally compensated to minimize the number of external components to
simplify the power supply design. Since LM2596 converter is a switch-mode power supply,
its efficiency is significantly higher in comparison with popular three-terminal linear
regulators, especially with higher input voltage. The LM2596 operates at a switching
frequency of 150 kHz thus allowing smaller sized filter components than what would be
needed with lower frequency switching regulators.

3.1.6.1 LM2596 Buck converter module Specifications


Input voltage 3-40V
Output Voltage 1.5-35v(Adjustable)
-Output Current Rated current is 2A, maximum 3A(Additional heatsink is
required)
Switching Frequency 150KHz
Operating Temperature Industrial grade (-40 to +85)
Conversion efficiency 92%(highest)
Load Regulation +0.5%
Voltage Regulation +0.5%
Dynamic Response Speed 5% 200Us
Dimension 45*20*14mm(L*W*H)
Shipment Weight 0.011kg
Shipment Dimensions 5*4*2 cm
Table-2 LM2596 Buck converter module Specifications

3.1.6.2 Features
 Input voltage:3-40V
 Output voltage:1.5-35V(Adjustable)
 Output current: Rated current is 2A, maximum 3A(Additional heatsink is required)
 Module Properties: non-isolated constant voltage module
 Rectification: non-synchronous rectification
 Short circuit protection: current limiting, since the recovery

3.2 Software Components


3.2.1 Arduino IDE
 Arduino IDE is an open source software that is mainly used for writing and
compiling the code into the Arduino Module.
 It is an official Arduino software, making code compilation too easy that even a
common person with no prior technical knowledge can get their feet wet with the
learning process.
 It is easily available for operating systems like MAC, Windows, Linux and runs on
the Java Platform that comes with inbuilt functions and commands that play a vital
role for debugging, editing and compiling the code in the environment.
 A range of Arduino modules available including Arduino Uno, Arduino Mega,
Arduino Leonardo, Arduino Micro and many more.
 Each of them contains a microcontroller on the board that is actually programmed
and accepts the information in the form of code.
 The main code, also known as a sketch, created on the IDE platform will ultimately
generate a Hex File which is then transferred and uploaded in the controller on the
board.
 The IDE environment mainly contains two basic parts: Editor and Compiler where
former is used for writing the required code and later is used for compiling and
uploading the code into the given Arduino Module.
 This environment supports both C and C++ languages.

3.2.2 MIT App Inventor


MIT App Inventor is a web application integrated development
environment originally provided by Google, and now maintained by the Massachusetts
Institute of Technology (MIT). It allows newcomers to computer programming to create
application software(apps) for operating systems (OS): Android which, as of 8 July 2019,
is in final beta testing. It is free and open-source software released under dual licensing:
a Creative Commons Attribution ShareAlike 3.0 Unported license, and an Apache License
2.0 for the source code.
App Inventor and the other projects are based on and informed by constructionist
learning theories, which emphasize that programming can be a vehicle for engaging
powerful ideas through active learning. As such, it is part of an ongoing movement in
computers and education that began with the work of Seymour Papert and the MIT Logo
Group in the 1960s, and has also manifested itself with Mitchel Resnick's work on Lego
Mindstorms and StarLogo.
IMAGES
Conclusion

This security system endeavours the safety transportation for the school children daily
outing. IN this project, bus safety system for school children has been developed. The
proposed system is designed to track the school bus in real-time with the help of GPS. The
system uses RFID for detecting the child whether boards or leaves the bus. This paper
showed how IoT technologies can be used to make the school transportation system
smarter. A smartphone application can be downloaded by the parents and school
administration which will continuously show the location of the bus and also provide
emergency notification in school administration application. The system provides security
to students effectively and also is more comfortable for parents and institutes.
Appendix

Coding

Arduino Nano

#include <LiquidCrystal.h>
#include <SoftwareSerial.h>

#define swPin A7
#define espTx 2
#define espRx 3
#define rfidPin 13

LiquidCrystal lcd(14, 15, 16, 17, 18, 19);


SoftwareSerial esp(espRx, espTx) ;

unsigned int swValue, idValue, oldRfid;

String rfidString = "" ;


String espString = "" ;
String request = "" ;
char student[6] = {'0', '0', '0', '0', '0'};

void setup() {
Serial.begin(9600);
esp.begin(9600);
lcd.begin(16, 2);
lcd.print("SCL BUS PROJECT");
pinMode(rfidPin, INPUT_PULLUP);
}
void loop() {
Serial.flush();
rfidString = "";

String data;
if (Serial.available() > 0) {
delay(200);
rfidString = "";

for (int i = 0; i < 12; i++) {


data = (char) Serial.read();
rfidString += data;
}
Serial.println(rfidString);

testCard();

Serial.println(idValue); Serial.flush();
if (idValue > 0) {
sendStudent();
}
delay(2000);

lcd.clear();
lcd.print("SCL BUS PROJECT");
}

swValue = analogRead(swPin); //1-2,510,680----790//

if (swValue < 770) {


espString = "REQUEST,";
if (swValue < 10) {
request = "MEDICAL,";
}
if (swValue > 485 && swValue < 550) {
request = "TECHNICAL,";
}
if (swValue > 650 && swValue < 700) {
request = "POLICE,";
}
espString += request ;

esp.flush();
delay(1);
esp.println(espString);

Serial.println(espString);

lcd.clear();
lcd.print(espString);
}

delay(200);
}

void testCard() {
idValue = 0;
if (rfidString.substring(0, 12) == "1800016E4136" && oldRfid != 1) {
idValue = 1; oldRfid = 1;

if (student[1] == '0') {
student[1] = 'U';
}
else {
if (student[1] == 'U') {
student[1] = 'D';
}
else {
if (student[1] == 'D') {
idValue = 0;
}
}
}
}
else {
if (rfidString.substring(0, 12) == "5300B8BFB5E1" && oldRfid != 2) {
idValue = 2; oldRfid = 2;

if (student[2] == '0') {
student[2] = 'U';
}
else {
if (student[2] == 'U') {
student[2] = 'D';
}
else {
if (student[2] == 'D') {
idValue = 0;
}
}
}
}
else {
if (rfidString.substring(0, 12) == "5300B8C01D36" && oldRfid != 3) {
idValue = 3; oldRfid = 3;

if (student[3] == '0') {
student[3] = 'U';
}
else {
if (student[3] == 'U') {
student[3] = 'D';
}
else {
if (student[3] == 'D') {
idValue = 0;
}
}
}
}
else {
if (rfidString.substring(0, 12) == "5300B8C06E45" && oldRfid != 4) {
idValue = 4; oldRfid = 4;

if (student[4] == '0') {
student[4] = 'U';
}
else {
if (student[4] == 'U') {
student[4] = 'D';
}
else {
if (student[4] == 'D') {
idValue = 0;
}
}
}
}
}
}
}
}

void sendStudent() {
espString = "Student," ;
espString += idValue ;
espString += "," ;

if (student[idValue] == 'U') {
espString += "UP";
}

if (student[idValue] == 'D') {
espString += "DOWN"; //espString += student[idValue] ;
}
espString += "," ;

esp.flush();
delay(1);
esp.println(espString);
Serial.println(espString);

lcd.clear();
lcd.print("STUDENT ");
lcd.print(idValue); lcd.setCursor(0, 1);

if (student[idValue] == 'U') {
lcd.print("UP");
}

if (student[idValue] == 'D') {
lcd.print("DOWN");
}
}
NodeMCU ESP8266

#include <TinyGPS.h>
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <FirebaseESP8266.h>

#define WIFI_SSID "project"


#define WIFI_PASSWORD "15081947"
#define FIREBASE_HOST "https://myfiredb-fb2a1-default-rtdb.firebaseio.com/"
#define FIREBASE_AUTH "hCQU7QrC3FZhjjqJdC6iEj4vpOxjvKcWoOJ8boRx"
FirebaseData fbdo ;

TinyGPS gps ;
SoftwareSerial ss(13, 15) ; // gps
SoftwareSerial nano(5, 4) ; // nano

const int led = 16 ;


const int netLed = 2 ;

String lati = "" ;


String lon = "" ;
String sat = "" ;
String spd = "" ;
String studentStatus = "" ;
String requestType = "Normal";

int count = 118 ;


int studentId = 0 ;
boolean gpsStatus = false ;

void setup() {
pinMode(led, OUTPUT); pinMode(netLed, OUTPUT);
Serial.begin(115200); ss.begin(9600); nano.begin(9600);
digitalWrite(led, LOW);

setupWifi();

Serial.println("G.P.S ?");
while (gpsStatus == false) {
getGps(); delay(1000);
digitalWrite(led, !digitalRead(led));
}
digitalWrite(led, HIGH);
updateRequest();
}

void loop() {
count++;
if (WiFi.status() == WL_CONNECTED) {
digitalWrite(netLed, !digitalRead(netLed));
}
else {
digitalWrite(netLed, HIGH);
}

if (count >= 120) {


updateBus();
count = 0;
}

if (nano.available() > 0) {
delay(200);
if (nano.find("Student")) {
studentId = nano.read() ;
studentStatus = nano.readString();

Serial.println(studentId);
Serial.println(studentStatus);

updateServer();

studentId = 0;
studentStatus = "";
nano.flush();
}
if (nano.find("REQUEST")) {
requestType = nano.readString();
Serial.println(requestType);
digitalWrite(led, LOW);
updateRequest();
nano.flush();
digitalWrite(led, HIGH);
}
}

delay(500);
}
void getGps(){
bool newData = false; // For one second we parse GPS data and report some key values
for (unsigned long start = millis(); millis() - start < 1000;){
while (ss.available()){
char c = ss.read();
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}

if (newData){
float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
lati = String(flat,6);
lon = String(flon,6);
sat = String(gps.satellites());
spd = String(gps.f_speed_knots(), 2);

if(sat.toInt() >3){
gpsStatus = true;
digitalWrite(led, LOW);
}else
digitalWrite(led, HIGH);
}
sendToSerial();
}
void updateBus(){
Firebase.setString(fbdo,"/Latitude", lati);
Firebase.setString(fbdo, "/Longitude", lon);
Firebase.setString(fbdo, "/Speed", spd);
Firebase.setString(fbdo, "/Sat", sat);
}
void updateRequest(){
Firebase.setString(fbdo,"/Latitude", lati);
Firebase.setString(fbdo, "/Longitude", lon);
Firebase.setString(fbdo, "/Speed", spd);
Firebase.setString(fbdo, "/Sat", sat);
Firebase.setString(fbdo, "/Req", requestType);
}
void updateSt1Up(){
Firebase.setString(fbdo,"/St1/Up/Latitude", lati);
Firebase.setString(fbdo,"/St1/Up/Longitude", lon);
}
void updateSt1Dn(){
Firebase.setString(fbdo,"/St1/Down/Latitude", lati);
Firebase.setString(fbdo,"/St1/Down/Longitude", lon);
}

void updateSt2Up(){
Firebase.setString(fbdo,"/St2/Up/Latitude", lati);
Firebase.setString(fbdo,"/St2/Up/Longitude", lon);
}
void updateSt2Dn(){
Firebase.setString(fbdo,"/St2/Down/Latitude", lati);
Firebase.setString(fbdo,"/St2/Down/Longitude", lon);
}

void updateSt3Up(){
Firebase.setString(fbdo,"/St3/Up/Latitude", lati);
Firebase.setString(fbdo,"/St3/Up/Longitude", lon);
}
void updateSt3Dn(){
Firebase.setString(fbdo,"/St3/Down/Latitude", lati);
Firebase.setString(fbdo,"/St3/Down/Longitude", lon);
}

void updateSt4Up(){
Firebase.setString(fbdo,"/St4/Up/Latitude", lati);
Firebase.setString(fbdo,"/St4/Up/Longitude", lon);
}
void updateSt4Dn(){
Firebase.setString(fbdo,"/St4/Down/Latitude", lati);
Firebase.setString(fbdo,"/St4/Down/Longitude", lon);
}

void sendToSerial(){
Serial.print("\n\nLAT "); Serial.println(lati);
Serial.print("LON ");Serial.println(lon);
Serial.print("SAT ");Serial.println(sat);
Serial.print("SPEED ");Serial.println(spd);
}

void setupWifi(){
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED){
Serial.print("."); delay(300);
}

Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());
Serial.println();

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
}

void updateServer(){
if(studentId == 1){
if(studentStatus == "UP"){updateSt1Up();}
if(studentStatus == "DOWN"){updateSt1Dn();}
}
if(studentId == 2){
if(studentStatus == "UP"){updateSt2Up();}
if(studentStatus == "DOWN"){updateSt2Dn();}
}
if(studentId == 3){
if(studentStatus == "UP"){updateSt3Up();}
if(studentStatus == "DOWN"){updateSt3Dn();}
}
if(studentId == 4){
if(studentStatus == "UP"){updateSt4Up();}
if(studentStatus == "DOWN"){updateSt4Dn();}
}
}

You might also like