Anda di halaman 1dari 27

School of Engineering & Applied Science

Ahmedabad University

ESD Project Report-2

Car Parking with empty slot


detection

Group No:7
Harsh Shah(201501096)
Meet Patel(201501074)
Motivation
Whenever we visit any place with our family in our favourite car and
when we go to park it, it always becomes cumbersome to find empty
slot to park our car. It becomes difficult to park and manage to drive
our car in such congested area. Instead of this if we have an
automated system which shows that which parking slots are empty
at the entry of a parking place then the problem gets solved. Bingo
!!!

Description
We are going to use Infra Red transmitters and Receivers for each
parking slot. The IR Receivers are connected to AVR microcontroller.
IR rays are obstructed when a car is parked in any parking slot. Thus
AVR will come to know that which slot is empty and which slot is
full.We have two types of gate: Entry gate and Exit gate also system
uses IR sensors to detect vehicles arriving at parking gates to open
the gates automatically on vehicle arrival.The microcontroller is used
to facilitate the working of the entire system.

Outcome
Our system consists of an LCD display that is used to demonstrate as
a parking gate entrance display.
The LCD display displays empty slots to new car arriving at gate of
parking area. If no parking space is available the system does not
open the gate and displays parking full.
If slot is empty system allows car to enter the lot and displays empty
slots where user can park.
Block Diagram

Transformer Rectifier Regulator Microcontroller


LCD

DC
Motor 1

IR Sensors

DC
Motor 2
Components needed
 Atmega32 Microcontroller

 LCD Display

 IR Sensors

 Motors

 Transformer

 Resistors

 Capacitors

 Diodes

Selection Criteria of components


Our Project can also be completed with the help of Atmega328 but in
future if we need to expand the project then we will need more
number of pins then at that time if pins are minimum we need to buy
higher Atmel Series, so to avoid such future problems we are
preferring Atmega32 microcontroller. As we have to display the
empty parking slots on LCD Display we need 16x2 LCD Display.
Datasheets of major components
 Datasheet for Atmega32
Sensors/Actuators interfacing with
ATMega16

1. Digital IR Sensor interfacing with ATMega16


We have used Digital IR sensor to detect whether any
car is parked in a particular parking slot or not. This
digital IR sensor gives digital output i.e. 0 or 1.

Circuit Diagram of Digital IR Sensor


We have used this module and it has main three pins:
GND, Vcc and SIG(output). This circuit gives output as
logic 1 if it detects a object otherwise it gives output as
logic 0.

Circuit Diagram of Interfacing Digital IR


Sensor with ATMega16
U1
1 40
2 PB0 Vcc 39 Digital IR Sensor
3 PB1 PA0 38
4 PB2 PA1 37
5 PB3 PA2 36
6 PB4 PA3 35 SIG
7 PB5 PA4 34
8 PB6 PA5 33
9 PB7 PA6 32 GND
10 RESET PA7 31
11 PD0 PE0 30
12 PD1 PE1 29
13 PD2 PE2 28 Vcc
14 PD3 PC7 27
15 PD4 PC6 26
16 PD5 PC5 25
17 PD6 PC4 24
18 PD7 PC3 23
19 XTAL2 PC2 22
20 XTAL1 PC1 21
GND PC0
ATmega162-DIL40small

In this circuit PA0 is connected to output of


the digital IR sensor and that pin is SIG. PA0 will
read the digital output (logic 1 or logic 0) of the IR
sensor. Other two pins of IR sensor are connected
to GND and Vcc.
Code of Interfacing Digital IR Sensor with
ATMega16
#include<avr/io.h>

int main()
{

DDRC=0xFF; //PORTC as output

DDRA=0x00; //PORTA as input

PORTC= 0x00; //Initializing PORTC

while(1) //Infinite loop


{

if(PINA.b0 == 1) //if PA0 is equal


to 1
{
PORTC.b0 = 1; //turn on LED at PC0
}
else
{
PORTC = 0x00; //turn off LED at PC0
}
}

return 0;
}

Description:

If there is an object in front of IR sensor then value of


PA0 will be 1 and if PA0 is equal to 1 then we are
turning on LED . If PA0 is equal to 0 then turn off the
LED at PORTC. If LED is on then there is some object
and if LED is off then there is no object.
2. LCD Display(16x2) interfacing with ATMega16

Circuit Diagram of Interfacing LCD Display


with ATMega16

We have used 16x2 LCD Display. We have used


PORTB as Data Port and 4-bit mode.
 In 4-bit mode, data is sent in 4-bit format.
 To do this 1st send Higher 4-bit and then send
lower 4-bit of data.
 Only 4 data (D4 - D7) pins of 16x2 of LCD are
connected to PORTB (PB4-PB7) and other
control pins RS (Register select), RW (Read /
write), E (Enable) are connected to pins PB0,
PB1,PB2 respectively. But here we have
grounded RW.

 Code of Interfacing LCD Display with


