Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 57

PROFESSIONAL TRAINING REPORT

at
Sathyabama Institute of Science and Technology
(DEEMED TO BE UNIVERSITY)

Submitted in partial fulfillment of the requirements for the award of


Bachelor of Engineering Degree in

Computer Science and Engineering


By

AMARA VENAKATA SAI NYNESH (Reg. No. 3511026)


AVULA PRUDHIV TEJ (Reg. No. 3511059)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SCHOOL OF COMPUTING
SATHYABAMA INSTITUTE OF SCIENCE AND TECHNOLOGY
(DEEMED TO BE UNIVERSITY)
JEPPIAAR NAGAR, RAJIV GANDHI SALAI,
CHENNAI – 600119, TAMILNADU.

MARCH 2019
SATHYABAMA INSTITUTE OF SCIENCE
AND TECHNOLOGY
(DEEMED TO BE UNIVERSITY)
(Established under Section 3 of UGC Act, 1956)
Jeppiaar Nagar, Rajiv Gandhi Salai, Chennai - 600119
www.sathyabamauniversity.ac.in

_________________________________________________________________

SCHOOL OF COMPUTING

BONAFIDE CERTIFICATE

This is to certify that this Professional Training Report is the bonafide work
AMARA VENKATA SAI NYNESH (Reg.No.3511026) who underwent the
professional training in “” under our supervision from May 2018 to June 2018.

Internal Guide
Ms.ISHWARYA M V M.E.,(Ph.D)

Head of the Department


Dr. M.E., Ph.D.,

Submitted for Viva voce Examination held on_____________________

Internal Examiner External Examiner


DECLARATION

I,AMARA VENKATA SAI NYNESH (Reg.No.3511026) hereby declare that the


Professional Training Report on “” done by me under the guidance of guide
Ms.Ishwarya M.V Assistant professor, Dept of CSE at Sathyabama Institute of
Science and Technology is submitted in partial fulfillment of the requirements for
the award of Bachelor of Engineering degree in Computer Science and
Engineering.

DATE:
PLACE:CHENNAI SIGNATURE OF THE CANDIDATE
ACKNOWLEDGEMENT

I am pleased to acknowledge my sincere thanks to Board of Management of


SATHYABAMA for their kind encouragement in doing this project and for completing
it successfully. I am grateful to them .

I convey my thanks to Dean, School of Computing and Dr.


M.E., Ph.D., Head of the Department, Dept. of Computer Science and
Engineering for providing me necessary support and details at the right time during
the progressive reviews.

I would like to express my sincere and deep sense of gratitude to my Project Guide for
her valuable guidance, suggestions and constant encouragement paved way for
the successful completion of my project work.

I wish to express my thanks to all Teaching and Non-teaching staff members of the
Department of Computer Science and Engineering who were helpful in many ways
for the completion of the project.
CHAPTER 1
INTRODUCTION

1.1 INTERNET OF THINGS(IOT)


Internet of Things (IOT) is the networking of physical objects that contain electronics
embedded within their architecture in order to communicate and sense interactions
amongst each other or with respect to the external environment. In the upcoming years,
IoT-based technology will offer advanced levels of services and practically change the
way people lead their daily lives. Advancements in medicine, power, gene therapies,
agriculture, smart cities, and smart homes are just a very few of the categorical
examples where IoT is strongly established. Over 9 billion ‘Things’ (physical objects) are
currently connected to the Internet, as of now. In the near future, this number is
expected to rise to a whopping 20 billion.
There are four main components used in IOT,Low power embedded system – Les
battery consumption, high performance are the inverse factors play a significant role
during the design of electronic system.Cloud Computing – Data collected through IOT
devices is massive and this data has to be stored on reliable storage server. This is
where cloud computing comes into play. The data is processed and learned, giving
more room for us to discover where things like electrical faults/error are within the
system.Big Data – We know that IOT relies on sensors, especially real-time. As these
electronic devices spread throughout every field, their usage is going to trigger a
massive flux of big data.
Networking Connection - In order to communicate, internet connectivity is a must where
each physical object is represented by an IP address. However, there are only a limited
number of addresses available according to the IP naming. Due to the growing number
of devices, this naming system will not be feasible anymore. Therefore, researchers are
looking for another alternative naming system to represent each physical object.
1.2 ARDUINO MEGA
The Mega 2560 is a microcontroller board based on the ATmega2560. It has 54
digital input/output pins (of which 15 can be used as PWM outputs), 16 analog inputs, 4
UARTs (hardware serial ports), a 16 MHz crystal oscillator, a USB connection, a power
jack, an ICSP header, and a reset button. It contains everything needed to support the
microcontroller; simply connect it to a computer with a USB cable or power it with a AC-
to-DC adapter or battery to get started. The Mega 2560 board is compatible with most
shields designed for the Uno and the former boards Duemilanove or Diecimila.
5V & 3.3V - This pin is used to provide output regulated voltage around 5V. This
regulated power supply powers up the controller and other components on the board. It
can be obtained from Vin of the board or USB cable or another regulated 5V voltage
supply. While another voltage regulation is provided by 3.3V pin. Maximum power it can
draw is 50mA.GND - There are 5 ground pins available on the board which makes it
useful when more than one ground pins are required for the project.Reset - This pin is
used to reset the board. Setting this pin to LOW will reset the board.Vin - It is the input
voltage supplied to the board which ranges from 7V to 20V. The voltage provided by the
power jack can be accessed through this pin. However, the output voltage through this
pin to the board will be automatically set up to 5V.Serial Communication - RXD and
TXD are the serial pins used to transmit and receive serial data i.e. Rx represents the
transmission of data while Tx used to receive data. There are four combinations of
these serial pins are used where Serail 0 contains RX(0) and TX(1), Serial 1 contains
TX(18) and RX(19), Serial 2 contains TX(16) and RX(17), and Serial 3 contains TX(14)
and RX(15).External Interrupts - Six pins are used for creating external interrupts i.e
interrupt 0(0), interrupt 1(3), interrupt 2(21), interrupt 3(20), interrupt 4(19), interrupt
5(18). These pins produce interrupts by a number of ways i.e. providing LOW value,
rising or falling edge or changing value to the interrupt pins.LED - This board comes
with built-in LED connected to digital pin 13. HIGH value at this pin will turn the LED on
and LOW value will turn it off. This gives you the change of nursing your programming
skills in real time.AREF - AREF stands for Analog Reference Voltage which is a
reference voltage for analog inputs.Analog Pins - There are 16 analog pins incorporated
on the board labeled as A0 to A15. It is important to note that all these analog pins can
be used as digital I/O pins. Each analog pin comes with 10-bit resolution. These pins
can measure from ground to 5V. However, the upper value can be changed using
AREF and analogReference() function.I2C - Two pins 20 and 21 support I2C
communication where 20 represents SDA (Serial Data Line mainly used for holding the
data) and 21 represents SCL(Serial Clock Line mainly used for providing data
synchronization between the devices)
SPI Communication - SPI stands for Serial Peripheral Interface used for the
transmission of data between the controller and other peripherals components. Four
pins i.e. 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS) are used for SPI communication.

1.3 IR SENSOR
An infrared sensor is an electronic device, that emits in order to sense some
aspects of the surroundings. An IR sensor can measure the heat of an object as well as
detects the motion. These types of sensors measures only infrared radiation, rather
than emitting it that is called as a passive IR sensor. Usually in the infrared spectrum, all
the objects radiate some form of thermal radiations. These types of radiations
are invisible to our eyes, that can be detected by an infrared sensor. The emitter is
simply an IR LED (Light Emitting Diode) and the detector is simply an IR photodiode
which is sensitive to IR light of the same wavelength as that emitted by the IR LED.
When IR light falls on the photodiode, the resistances and these output voltages,
change in proportion to the magnitude of the IR light received.

1.4 MAX 232


The MAX232 is a dual driver/receiver that includes a capacitive voltage generator
to supply RS 232 voltage levels from a single 5v supply. Each receiver converts RS-232
to 5v TTL/CMOS levels. Each driver converts TLL/CMOS input levels into EIA-232
levels. The P3_0 (RX) and P3_1 (TX) pin of controller is connected to the max 232
driver and the TX and RX pin of max 232 is connected to the GSM modem or PC.
In this circuit the microcontroller transmitter pin is connected in the MAX232 T2IN
pin which converts input 5v TTL/CMOS level to RS232 level. Then T2OUT pin is
connected to reviver pin of 9 pin D type serial connector which is directly connected to
PC.In PC the transmitting data is given to R2IN of MAX232 through transmitting pin of 9
pin D type connector which converts the RS232 level to 5v TTL/CMOS level. The
R2OUT pin is connected to receiver pin of the microcontroller. Likewise the data is
transmitted and received between the microcontroller and PC or other device vice
versa.

1.5 RFID TAG


An RFID reader is a device that is used to interrogate an RFID tag. The reader
has an antenna that emits radio waves; the tag responds by sending back its data.
An RFID tag is a microchip combined with an antenna in a compact package; the
packaging is structured to allow the RFID tag to be attached to an object to be tracked.
"RFID" stands for Radio Frequency Identification. The tag's antenna picks up signals
from an RFID reader or scanner and then returns the signal, usually with some
additional data (like a unique serial number or other customized information).
A passive tag is an RFID tag that does not contain a battery; the power is
supplied by the reader. When radio waves from the reader are encountered by a
passive RFID tag, the coiled antenna within the tag forms a magnetic field. The tag
draws power from it, energizing the circuits in the tag. The tag then sends the
information encoded in the tag's memory. The RX and TX pins of RFID reader
connected to Tx and Rx pins of 8051 Microcontroller respectively. Then the reader
senses the data from the Tag and transmits the sensed data to microcontroller via serial
port.
The EM-18 RFID Reader module operating at 125kHz is an inexpensive solution
for your RFID based application. The Reader module comes with an on-chip antenna
and can be powered up with a 5V power supply. Power-up the module and connect the
transmit pin of the module to recieve pin of your microcontroller. Show your card within
the reading distance and the card number is thrown at the output. Optionally the module
can be configured for also a weigand output.
1.6 LCD
LCD technologies allow displays to be much thinner when compared to cathode
ray tube (CRT) technology. The liquid has a unique advantage of having low power
consumption than the LED or cathode ray tube. Liquid crystal display screen works on
the principle of blocking light rather than emitting light.
Liquid crystal display is composed of several layers which include two polarized
panel filters and electrodes. LCD technology is used for displaying the image in
notebook or some other electronic devices like mini computers. Light is projected from a
lens on a layer of liquid crystal. This combination of colored light with the grayscale
image of the crystal (formed as electric current flows through the crystal) forms the
colored image. This image is then displayed on the screen.

1.7 GSM
GSM stands for Global System for Mobiles. This is a world-wide standard for
digital cellular telephony, or as most people know them Digital Mobile Telephones. GSM
was created by the Europeans, and originally meant "Group Special Mobile", but this
didn't translate well, so the now common more globally appealing name was adopted.
GSM is a published standard by ETSI, and has now enjoys widespread implementation
in Europe, Asia, and increasingly America.
The concept of cellular service is the use of low-power transmitters where
frequencies can be reused within a geographic area. The idea of cell-based mobile
radio service was formulated in the United States at Bell Labs in the early 1970s.
However, the Nordic countries were the first to introduce cellular services for
commercial use with the introduction of the Nordic Mobile Telephone (NMT) in 1981.

1.8 TRAFFIC LIGHTS


A traffic light, traffic signal, or stop light is a signaling device positioned at a road
intersection, pedestrian crossing, or other location in order to indicate when it is safe to
drive, ride, or walk using a universal color code. In Malaysia, the traffic lights for
vehicles commonly have three main lights, a red light that means stop, a green light that
mean go and yellow that means ready to stop.
1.9 OUTLINE OF THE PROJECT
This project is all about, to reduce the death rate of the people due to the traffic
congestion in now a days. We are implementing a model that will monitor the traffic and
also manage the traffic level. With the help of IOT we are implementing this, this system
will be placed on the road dividers. In this we are having some components like,
Arduino Mega; IR Sensor; Max232; RFID Tag; LCD; GSM; Traffic Lights. All the
components will connected to the Arduino Mega and we will use Arduino software which
runs with Arduino c language. We will attach the RFID tags to the vehicles like
emergency vehicles will have separate code and the all remaining vehicles will have
other.
Whenever the emergency vehicle RFID tag read by the RFID reader then it will
check in the data base wether it is an emergency vehicle are not if it is emergency
vehicle then it will check the traffic rate through the IR sensors if the traffic rate is high
then the traffic signal of that path will be turned into green and give a way to emergency
vehicle so that the emergency vehicles will reach their location fast. And in this we also
implemented the theft vehicle detection so by this if any one loss their vehicles then it is
easy to find that vehicle by their RFID traced location.