ATMega16

#define F_CPU 8000000UL /*


Define CPU Frequency e.g. here its 8MHz */
#include <avr/io.h> /*
Include AVR std. library file */
#include <util/delay.h> /*
Include inbuilt defined Delay header file */

#define LCD_Dir DDRB /*


Define LCD data port direction */
#define LCD_Port PORTB /* Define
LCD data port */
#define RS PC0 /*
Define Register Select (data reg./command reg.)
signal pin */
#define EN PC1 /*
Define Enable signal pin */

void LCD_Command( unsigned char cmnd )


{
LCD_Port = (LCD_Port & 0x0F) | (cmnd &
0xF0); /* sending upper nibble */
LCD_Port &= ~ (1<<RS);
/* RS=0, command reg. */
LCD_Port |= (1<<EN);
/* Enable pulse */
_delay_us(1);
LCD_Port &= ~ (1<<EN);

_delay_us(200);

LCD_Port = (LCD_Port & 0x0F) | (cmnd <<


4); /* sending lower nibble */
LCD_Port |= (1<<EN);
_delay_us(1);
LCD_Port &= ~ (1<<EN);
_delay_ms(2);
}

void LCD_Char( unsigned char data )


{
LCD_Port = (LCD_Port & 0x0F) | (data &
0xF0); /* sending upper nibble */
LCD_Port |= (1<<RS);
/* RS=1, data reg. */
LCD_Port|= (1<<EN);
_delay_us(1);
LCD_Port &= ~ (1<<EN);

_delay_us(200);

LCD_Port = (LCD_Port & 0x0F) | (data <<


4); /* sending lower nibble */
LCD_Port |= (1<<EN);
_delay_us(1);
LCD_Port &= ~ (1<<EN);
_delay_ms(2);
}

void LCD_Init (void) /* LCD


Initialize function */
{
_delay_ms(20); /* LCD
Power ON delay always >15ms */
LCD_Dir = 0xFF; /*
Make LCD command port direction as o/p */

LCD_Command(0x02); /*send for 4


bit initialization of LCD */
LCD_Command(0x28); /*use 2
line and initialize
5*7
matrix in (4-bit mode)*/
LCD_Command(0x0c); /*display
on cursor off*/
LCD_Command(0x06);
/*increment cursor (shift cursor to right)*/
LCD_Command(0x01); /*clear
display screen*/
}
void LCD_String (char *str) /* Send
string to LCD function */
{
int i;
for(i=0;str[i]!=0;i++) /* Send
each char of string till the NULL */
{
LCD_Char (str[i]);
}
}

void LCD_String_xy (char row, char pos, char *str)


/* Send string to LCD

with xy position */
{
if (row == 0 && pos<16)
LCD_Command((pos & 0x0F)|0x80);
/* Command of first row

and required position<16 */


else if (row == 1 && pos<16)
LCD_Command((pos & 0x0F)|0xC0);
/* Command of first row and

required position<16 */
LCD_String(str);
/* Call LCD string function */
}

void LCD_Clear()
{
LCD_Command (0x01);
/* clear display */
LCD_Command (0x80);
/* cursor at home position */
}

int main()
{

LCD_Init();
/* initialization of LCD*/

LCD_String("Empty Slots"); /*
write string on 1st line of LCD*/
LCD_Command(0xc0);
/*go to 2nd line*/
LCD_String("No Empty Slots");
/*write string on 2nd line*/

DDRD=0xFF;
PORTD=0xFF;

return 0;
}

 Interfacing circuit
3. DC Motor interfacing with ATMega16

 Motor Specification
We have used 12V DC Motor and its speed is 60 rpm.
This motor is used to open and close the entrance
gate of parking .If there are empty slots then motor
will turn on and open the gate.
We have used L293D motor driver to control the
motor.

 Interfacing Diagram of DC Motor with


ATMega16
 Code
#defie F_CPU
#define F_CPU 8000000UL // 16MHz clock speed
#endif

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
DDRC = 0xFF; //PORTC as Output
while(1)
{
//Rotates Motor in Antilockwise
PORTC = 0x01; //00000001
delay_ms(6000);

//Stops Motor
PORTC = 0x00; //00000000
delay_ms(6000);

//Rotates Motor in Clockwise


PORTC = 0x02; //00000010
delay_ms(6000);

//Stops Motor
PORTC = 0x03; //00000011
delay_ms(6000);
}
}

 As of now we have not included our main logic


part to motor functioning. We have just
checked the motor basic functioning.
Our Final Circuit Diagram
Photo of a Circuit
Final Flowchart of Program

START

Take input from IR


Sensors

Car is at
Entry gate

TRUE FALSE Display Welcome


message on LCD