1.10 OBJECTIVES
The main objective of this project is to decrease the travel time of the emergency
vehicles to their destination without any issues and also we will find the theft vehicles in
this by the help of RFID tag. In the theft vehicles scenario we will get the location and
time when did the vehicle crossed that particular sensor.
In any hard situation like, it is difficult to clear the traffic through the above
process we will send a message to the emergency vehicle driver that the traffic is high
in this route
So go in another route. So by this the emergency vehicles won’t struck in the traffic they
can easily go to their destination without any delay.

CHAPTER 2
ALGORITHMS AND METHODS

2.1 GENERAL
Embedded C Programming is the soul of the processor functioning inside each
and every embedded system we come across in our daily life, such as mobile phone,
washing machine, and digital camera. Each processor is associated with an embedded
software. The first and foremost thing is the embedded software that decides
functioning of the embedded system. Embedded C language is most frequently used
to program the microcontroller. In many embedded applications were developed using
assembly level programming. However, they did not provide portability. This
disadvantage was overcome by the advent of various high level languages like C,
Pascal, and COBOL. However, it was the C language that got extensive acceptance for
embedded systems, and it continues to do so. The C code written is more reliable,
scalable, and portable; and in fact, much easier to understand.
The embedded system designers must know about the hardware architecture to
write programs. These programs play prominent role in monitoring and controlling
external devices. They also directly operate and use the internal architecture of the
microcontroller, such as interrupt handling, timers, serial communication and other
available features
C language was developed by Dennis Ritchie in 1969. It is a collection of one or
more functions, and every function is a collection of statements performing a specific
task.
C language is a middle-level language as it supports high-level applications and low-
level applications. Before going into the details of embedded C programming, we should
know about RAM memory organization.
Salient features of the language, C language is a software designed with different
keywords, data types, variables, constants, etc. Embedded C is a generic term given to
a programming language written in C, which is associated with a particular hardware
architecture. Embedded C is an extension to the C language with some additional
header files. These header files may change from controller to controller.
The microcontroller 8051 #include<reg51.h> is used.
2.2 OVERVIEW
The application is developed by using embedded C programing language and
Arduino as platform. Arduino is a platform in which embedded C language is used to
develop IOT applications.
In this we are having a website which will helps in the theft vehicle identification
and in this website we will have date, time also location of the vehicles where it is
identified. By this it is easy to catch theft vehicle faster. And in this project the main thing
is to control the traffic and allow the emergency vehicles faster to the location. Each and
every emergency vehicle will have different number and also normal vehicles will also
have different number which is different from each and everyone.
By this application we can reduce the wait time of the emergency vehicles and
also we can improve India traffic situation to be good. In this project we will use
embedded c language to make hardware work as our need.

2.3 SUMMARY
This project is about monitoring the traffic and managing the traffic through this
IOT application. And also we will find the theft vehicles using this IOT application. So
this is a Multipurpose application which is helpful for emergency vehicles and also at
same time for theft vehicles.
CHAPTER 3
SYSTEM IMPLEMENTATION

3.1 EMBEDDED C PROGRAMING CODE


This is the code for the application that using embedded c programing language.
3.1.1 CODE
#include "LPC214x.h"
#include <stdio.h>
#include <string.h>
#include<math.h>
#define PWMPRESCALE 60
#define clear (1<<18)|(1<<19)|(1<<20)|(1<<21)
#define CLEARSCREEN Lcd_Cmd(0x01)

unsigned char GsmSendMsg(unsigned char *msgStr);


unsigned char GsmSendMsg1(unsigned char *msgStr);
unsigned char Gsmdial(void);
unsigned char Gsmdial1(void);

void initPWM(void);
int temp1,temp2=0,m_length;
unsigned int alc=0;
int distance,speed;
char TX_Buf[150];
char RX_Buf[45];
char control_data[16];
unsigned char B[10];

char Out[15];
char data_len= 0;
int TX_Len= 0;
char RX_Len= 0;
int TX_Max_Len= 0;
char carr= 0;
char k= 0;
char zz[50];
char TX_Enable;
char RX_Enable;
char Ok;
char Send_Enable;
char check,Serial_check;
char count=0;
char carr2;
char data_send;
char data_send1;
char message;
char web_error;
char GPRS_Enable;
char RX_Flag,Rdy,Vechile_Status;
char data_mode;
char data_mode1=0;
unsigned char medicine=0;
char Zigbee_RX_Flag;
volatile static unsigned char Zigbee_Data;
char RX_Buf_Zigbee[4];

/*************** gps***********************/
char Lat[13] = {"0000.0000"};
char Log[13] = {"00000.0000"};
char RX_Buf_GPS[200];
char Serial_RX_BUF[50];
int Serial_len=0;
char Temp_GPS[100];
char Buf[4];
unsigned char RX_Len_GPS=0;
unsigned char RMC_Enable=0;

volatile static unsigned char GPS_Data;


void ADC_Init(void);
void Length_CAL1(void);
void CSB_init(void);
void delay11(unsigned int delay);
void CSB_START1(void);
void ENTinit(void);
unsigned char RX_Enable_GPS;
unsigned char Msg_End;
unsigned char GGA_Enable;
unsigned char Close;
unsigned char shutdown;
void heartrate(void);
void uartdata_send(unsigned char transmit);
void uartstring_send(unsigned char* string) ;
char aa=0;
//unsigned char GsmSendMsg(unsigned char *msgStr);
unsigned char RMC;

//static unsigned char Serial_Moniter(void);

void Lcd_Cmd(int Cmd);


void Lcd_Delay(unsigned int del);
void delay3(unsigned int delay);
void Uart1PutCh (unsigned char ch);
void Uart1PutS( char *str);
void modem_terminate(void);
void action(void);
void Read_data(void);
void HTTP_INIT(void);
char ISR;
char lamp_load;