Any Empty
slot
detected

TRUE FALSE

Do not turn on
Rotate motor in
anticlockwise and motor and display
Display Empty Slots “No Empty Slots” in
in LCD Display LCD Display.

If car is TRUE
not Rotate Motor in
detected clockwise direction

STOP
Final Working Code Of Project
#include <avr/io.h>
#include <avr/interrupt.h>
/* Include AVR std. library file */
#include <util/delay.h>
/* Include inbuilt defined Delay header file */

#define F_CPU 8000000UL


/* Define CPU Frequency e.g. here its 8MHz */

#define LCD_Dir DDRA


/* Define LCD data port direction */
#define LCD_Port PORTA
/* Define LCD data port */
#define RS PA0
/* Define Register Select*/

#define EN PA1
/* Define Enable signal pin */

void controlGate() {

//Rotates Motor in Anticlockwise direction


PORTC = 0x02; //00000001
_delay_ms(1000);

//Stops Motor
while((PIND & 0x04) == 4 )
PORTC = 0x00; //00000000

//Rotates Motor in Clockwise


PORTC = 0x01; //00000010
_delay_ms(1000);

//Stops Motor
PORTC = 0x03; //00000011

int checkEmptySlots() {

int ret =0;

if(!(( (PINB & 0b00000010) == 2) && ((PINB & 0b00000100) == 4)


&&((PINB & 0b00001000) == 8) && ((PINB & 0b00010000) == 16) ) )
ret=1;

return ret;
}

void LCD_Command( unsigned char cmnd )


{
// sending upper nibble
LCD_Port = (LCD_Port & 0x0F) | (cmnd & 0xF0);

// RS=0, command reg.


LCD_Port &= ~ (1<<RS);

/* Enable pulse */
LCD_Port |= (1<<EN);
_delay_us(1);
LCD_Port &= ~ (1<<EN);
_delay_us(200);

// sending lower nibble


LCD_Port = (LCD_Port & 0x0F) | (cmnd << 4);

LCD_Port |= (1<<EN);
_delay_us(1);
LCD_Port &= ~ (1<<EN);
_delay_ms(2);
}

void LCD_Char( unsigned char data )


{
// sending upper nibble
LCD_Port = (LCD_Port & 0x0F) | (data & 0xF0);
/* RS=1, data reg. */
LCD_Port |= (1<<RS);
LCD_Port|= (1<<EN);
_delay_us(1);
LCD_Port &= ~ (1<<EN);

_delay_us(200);
// sending lower nibble
LCD_Port = (LCD_Port & 0x0F) | (data << 4);
LCD_Port |= (1<<EN);
_delay_us(1);
LCD_Port &= ~ (1<<EN);
_delay_ms(2);
}

void LCD_Init() /* LCD Initialize function */


{

/* LCD Power ON delay always >15ms */


_delay_ms(20);

/* Make LCD command port direction as o/p */


LCD_Dir = 0xFF;

/*send for 4 bit initialization of LCD */


LCD_Command(0x02);

LCD_Command(0x28); /*use 2 line and initialize


5*7 matrix in (4-bit mode)*/

LCD_Command(0x0c); /*display on cursor off*/


/*increment cursor (shift cursor to right)*/
LCD_Command(0x06);

LCD_Command(0x01); /*clear display screen*/


}

void LCD_String (char *str) /* Send string to LCD function */


{
int i;
for(i=0;str[i]!=0;i++)
{
/* Send each char of string till the NULL */
LCD_Char (str[i]);
}
}

void LCD_String_xy (char row, char pos, char *str)


{
/* Send string to LCD with xy position */
if (row == 0 && pos<16)
LCD_Command((pos & 0x0F)|0x80);
/* Command of first rozand required position<16 */
else if (row == 1 && pos<16)
LCD_Command((pos & 0x0F)|0xC0);
/* Command of first row and required position<16 */
LCD_String(str);
/* Call LCD string function */
}

void LCD_Clear()
{
/* clear display */
LCD_Command (0x01);

/* cursor at home position */


LCD_Command (0x80);
}

void displayMessage()
{

if( !checkEmptySlots() )
{
LCD_Init();

/* write string on 1st line of LCD*/


LCD_String("No Empty Slot");
/*go to 2nd line*/
LCD_Command(0xc0);

/*write string on 2nd line*/


LCD_String("Come Later");
}
else
{

char a[16]={' ', ' ',' ',' ',' ',' ',' ',' ',' ', ' ','
',' ',' ',' ',' ',' '};
int i;
int index=0;

if( !((PINB & 0b00000010) == 2))


{
a[index]=1+'0';
a[index+1]=',';
index+=2;
}
if( !((PINB & 0b00000100) == 4))
{
a[index]=2+'0';
a[index+1]=',';
index+=2;
}
if( !((PINB & 0b00001000) == 8))
{
a[index]=3+'0';
a[index+1]=',';
index+=2;
}
if( !((PINB & 0b00010000) == 16))
{
a[index]=4+'0';
a[index+1]=',';
index+=2;
}
a[index-1]=' ';
LCD_Init();

/* write string on 1st line of LCD*/


LCD_String("Empty Slots");
/*go to 2nd line*/
LCD_Command(0xc0);

/*write string on 2nd line*/


LCD_String(a);

}
}

void displayDefaultMessage() {

LCD_Init();
/* write string on 1st line of LCD*/
LCD_String("Welcome to");
/*go to 2nd line*/
LCD_Command(0xc0);

/*write string on 2nd line*/


LCD_String("MH Parking Arena");

}
void init_interrupts()
{

cli(); //Disable Global Interrupts


GICR =(1<<INT0); //Set Bit6 of GICR to unmask INT0 interrupt

//Configuring MCUCR for Rising Edge


//interrupt for INT0
MCUCR =(3<<ISC00);

sei();//Enable Global Interrupts


}

ISR (INT0_vect)
{

LCD_Init();
LCD_String("Checking");
LCD_Command(0xc0);
LCD_String("Empty Slots..");
_delay_ms(2000);

displayMessage();
if(checkEmptySlots())
controlGate();
GIFR = (1 << INTF0);
}

int main(void)
{
DDRC = 0xFF; //PORTB as Output
DDRB = 0x00; //PORTB as Output

PORTC = 0x00; //00000000


PORTB = 0x00; //00000000

LCD_Init(); /*
/*initialization of LCD*/

DDRD=0x00;
PORTD=0x00;

init_interrupts();

while(1)
{

displayDefaultMessage();
_delay_ms(2000);
LCD_Init();

/* write string on 1st line of LCD*/


LCD_String(" ");
LCD_Command(0xc0);
LCD_String(" ");

}
return 0;
}

Descriptions of Various Functions of our Code

The controlGate() function :->


This Function handles code to make motor rotate in clockwise
or anticlockwise direction to open and close Gate of the Parking
Arena whenever needed. Here when any car arrives at entry gate
and if there are empty slots available for that car in the parking then
motor will rotate and open the gate and the gate will remain open till
the car gets inside the Parking Arena. As soon as car goes inside the
Parking Arena, motor will rotate in opposite direction and gate will
be closed.

The checkEmptySlots() function :->


This Function will check for available empty slots. If all the
parking slots are reserved and none of them is empty then function
will return 0 and if at least one slot is available for parking then
function will return 1.

The displayDefaultMessage() function :->


This Function will display default message (i.e.”Welcome to MH
Parking Arena”) on the 16*2 LCD display.
The displayMessage() function :->
This Function will display appropriate message on the 16*2 LCD
display according to availability of slots. If there are no empty slots
then it will display “No Empty Slots. Come Later”. On the other hand,
if there are some empty slots , then this function will calculate which
slots are empty and display those slot numbers on the LCD display.

The init_interrupts() function :->


This Function will enable global interrupt as well as interrupt 0
and initialize interrupt 0 to set INTF0 flag whenever there is rising
edge. Actually, we are handling any new car arrival at Entrance Gate
as an interrupt. So whenever any Car arrives at Gate, interrupt 0 will
be enabled and then interrupt 0 sub-routine will get executed. In
that Sub-routine, displayMessage() and controlGate() functions will
be called according to availability of empty slots. At the end of the
sub-routine, Interrupt 0 flag will be cleared.

The LCD_Clear() function :->


This function will clear the LCD display and take the cursor to
home position.

The LCD_Init() function :->


This function will initialize the LCD display. It will send
command for 4-bit initialization of LCD. It will clear the LCD display.

The LCD_String_xy() function :->


This function will send string which is to be displayed on LCD
display to the LCD_String() function with its xy position. It will
manage the display of the string on the first or second row.

The LCD_String() function :->


This function will send the whole string which is to be displayed
on LCD display character by character to the LCD_Char() function till
NULL character arrives.

The LCD_Char() function :->


This function will send the data string to upper nibble and
lower nibble and will enable LCD display at the same time.

Challenges Faced During Implementation


 While testing the whole circuit on breadboard , we
faced some difficulty in implementing the whole
circuit on breadboard.
 We also faced several problems on interfacing LCD
display and displaying the data that we wanted to
display.
 Also, at one time we were getting the 4 bit shifted
data on LCD. We took long time in debugging that
error.
Learning Outcomes
 We learned to interface and use sensor
components like IR sensor, DC motor and 16*2 LCD
display.
 We get to know how real life embedded systems
are designed.
 At one point , our DC motor wasn’t functioning
properly . So we opened DC motor and due to that we
got familiar with inside circuit of DC motor.

Anda mungkin juga menyukai