char LCD_Buf[16];
unsigned char lamp0=0,lamp1=0,lamp2=0,lamp3=0;
static unsigned char v;
unsigned char gps_receiver(void);
void delay(void)
{
unsigned long wait;
for(wait=0;wait<=250000;wait++);

void Length_CAL2(void);

/***************************************************************************************/
void UART1(void) __irq
{
char aa=0;
aa= U1IIR;

if(U1LSR==0x61)
{

Close= U1RBR;
if(Close=='A')
{
lamp0=1;
lamp1=0;
}
if(Close=='B')
{
lamp1=1;
lamp0=0;
}
/* if(Close=='C')
{
lamp2=1;
}
if(Close=='D')
{
lamp3=1;
} */

if(aa&0x04)
{
lamp_load=Close;
RX_Flag=1;
}
if(Close=='~')
{

Rdy=1;
}

else if(Rdy&&(Close!='~'))
{
Vechile_Status=Close;
RX_Flag=1;
Rdy=0;

else if(Close==0x0D)
{
carr++;

}
else if(Close != 0x0D && Close != 0x0A && data_mode==0)
{
RX_Buf[RX_Len] = Close;
RX_Len=RX_Len+1;
if(message==1)
k++;

}
else if( Close==0x0D)
{
carr++;

if(carr==2 && count==0 && data_send==0)


{
RX_Buf[RX_Len] = '\0';
carr=0;
RX_Len=0;
RX_Enable=0;
check=1;
}
if(aa&0x04)
{

Serial_RX_BUF[Serial_len]=0;
if(Close)
{

Serial_check = 1;
Serial_RX_BUF[Serial_len]=Close;
// Serial_len++;
Serial_len=Serial_len+1;
Serial_RX_BUF[Serial_len]=0;
}

}
else if(U1LSR==0x20 )
{

if(TX_Buf[TX_Len]!='\0' && TX_Enable==1)


U1THR=TX_Buf[TX_Len++];
else
{
TX_Len=0;
TX_Enable=0;

}
VICVectAddr = 0x00000000;

int test_len=0;
void UART0_ISR_GPS(void)__irq
{

aa=U0IIR;
GPS_Data= U0RBR;
if(U0LSR==0x60)
{
test_len++;
if(test_len<12)
{
RX_Buf_GPS[RX_Len_GPS] = GPS_Data;
RX_Len_GPS++;

}
else if(test_len==12)
{

Msg_End = 1;
RX_Buf_GPS[RX_Len_GPS]='\0';
RX_Len_GPS=0;
test_len=0;
}

/* if((GPS_Data !=0X0D)&&(GPS_Data != 0X0A))


{
RX_Buf_GPS[RX_Len_GPS] = GPS_Data;
RX_Len_GPS++;
}

else if(GPS_Data==0x0D)
{

Msg_End = 1;
RX_Buf_GPS[RX_Len_GPS]='\0';
RX_Len_GPS=0;
} */

}
VICVectAddr = 0x00000000;
}
/*else if(U0LSR==0x20 )
{

if(TX_Buf[TX_Len]!='\0' && TX_Enable==1)


U0THR=TX_Buf[TX_Len++];
else
{
TX_Len=0;
TX_Enable=0;

VICVectAddr = 0x00000000;
} */

/***************************************************************************************/
void delay_s(unsigned int val){

T0MR3 = val*29498500;
T0EMR &= 0xFFFFFFF7;
T0TC = 0x00000000;
T0TCR =1;
while((T0EMR & 0x00000008)==0);

/***************************************************************************************/
void UART0_Init(void)
{
PINSEL0= 5;
VPBDIV = 2;
U0FCR = 0x07;
U0LCR = 0x83;

U0DLL = 0xc3;
U0DLM = 0x00;
U0LCR = 0x03;
U0IER = 0x03; // tX intr enable
VICIntSelect = 0x00000000;
VICIntEnable = 0x00000040;
VICVectCntl3 = 0x00000020|6;
VICVectAddr3 = (unsigned int) UART0_ISR_GPS;
}

void UART1_Init(void)
{

U1FCR = 0x07;
U1LCR = 0x83;
U1DLL = 0xc3;
U1DLM = 0x00;
U1LCR = 0x03;
U1IER = 0x03; // tX intr enable
PINSEL0|= 0x50000;

VICIntSelect = 0x00000000;
VICIntEnable = 0x00000080;
VICVectCntl2 = 0x00000020|7;
VICVectAddr2 = (unsigned int)UART1;
}

void uartdata_send(unsigned char transmit)


{
U0THR=transmit;
while((U0LSR&0x20)!=0x20);
U0FCR=0x07;
}
void uartstring_send(unsigned char* string)
{
while(*string)
{
U0THR=*string;
while (!(U0LSR & 0x20));
string++;
}
}

void _DelayMs(unsigned int count)


{
volatile unsigned int j,k;
for (j=0;j<count;j++)
{
for (k=0;k<6000;k++)
{
__asm
{
nop;
nop;
}
}
}
}
//********************************************************************************
void Lcd_Init(void)
{
IO1DIR=0X00FF0000;
Lcd_Cmd(0x02);
Lcd_Cmd(0x28);
Lcd_Cmd(0x01);
Lcd_Cmd(0x06);
Lcd_Cmd(0x0d);
Lcd_Cmd(0x0e);
Lcd_Cmd(0x80);
Lcd_Cmd(0xc0);
}
/***************************************************************************************/
void start_tx1(void)
{

TX_Enable = 1;
TX_Len = 1;
TX_Max_Len=strlen(TX_Buf);
U0THR = TX_Buf[0];
while(TX_Enable);
}
/***************************************************************************************/
void Lcd_Cmd(int a)
{
int b,c;
b = a>>4;
IO1CLR =(1<<16);
IO1SET =(1<<17);
IO1CLR = clear;
IO1SET = (b<<18);
delay3(10);
IO1CLR =(1<<17);
delay3(10);

c = a&0x0f;
IO1CLR =(1<<16);
IO1SET =(1<<17);
IO1CLR = clear;
IO1SET = (c<<18);
delay3(10);
IO1CLR =(1<<17);
delay3(10);

/*******************************************************************************************/
void lcd_data(unsigned char a)
{
int b,c;
b = a>>4;
IO1SET =(1<<16);
IO1SET =(1<<17);
IO1CLR = clear;
IO1SET = (b<<18);
delay3(10);
IO1CLR =(1<<17);
delay3(10);

c = a&0x0f;
IO1SET =(1<<16);
IO1SET =(1<<17);
IO1CLR = clear;
IO1SET = (c<<18);
delay3(10);
IO1CLR =(1<<17);
delay3(10);
}
/***************************************************************************************/

void LCD (unsigned char *dat)


{

while(*dat)
{
lcd_data(*dat);
dat++;
}
}

/***************************************************************************************/
void delay3(unsigned int delay3)
{
unsigned int i,j;
for(i=0;i<delay3;i++)
{
for(j=0;j<10000;j++)
{}
}
}

/*******************************************************************************************/
void Start_TX(void)
{
TX_Enable = 1;
TX_Len = 1;
TX_Max_Len=strlen(TX_Buf);
U1THR = TX_Buf[0];
while(TX_Enable);
}
/*******************************************************************************************/

void init_delay(void)
{

//Initial Timer Operate


T0TCR &= 0xFFFFFFFE;
T0TC = 0x00000000; // Timer Start = 0
T0PR = 0x00000000; // Prescale = 0
T0PC = 0x00000000; // Prescale Count = 0

//Initial Timer0 Match Operate


T0MCR &= 0xFFFE; // Disable Interrupt on Match-0 (1111 1111 1111 111x)
T0MCR &= 0xFFFD; // Disable Reset TC on Match-0 (1111 1111 1111 11x1)
T0MCR &= 0xFFFB; // Disable Stop TC on Match-0 (1111 1111 1111 1x11)
T0MCR &= 0xFFF7; // Disable Interrupt on Match-1 (1111 1111 1111 x111)
T0MCR &= 0xFFEF; // Disable Reset TC on Match-1 (1111 1111 111x 1111)
T0MCR &= 0xFFDF; // Disable Stop TC on Match-1 (1111 1111 11x1 1111)
T0MCR &= 0xFFBF; // Disable Interrupt on Match-2 (1111 1111 1x11 1111)
T0MCR &= 0xFF7F; // Disable Reset TC on Match-2 (1111 1111 x111 1111)
T0MCR &= 0xFEFF; // Disable Stop TC on Match-2 (1111 111x 1111 1111)
T0MCR |= 0x0800; // Enable Stop TC on Match-3 (0000 x000 0000 0000)
T0MCR |= 0x0400; // Enable Reset TC on Match-3 (0000 0x00 0000 0000)
T0MCR &= 0xFDFF; // Disable Interrupt on Match-3 (1111 x111 1111 1111)

//Initial Timer0 Interrupt


T0IR &= 0xFE; // Disable MAT0 Interrupt (1111111x)
T0IR &= 0xFD; // Disable MAT1 Interrupt (111111x1)
T0IR &= 0xFB; // Disable MAT2 Interrupt (11111x11)
T0IR &= 0xF7; // Disable MAT3 Interrupt (1111x111)
T0IR &= 0xEF; // Disable CAP0 Interrupt (111x1111)
T0IR &= 0xDF; // Disable CAP1 Interrupt (11x11111)
T0IR &= 0xBF; // Disable CAP2 Interrupt (1x111111)

//Initial Timer0 External Match Register


T0EMR = 0x000; //Set States to 0000 0000 0000 0000
T0EMR |= 0x800; //Set Match0.3 to Go High on Match 10xx xxxx xxxx
T0EMR &= 0xCFF; //Set Match0.2 to Do Nothing on Match xx00 xxxx xxxx
T0EMR &= 0xF3F; //Set Match0.1 to Do Nothing on Match xxxx 00xx xxxx
T0EMR &= 0xFCF; //Set Match0.0 to Do Nothing on Match xxxx xx00 xxxx
}
/*************************************************************************************/
//*********************************/;
//* Delay Function [Microseconds] */;
//*********************************/;
void delay_us(unsigned int val){
T0MR3 = val*29;
T0EMR &= 0xFFFFFFF7;
T0TC = 0x00000000;
T0TCR=1;
while((T0EMR & 0x00000008)==0);
}
//************************************/
//* Delay Function [Miliseconds] */
//************************************/
void delay_ms(unsigned int val){

T0MR3 = val*29498;
T0EMR &= 0xFFFFFFF7;
T0TC = 0x00000000;
T0TCR =1;
while((T0EMR & 0x00000008)==0);
}
//************************************/
//* Delay Function [Seconds] */
//************************************/

void Delay(void)
{
unsigned int count=65535;
while(count--);
count=65535;
while(count--);
count=65535;
while(count--);
count=65535;
while(count--);
}
/***********************************************************************************************/
void EXTINTVectoredIRQ (void) __irq
{

temp2=temp2+1;;

EXTINT = 0x04; //Clear the peripheral interrupt flag


temp1=1;
VICVectAddr = 0x00000000; //Dummy write to signal end of interrupt

} /*****************************************************************************************/
void Init_EINT1(void)
{
PINSEL0 |= (1<<31)|(0<<30); //Enable the EXTINT1 interrupt

EXTMODE = 0X04;

EXTPOLAR = 0X04;

VICVectCntl1 = 0x00000020|16; //select a priority slot for a given interrupt

VICVectAddr1 = (unsigned)EXTINTVectoredIRQ; //pass the address of the IRQ


into the VIC slot

VICIntEnable = 0x00010000; //enable interrupt

}
/*******************************************************************************************/
void dela(unsigned int num)
{
unsigned int i,j;
for(i=0;i<num;i++)
for(j=0;j<65534;j++);
}

/*******************************************************************************************/
void Modem_Config(void)
{

CLEARSCREEN;
Uart1PutS("AT\r"); // this code is to show the data from gprs shield, in order to easily
see the process of how the gprs shield submit a http request, and the following is for
this purpose too.
_DelayMs(100);
Uart1PutS("\n\r");

Uart1PutS("ATE0\r"); // this code is to show the data from gprs shield, in order to
easily see the process of how the gprs shield submit a http request, and the following is
for this purpose too.
_DelayMs(100);
Uart1PutS("\n\r");

Uart1PutS("AT+COPS?\r"); // this code is to show the data from gprs shield, in order
to easily see the process of how the gprs shield submit a http request, and the following
is for this purpose too.
_DelayMs(100);
Uart1PutS("\n\r");
Uart1PutS("AT+CSQ\r"); // this code is to show the data from gprs shield, in order to
easily see the process of how the gprs shield submit a http request, and the following is
for this purpose too.
_DelayMs(100);
Uart1PutS("\n\r");

Uart1PutS("AT+CGATT?\r");
_DelayMs(100);
Uart1PutS("\n\r");

Uart1PutS("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r");
_DelayMs(100);
Uart1PutS("\n\r");

Uart1PutS("AT+SAPBR=3,1,\"APN\",\"CMNET\"\r");
_DelayMs(100);
Uart1PutS("\n\r");

Uart1PutS("AT+SAPBR=1,1\r");
_DelayMs(100);
Uart1PutS("\n\r");

Uart1PutS("AT+DDET=1,1000,0,0\r");
_DelayMs(100);
Uart1PutS("\n\r");
}

void sentto_webpage(char status[],char number[],char area[],char city[])


{
HTTP_INIT();

CLEARSCREEN;
Lcd_Cmd(0x01);
Lcd_Cmd(0x80);
LCD("Accessing web url");
delay3 (500);
sprintf(TX_Buf,"AT+HTTPPARA=\"URL\",\"http://iotclouds.in/swmanageeaswari/
upload.php?bstatus=%s&bnumber=%s&area=%s&city=%s\"\r",status,number,area,city);
Uart1PutS(TX_Buf);
delay_ms(200);
Uart1PutS("\n\r");
delay_ms(200);
CLEARSCREEN;
action();

CLEARSCREEN;
Read_data();

CLEARSCREEN;
// modem_terminate();

void action(void)
{
Uart1PutS("AT+HTTPACTION=0\r");
_DelayMs(1000);
// Uart1PutS("\n\r");
Uart1PutS("\n\r");

void Read_data(void)
{
Uart1PutS("AT+HTTPREAD\r");

Uart1PutS("\n\r");

}
//void modem_terminate(void)
//{
// CLEARSCREEN;
// Lcd_Cmd(0x01);
// Lcd_Cmd(0x80);
// LCD("terminate");
// _DelayMs(100);
// Uart1PutS("AT+HTTPTERM\r");
//
// Uart1PutS("\n\r");
//
//}

void HTTP_INIT(void)
{
Uart1PutS("AT+HTTPINIT\r");

Uart1PutS("\n\r");
}

/*************************************************************************************/

int main(void)
{
char BUF[10];
int value;
int i=0,j=0;
int a,b=0,c,d,e=0,ts,as,t;
int x,x1;
char a1[16];
IO0DIR &= ~(1<<5);

init_delay();
Lcd_Init();
UART0_Init();
UART1_Init();
ADC_Init();

CSB_init();
delay_ms(50);
Init_EINT1();

Modem_Config();
Lcd_Cmd(0x01);
Lcd_Cmd(0x80);
LCD(" Garbage ");
Lcd_Cmd(0xC0);
LCD(" Management ");
delay3(1000);
CLEARSCREEN;

while(1)
{
delay_ms(100);
CSB_START1();
Length_CAL1();

value=m_length;

if(m_length>100)
value=100;

sprintf(BUF,"Distance=%d",value);
Lcd_Cmd(0x80);
LCD(BUF);
delay_ms(100);

// if(m_length==0)
// {
// CLEARSCREEN;
// }

if(m_length>100)
{
CLEARSCREEN;
sprintf(BUF,"Distance=%d",100);
LCD(BUF);
Lcd_Cmd(0xc0);
LCD("Bin is Empty");
delay_ms(300);
CLEARSCREEN ;
a++;
if(a==1)
{
LCD("Updated to Server");
delay_ms(300);
CLEARSCREEN ;
LCD("Accessing web url");
delay_ms(300);
sentto_webpage("Bin_is_Empty","7","Ashok_Nagar","Chennai");

}
CLEARSCREEN;
}
else if(value<=100 && value>=81)
{
Lcd_Cmd(0x01);
sprintf(BUF,"Distance=%d",value);
Lcd_Cmd(0x80);
LCD (BUF);
_DelayMs(500);
t++;
if(t==1)
{
LCD("Updated to Server");
delay_ms(300);
CLEARSCREEN ;
LCD("Accessing web url");
delay_ms(300);
sentto_webpage("Bin_is_Empty","7","Ashok_Nagar","Chennai");

}
CLEARSCREEN;
}
else if(value>=1 && value<=20)
{
b++;
CLEARSCREEN ;
Lcd_Cmd(0xc0);
LCD("Dust Bin Filled");
delay_ms(300);
Lcd_Cmd(0x01);
if(b==1)
{
Lcd_Cmd(0x80);
LCD("Update to Server");
delay_ms(300);
sentto_webpage("Dust_Bin_Filled","7","Ashok_Nagar","Chennai");
Lcd_Cmd(0x01);
Lcd_Cmd(0x80);
LCD("Call To Emp1");
delay_ms(300);
Gsmdial();
Serial_len=0;

for(i=0;i<30;i++)
{

Lcd_Cmd(0x01);
Lcd_Cmd(0x80);
LCD("Calling1...");
delay_ms(100);
Lcd_Cmd(0x01);
if(Serial_RX_BUF[9]=='1'||(strcmp(Serial_RX_BUF,"NO CARRIER")==0))
{

Uart1PutS("ATH\r\n");
delay_ms(50);
GsmSendMsg("Bin No:7");
Lcd_Cmd(0x80);
LCD(" Employee 1");
Lcd_Cmd(0xc0);
LCD("Answered 'YES'");
delay_ms(300);
// Serial_RX_BUF[9]='\0';
ts=1;
break;
}
else if(Serial_RX_BUF[9]=='2'|| (strcmp(Serial_RX_BUF,"NO
CARRIER")==0))
{
Uart1PutS("ATH\r\n");
delay_ms(50);
Lcd_Cmd(0x80);
LCD(" Employee 1");
Lcd_Cmd(0xc0);
LCD("Answered 'NO'");
delay_ms(300);
Lcd_Cmd(0x01);
Lcd_Cmd(0x80);
LCD("Call To Next Emp");
delay_ms(300);
Gsmdial1();
delay_ms(50);
// Serial_RX_BUF[9]='\0';
Serial_len=0;

for(j=0;j<30;j++)
{
LCD("Calling2...");
delay_ms(100);
Lcd_Cmd(0x01);

if(Serial_check==1)
{
Serial_check=0;
if(Serial_RX_BUF[9]=='1')
{
Lcd_Cmd(0x01);
Uart1PutS("ATH\r\n");
delay_ms(50);
GsmSendMsg1("Bin No:7");
LCD(" Employee 2");
Lcd_Cmd(0xc0);
LCD("Answered 'YES'");
delay_ms(300);
i=50;as=1;
break;
}
}

}
// Serial_RX_BUF[9]='\0';

Serial_RX_BUF[0]=='\0';
Lcd_Cmd(0x01);
LCD(Serial_RX_BUF);
delay_ms(300);
Serial_RX_BUF[9]='\0';
delay_ms(300);
CLEARSCREEN ;
}
}
else if(value>=21&&value<=50)
{

CLEARSCREEN;
Lcd_Cmd(0x80);
LCD("Below 80% Filled");
delay_ms(300);
CLEARSCREEN ;

d++;
if(d==1)
{
LCD("Updated to Server");
delay_ms(300);
CLEARSCREEN ;
LCD("Accessing web url");
delay_ms(300);
// Modem_Config();
sentto_webpage("Below_80%_Filled","7","Ashok_Nagar","Chennai");
}

}
else if(value>50&&value<=80)
{

CLEARSCREEN ;
Lcd_Cmd(0x80);
LCD("Below 50% Filled");
delay_ms(300);
CLEARSCREEN ;
e++;
if(e==1)
{
LCD("Updated to Server");
delay_ms(300);
CLEARSCREEN ;
LCD("Accessing web url");
delay_ms(300);
// Modem_Config();
sentto_webpage("Below_50%_Filled","7","Ashok_Nagar","Chennai");
e++;
}
CLEARSCREEN ;
}
if (Msg_End ==1)
{
Msg_End=0;
// Lcd_Cmd(0x01);
delay3(1000);

LCD( RX_Buf_GPS);
if((strcmp(RX_Buf_GPS,"21008B1B902")==0)&&ts==1)
{
Lcd_Cmd(0x01);
Lcd_Cmd(0x80);
LCD("Employee 1 ");
delay_ms(300);

for(i=0;i<10;i++)
{
Lcd_Cmd(0x01);
Lcd_Cmd(0x80);
LCD("Cleaning...");
delay_ms(20);
}

Lcd_Cmd(0x80);
LCD("Bin Cleaned ");
delay_ms(300);
sentto_webpage("Cleaned_by_Employee_1","7","Ashok_Nagar","Chennai");
a=0,b=0,c=0,d=0,e=0,ts=0,t=0;
CSB_START1();
Length_CAL1();
value=m_length;
if(m_length>100)
value=100;
sprintf(BUF,"Distance=%d",value);
Lcd_Cmd(0x80);
LCD(BUF);
}
else if((strcmp(RX_Buf_GPS,"210088FCE5B")==0)&&as==1)
{
Lcd_Cmd(0x01);
Lcd_Cmd(0x80);
LCD("Employee 2 ");
delay_ms(300);

for(i=0;i<10;i++)
{
Lcd_Cmd(0x01);
Lcd_Cmd(0x80);
LCD("Cleaning...");
delay_ms(20);
}

Lcd_Cmd(0x80);
LCD("Bin Cleaned");
delay_ms(300);
sentto_webpage("Cleaned_by_Employee_2","7","Ashok_Nagar","Chennai");
a=0,b=0,c=0,d=0,e=0,as=0,t=0;
CSB_START1();
Length_CAL1();
value=m_length;
if(m_length>100)
value=100;
sprintf(BUF,"Distance=%d",value);
Lcd_Cmd(0x80);
LCD(BUF);
}
}

}
}

/*******************************************************************************************/
void Uart1PutCh (unsigned char ch) // Write character to Serial Port
{
U1THR = ch;
while (!(U1LSR & 0x20));

}
//******************************************************************************

void Uart1PutS( char *str) //A function to send a string on UART1


{
while(*str)
{
U1THR=*str;
while (!(U1LSR & 0x20));
str++;
}
}

void DelayNS (int dly)


{
int i;

for ( ; dly>0; dly--)


for (i=0; i<50000; i++);
}
/*******************************************************************************************/

void ADC_Init(void)
{
PINSEL0 |= ((1<<8)|(1<<9)|(1<<10)|(1<<11)); //AD0.6+AD0.7
PINSEL1 |= ((0<<25)|(1<<24)|(0<<27)|(1<<26)); //AD0.1+AD0.2
VPBDIV = 2;
}

int adc_read(char ch)


{
int i;
long regVal;
AD0CR = 0x00200D00 | (1<<ch);
AD0CR |= 0x01000000; // Start A/D Conversion
if ( regVal & 0x0000FF00 ) /* check OVERRUN error first */
{
regVal = AD0GDR;
}
do
{
i= AD0GDR; // Read A/D Data Register
} while ((i & 0x80000000)!= 0x80000000); // Wait for end of A/D Conversion
AD0CR &= 0xF8FFFFFF; // Stop A/D Conversion
return(i=(i >> 6) & 0x03FF); // bit 6:15 is 10 bit AD value
}

/*************************************************************************************/

void initPWM(void)
{

PINSEL0 |= (1<<15)|(0<<14);
PWMPCR = 0x0;
PWMPR = PWMPRESCALE-1;
PWMMR0 = 10000;
PWMMR2 = 1000;
PWMMCR = (1<<1);
PWMLER = (1<<2) | (1<<0);
PWMPCR = (1<<10);
PWMTCR = (1<<7) ;

PWMTCR = (1<<0) | (1<<3);

void _Delaynn(unsigned int count)


{
volatile unsigned int j,k;
for (j=0;j<count;j++)
{
for (k=0;k<6000;k++)
{
__asm
{
nop;
nop;
}
}
}
}

//unsigned char usrNumStr[]="+918489556191";

unsigned char GsmSendMsg(unsigned char *msgStr)


{
Uart1PutS("AT\r");
_DelayMs(1000);
_DelayMs(1000);
Lcd_Cmd(0x01);
LCD("Done");
Uart1PutS("ATE0\r");
_DelayMs(500);

Lcd_Cmd(0x01);
_DelayMs(500);
LCD("Done");
// For getting sms length during sms read
Uart1PutS("AT+CSDH=1\r");
_DelayMs(500);
Uart1PutS("AT+CMGS=");
Uart1PutCh('"');
Uart1PutS("8056156998");
Uart1PutCh('"');
Uart1PutCh('\r');
_DelayMs(1000);
Uart1PutS(msgStr);
_DelayMs(1000); // timepass
Uart1PutCh(0x1A);
_DelayMs(1000); // timepass
// return (1);
}

unsigned char GsmSendMsg1(unsigned char *msgStr)


{
Uart1PutS("\r");
_DelayMs(1000);
Uart1PutS("AT\r");
_DelayMs(1000);
_DelayMs(1000);
LCD("ok");
Uart1PutS("ATE0\r");
_DelayMs(1000);
_DelayMs(1000);
LCD("ok");

// For getting sms length during sms read


Uart1PutS("AT+CSDH=1\r");
_DelayMs(1000); _DelayMs(1000);
Uart1PutS("AT+CMGS=");
Uart1PutCh('"');
Uart1PutS("9789976072");
Uart1PutCh('"');
Uart1PutCh('\r');
_DelayMs(1000); _DelayMs(1000);
Uart1PutS(msgStr);
_DelayMs(1000); _DelayMs(1000); // timepass
Uart1PutCh(0x1A);
_DelayMs(3000); // timepass

}
unsigned char Gsmdial(void)
{
Uart1PutS("\r");
delay_ms(100);
Uart1PutS("AT\r\n");
delay_ms(100);
LCD("ok");
Uart1PutS("ATE0\r\n");
delay_ms(500);
LCD("ok");
Uart1PutS("ATD 8056156998;\r\n");
delay_ms(100);
return (1);
}

unsigned char Gsmdial1(void)


{
Uart1PutS("\r");
_DelayMs(1000);
Uart1PutS("AT\r\n");
_DelayMs(2000);
LCD("ok");
Uart1PutS("ATE0\r\n");
_DelayMs(2000);
LCD("ok");
Uart1PutS("ATD 9789976072;\r\n");
delay_ms(100);
}

/***************************************************************************************/
void Length_CAL1(void)
{
m_length=((temp1)*700)*0.0003;
m_length=m_length*0.04;
m_length=m_length*0.5;
}

void Length_CAL2(void)
{
m_length=((temp2)*700)*0.0003;
m_length=m_length*0.04;
m_length=m_length*0.5;
}

/*******************************************************************************************/

void Timer1_CapInt(void) __irq


{
T0IR |= 1 << 4;

temp1=T0CR0;

T0CR0=0;

VICVectAddr = 0x00;
}
void ENTinit(void)
{

PINSEL1 |=0X30000003;
PINSEL0 |=0X00001000;
VICIntSelect = 0x00000000;
VICVectCntl0 = 0x20 | 4;
VICVectAddr0 = (long)Timer1_CapInt;
VICIntEnable = 1 << 4;

}
void Time1init(void)
{

T0PR = 9;
T0CCR = (1 << 1)|(1 << 2);
}

void TimeDelay()
{
int i;
for(i=100;i>0;i--) ; ///25KHZ
}
void CSB_init(void)
{
Time1init();
IO0DIR |=1<<21;
ENTinit();

void CSB_PWM_OUT1()
{
IO0SET |=1<<21;
TimeDelay();
IO0CLR |=1<<21;
TimeDelay();
IO0SET |=1<<21;
TimeDelay();
IO0CLR |=1<<21;
TimeDelay();
IO0SET |=1<<21;
TimeDelay();
IO0CLR |=1<<21;
TimeDelay();
IO0SET |=1<<21;
TimeDelay();
IO0CLR |=1<<21;
TimeDelay();
}
void CSB_START1(void)
{
T0TC=0;
CSB_PWM_OUT1();
VICIntEnable = 1 << 4;
T0TCR = 0x2;
T0TCR=0x01;
}
void delay11(unsigned int delay)
{
unsigned int i,j;
for(i=0;i<delay;i++)
{
for(j=0;j<65535;j++)
{}
}
}

/*ultrasonic1---->trig p0.21
echo---> p0.30

*/

/************************************************************************************

CHAPTER 4
CONCLUSION AND FUTURE WORK

4.1 CONCLUSION
This survey has been performed for collecting the details of Smart Waste Collection
System based on IoT and to find out effective methods which are useful for providing
hygiene environment in cities. As the level of garbage in the bins crossed the threshold,
it will be informed to the corresponding authority, if it was found ignored then the details
will be forwarded to the higher authority to take necessary actions. Thus a hygiene and
clean environment can be provided. This survey helps in identifying all possible smart
waste collection methods that can be implemented to make city clean.

This proposed system assures the collection of garbage soon when the garbage level
reaches its maximum level. The system will thus provide accurate reports, increasing
the efficiency of the system. The real-time monitoring of the garbage level with the help
of sensors and wireless communication will reduce the total number of trips required of
GCV and thus, will reduce the total expenditure associated with the garbage collection.
Thus, the dustbins will be cleared as and when filled, giving way to cleaner city, better
infrastructure and increased hygiene.

4.2 FUTURE WORK


The management of solid waste is an important aspect in which everyone needs to put
responsive and immediate action without any delay. For a future prospective web server
can also build for effective graphic user interface of a system and controlling action. All
bins are equipped with GPRS enabled embedded system. Central servers receive
information from bins. It can store all necessary information such as bin level history,
number of dispatched waste collecting vehicles etc. Thus based on prediction of
collected data on bin level, it enables optimization of number of vehicles used. An
application for smartphone will be developed, through which citizens can report to
municipal office (fill level, photo, comment, etc.). When all such a technology integrated
together a new way of waste management system emerges. This will led to reduction in
amount of garbage in city and cost of transportation and realized clean and convenient
environment.

You might also like