You are on page 1of 25

Ajman University

College of Engineering and Information Technology


Department of Electrical and Computer Engineering

COE 349: Embedded Systems


COURSE PROJECT: Road Tech

Name: Khadija Muhammad ID: 201811672

Theory Instructor: Dr. Khalid Ammar


Lab Instructor: Engr. Wessam Shehieb

Comments & Marks:

________________________________________________________________________________________________________

_______________________________________________________________________________________________________
Embedded Systems
COE349
College: Engineering and Information Technology
Department: Electrical and Computer Engineering

Dr. Khalid Ammar

ROAD TECH.
ABSTRACT
The project name gives up the idea of the project. In this project we
implement road technology such as radar sensors, pedestrian
crossing as well as traffic signal using microcontrollers.

Done by:
❖Khadija Muhammad 201811672

COURSE PROJECT: ROAD TECH 2


Contents
ABSTRACT .........................................................................................................................................................................................2
INTRODUCTION .................................................................................................................................................................................4
WHAT ARE MICROCONTROLLERS? ................................................................................................................................................................. 4
ADVANTAGES AND DISADVANTAGES OF MICROCONTROLLERS ............................................................................................................................. 4
PIC16F887 MICROCONTROLLER .................................................................................................................................................................. 5
PIC16F887 PINOUT................................................................................................................................................................................... 5
OBJECTIVE .........................................................................................................................................................................................6
WORKING .............................................................................................................................................................................................. 6
TRAFFIC SIGNAL ................................................................................................................................................................................. 6
PEDESTRIAN ...................................................................................................................................................................................... 6
RADAR ............................................................................................................................................................................................... 6
THEORITICAL BACKGROUND .............................................................................................................................................................7
PUSH BUTTON:........................................................................................................................................................................................... 7
TRAFFIC SIGNAL: ........................................................................................................................................................................................ 7
LED – LIGHT EMITTING DIODE:..................................................................................................................................................................... 7
7-SEGMENT DISPLAY:.................................................................................................................................................................................. 8
4511 Decoders ................................................................................................................................................................................... 8
LCD - LIQUID CRYSTAL DISPLAY: ................................................................................................................................................................... 8
CUSTOM CHARACTERS:................................................................................................................................................................................ 9
POTENTIOMETER: ....................................................................................................................................................................................... 9
EXTERNAL INTERRUPT:................................................................................................................................................................................. 9
ADC – ANALOG TO DIGITAL CONVERTER: ..................................................................................................................................................... 10
ADC in PIC16F887 ............................................................................................................................................................................ 10
Registers associated with ADC ........................................................................................................................................................ 10
PROCEDURE .................................................................................................................................................................................... 11
CODE: MIKRO C PRO ........................................................................................................................................................................ 12
RADAR.H............................................................................................................................................................................................... 12
PEDESTRIAN.H ...................................................................................................................................................................................... 14
TRAFFICSIGNAL.C ..................................................................................................................................................................................... 15
SIMULATION CIRCUIT ...................................................................................................................................................................... 18
SIMULATION OUTPUT ..................................................................................................................................................................... 19
CONCLUSION ................................................................................................................................................................................... 25
REFERENCES .................................................................................................................................................................................... 25

COURSE PROJECT: ROAD TECH 3


INTRODUCTION
This Project is simulation based only. It is done using Proteus 8 professional (Schematic design) and MikroC Pro (coding).
The project is based on the use of Microcontrollers and how can we design the circuit according to our use and preference.
What are Microcontrollers?
A Microcontroller (MCU) is a small computer
made on a single metal-oxide-semiconductor IC
chip. (wikipedia, n.d.) They are used in products
that needs to be controlled automatically. They
have vast use in electronics market. They are
usually embedded inside the devices to control
the features and actions of the product;
therefore, they are also called embedded
controllers (IntervalZero, n.d.). One specific
program is dedicated to a single task.
Microcontrollers contains memory, CPU, I/O all
integrated into one chip. They have internal
controlling bus for RAM, ROM, and other
peripherals (guru99, n.d.). Microcontrollers can
be reprogrammed for a different program, they are cost efficient, and energy efficient (Electrical Academia,
n.d.). The processing speed of microcontrollers can be as low as 31kHz and as high as 50MHz.
In the simulation we have used PIC microcontroller PIC16F887.
PIC is a family of microcontrollers made by Microchip Technology.

Advantages and Disadvantages of Microcontrollers


As with any device of system approach their various advantages and disadvantages of microcontrollers need to
be considered when undertaking a new design

ADVANTAGES DISADVANTAGES
• Lower cost because many • Less flexibility because all
elements of the processor are components are integrated into
contained within the one chip the one chip.
resulting in lower chip cost and • Limited performance because the
board cost. size of memory is limited by what
• Lower power consumption. can be accommodated on the
• Integrating all components onto chip.
one chip enables processor to be • MCUs tend to be application
optimized for a given application. specific so the choice may be
limited.

COURSE PROJECT: ROAD TECH 4


PIC16F887 Microcontroller

The PIC16F887 is an 8-bit microcontroller from Microchip. The 40-pin IC


has 14 Channel 10-bit ADC making it suitable for applications which
require more ADC inputs. The IC also has 2 Comparators, 2 Timers (8-bit
and 16-bit) and supports SPI, I2C and UART communication protocols.
It can operate at a speed of up to 20MHz with external oscillator and
has precision internal oscillator tunable between 8MHz to 32kHz. The IC
supports nanowatt technology allowing it to consume very low power
and operate in Power-Saving sleep mode (guru99, n.d.). It also has a
wide operating voltage from 2V to 5.5V making it suitable for battery
powered applications.

PIC16F887 Pinout
Getting a hold of Pinout and Pin descriptions is mandatory to check the working of each pin on this tiny chip. If
you are a newbie or an expert, you need to know the function associated with each pin for a better
understanding of the chip.

COURSE PROJECT: ROAD TECH 5


OBJECTIVE
This project is about the working of pedestrian crossing using external interrupt, radar sensors using AD
converter and Traffic Signal. They all work together and work in light to the real-life application.

WORKING
It is a two-way road where either the car can go straight or make a U-turn. There is radar which detects the
speed of the car and displays the speed. It also had pedestrian crossing on both the sides of the roads.

TRAFFIC SIGNAL
• By default, Signal 1 is Green, and Signal 2 is Red. The timer counts down from 9 to 0.
• Both the Signals turn Yellow, and the timer starts counting down from 3 to 0.
• Then Signal 2 becomes Green, and Signal 1 becomes Red. The timer counts down from 9 to 0.
• And this repeats continuously.

PEDESTRIAN
• By default, both the Pedestrian crossing are RED (STOP).

• When Pedestrian button is pushed while Signal 1 is Green, and Signal 2 is Red.
o Both the Signals will turn into Yellow countdown of 3 seconds will start. While the pedestrian
lights are still RED.
o After the countdown both the signals will become Red, and the pedestrian light will turn into
GREEN (WALK) for 9 seconds.
o After the countdown of pedestrian is over. The Pedestrian lights will turn to RED (STOP).
o Both the Signals will be Yellow for 3 seconds.
o Now Signal 1 is Red, and Signal 2 is Green.

• When Pedestrian button is pushed while Signal 1 is Red, and Signal 2 is Green.
o Both the Signals will turn into Yellow countdown of 3 seconds will start. While the pedestrian
lights are still RED.
o After the countdown both the signals will become Red, and the pedestrian light will turn into
GREEN (WALK) for 9 seconds.
o After the countdown of pedestrian is over. The Pedestrian lights will turn to RED (STOP).
o Both the Signals will be Yellow for 3 seconds.
o Now Signal 1 is Green, and Signal 2 is Red.

RADAR
• When the car is under speed of 100 km/hr. The radar sensor will sense it and display the speed of the car
and Smiley emoticon on the radar display.
• When the car is over the speed limit of 100 km/hr. The radar sensor will sense it and display the speed of
the car with a sad emoticon on the radar display. And displays a message “Please Slow Down”.

COURSE PROJECT: ROAD TECH 6


THEORITICAL BACKGROUND
Push button:
• Mechanical switch used for control.
• Switches open (OFF) and close (ON) the contact between two ends of a line.
• Used as input device.
• Interface in Pull-Up or Pull-Down mode is better than direct interface.

• The pull-up mode is used for MCLEAR which will work in active low mode.
• When the button is pushed. The Microcontroller is cleared.

The pull-down is used for Pedestrian which will work in Active high mode for interrupts. •
When the button is pushed. Appropriate action is taken. •

Traffic Signal:
• Signaling devices that control the flow of traffic.
• Red: stop (disallow traffic from going on), yellow: get
ready to stop, green: go (allow traffic to go).

LED – Light Emitting Diode:


• Light emitting diode.
• Emits light when current passes through it.
• Semiconductor diode.
• Allow current to flow in forward direction.

ADVANTAGES DISADVANTAGES
• Small. • Consume power.
• Intensity of light depend • Cost is high.
on current flow.
• High efficiency.

COURSE PROJECT: ROAD TECH 7


7-Segment Display:
• Consists of seven LEDs in a rectangle form.
• Each of the LED is called segment.
• When a segment is on it form part of a number.
• DP: 8th LED, indicate a decimal point when more than one display is connected.
• Total 4 pins are used to connect the 7-Segment display through 4511 decoders.

4511 Decoders
• BCD decoder.
• Used to convert a BCD to an equivalent decimal number.
• Takes a binary number as input then display it on 7-segment display using
its outputs.
• Reduce the controller pins by using only 4 lines to drive the 7-segment.

LCD - Liquid Crystal Display:


For the LCD 16x2 display is used in 4-bit mode. Only 4 data pins are
connected to the microcontroller, other 4 data pins are grounded. VEE
is connected to potentiometer to change the contrast; the value of
the potentiometer can be changed to change the voltage between Vcc
and Vee which changes the contrast of the LCD screen.

• GND Pin: Ground pin.


• VCC Pin: Voltage supply pin.
• VEE Pin: Regulates the difference and changes the contrast of
LCD.
• RS Pin: Toggles between command or data register.
• RW Pin: Toggles the display among the read or writes
operation, obtain either 0 = Write, and 1 = Read.
• EN Pin: should be held high to execute Read/Write process.
• D0 - D7 Pins: used to send data to the display.
• LED+ : connected to +5V.
• LED- : connected to GND.

COURSE PROJECT: ROAD TECH 8


Custom Characters:
• To display must generate a pattern and then save it to the
CGRAM.
• CGRAM: character generator RAM, stores the custom
character once declared in the code.
• Each character is 8 bytes.
• Each character is 5x8 matrix.
• select which pixel(dot) should go high (1) and which stay low
(0).

Potentiometer:
• Variable resistor.
• Resistance manually changed to control the flow of
current.
• Work: when varying the position of the sliding contact.

External Interrupt:
• Special events that need immediate attention, it stops the microcontroller from running to do task.
• Interrupt triggered by changing of pin RB0 of PORTB.
• Change happens in two cases:
o Negative edge: high to low transition.
o Positive edge: low to high transition.
• Registers used:
• INTCON:

• GIE: global interrupt enable. Set to 1 to enable all unmasked interrupts.


• INTE: RB0/INT external interrupt enable. Set to 1 to enable all INT interrupts.
• INTF: INT External Interrupt FLAG bit) is used to check if external interrupt has occurred. When INTF=0, it
means there was no external interrupt. When INTF=1 , it means there was External interrupt. After an external
interrupt occers it should be cleared immediately before returning to rest of the program.

COURSE PROJECT: ROAD TECH 9


ADC – Analog to Digital Converter:
• Common way to read data from real world.
• Almost every known sensor or transducer produce analog
voltage.
• Every type of ADC has its own speed and resolution.

ADC in PIC16F887
• Uses 10-bit ADC module.
• Max count obtained = 210 = 1024.
• Consists of 14 pins/channels from AN0 to AN13.
• Reference voltage is software selectable, so, it can be generated internally or provided externally.
• The interrupt can be enabled or disabled, it happens when 1 full conversion is done.

Registers associated with ADC


• TRIS: data direction registers, 0 = output, 1 = input.
• ANSEL- ANSELH: used to select the channel for the analog input.

• ADCON0: A/D control register 0.

o We enable the inbuilt ADC that is present in the microcontroller by setting the least significant bit of
ADCON0 to ‘1’.

• ADCON1: A/D control register 1.

o To select the V+ref and V-ref we use ADCON1 register. Where the reference voltages are by
default set to Vss and Vdd.
o ADFM = 0 : left justified result, ADFM=1 : right justified result.

• ADRESH – ADRESL: 8-bit register, used to store the conversion result.

COURSE PROJECT: ROAD TECH 10


PROCEDURE
1. We connect a PIC16F887 microcontroller to an active low switch at Pin1 (RE3) for MCLEAR. Which will help
us reset the microcontroller when needed.
2. (RA1) is connected to POT-hg that will act as Radar sensor in the simulation.
3. (RB2) to (RB7) of the microcontroller is connected to LCD that will tell us about the car speed and display
message to slow down when required.
4. (VSS, RW, D0, D1, D2, D3) of the LCD are connected to the ground.
5. (RA2) & (RA3) are connected to Green LED and Red Led respectively for Pedestrian indication to walk or stop
walking.
6. (RB0) is connected to active high switch that is used as external interrupt for the pedestrian crossing.
7. (RC0 to RC2) & (RC3 to RC5) of the microcontroller is connected to the two Traffic signals respectively.
8. (RD0 to RD3) are connected to a 7-Segment Decoder (4511) Pins 7, 1, 2, 6 respectively.
9. Pin 3 (LT) and Pin4 (BI) of the decoder is active low therefore they are connected to a power supply.
10. Pin5 (LE/STB’) of the decoder is connected ground.
11. Pin9 to pin15 of the decoder is connected to the 7-Segment Display.

COURSE PROJECT: ROAD TECH 11


CODE: Mikro C Pro
RADAR.h
//Header file for the application of radar.
void Lcd_Init();
sbit LCD_RS at RB2_bit;
sbit LCD_EN at RB3_bit;
sbit LCD_D4 at RB4_bit;
sbit LCD_D5 at RB5_bit;
sbit LCD_D6 at RB6_bit;
sbit LCD_D7 at RB7_bit;
sbit LCD_RS_Direction at TRISB2_bit;
sbit LCD_EN_Direction at TRISB3_bit;
sbit LCD_D4_Direction at TRISB4_bit;
sbit LCD_D5_Direction at TRISB5_bit;
sbit LCD_D6_Direction at TRISB6_bit;
sbit LCD_D7_Direction at TRISB7_bit;
//---------------------------------------------------------------------------------------
char J;
const char character1[] = {0,10,0,14,17,0,0,0}; //SAD EMOJI
void CustomChar1(char pos_row, char pos_char)
{
Lcd_Cmd(64);
for (J = 0; J<=7; J++) Lcd_Chr_CP(character1[J]);
Lcd_Cmd(_LCD_RETURN_HOME);
Lcd_Chr(pos_row, pos_char, 0);
}
//---------------------------------------------------------------------------------------
const char character2[] = {0,10,0,17,14,0,0,0}; //SMILEY
void CustomChar2(char pos_row, char pos_char)
{
Lcd_Cmd(64);
for (J = 0; J<=7; J++) Lcd_Chr_CP(character2[J]);
Lcd_Cmd(_LCD_RETURN_HOME);
Lcd_Chr(pos_row, pos_char, 0);
}
//---------------------------------------------------------------------------------------
unsigned long speed;
// unsigned long scale_speed;
unsigned long LIMIT=100;
char S_ch[10];
int i,K;
//---------------------------------------------------------------------------------------
void radar()
{
Lcd_Cmd(_LCD_CLEAR);
speed=ADC_Read(1); //READS AC SENSOR
speed = speed/5;

COURSE PROJECT: ROAD TECH 12


if(speed>=LIMIT) //SPEED OVER THE LIMIT
{
LongToStr(speed,S_ch); //CONVERT TO STRING FOR DISPLAY
for(K=0;K<=9;K++) //FIXING DISPLAY OUTPUT
{
S_ch[K]=S_ch[K+7];
}
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Speed: ");
Lcd_Out(1,8,S_ch); //DISPLAY SPEED
CustomChar1(1,13); //DISPLAY SPEED
Lcd_Out(2,1,"Please Slow Down");
return;
}

if(speed<LIMIT) // NORMAL SPEED


{
LongToStr(speed,S_ch); //CONVERT TO STRING FOR DISPLAY
for(K=0;K<=9;K++) //FIXING DISPLAY OUTPUT
{
S_ch[K]=S_ch[K+7];
}

Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,"Speed: ");
Lcd_Out(1,8,S_ch); //DISPLAY SPEED
CustomChar2(1,13); //DISPLAY SMILEY
return;
}
}
//---------------------------------------------------------------------------------------

COURSE PROJECT: ROAD TECH 13


PEDESTRIAN.h
//This header file has function for pedestrian and interrupt function
//TRAFFIC SIGNAL CONNECTION MODULE
sbit led_Green1 at RC2_bit;
sbit led_Yellow1 at RC1_bit;
sbit led_Red1 at RC0_bit;
sbit led_Green2 at RC5_bit;
sbit led_Yellow2 at RC4_bit;
sbit led_Red2 at RC3_bit;

//---------------------------------------------------------------------------------------
int L,flag=0;
void pedestrian()
{
for(i= 3;i>=0;i--) //Yellow light for both signals
{
PORTD=i;
led_Green1=0;
led_Green2=0;
led_Red1=0; led_Red2=0;
led_Yellow2=1;led_Yellow1=1;
Delay_ms(600);
radar();
}
PORTA.F3=0;
for(L=9; L>=0;L--) //both signals are red for pedestrian to cross
{
PORTD=L;
led_Green1=0;
led_Green2=0;
led_Yellow1=0;
led_Yellow2=0;
led_Red1=1; led_Red2=1;
Delay_ms(600);
radar();
PORTA.F2=1;
}
flag=0; // clear flag
PORTA.F3=1; //switch on red light for pedestrian
PORTA.F2=0; //swith off green light
}
//---------------------------------------------------------------------------------------
void interrupt ()
{
if(INTCON.INTF==1)
flag=1; //set flag
INTCON.INTF=0;
}

COURSE PROJECT: ROAD TECH 14


TrafficSignal.c
//Main Program
#include"RADAR.h" //user defined header file
#include"PEDESTRIAN.h" // user defined header file

//---------------------------------------------------------------------------------------

void main()
{
ANSEL=0X02; //CHANNEL 1
ANSELH=0;
ADCON0=0x01; //ENABLE ADC
TRISA.F1=1; //SENSOR INPUT AT CHANNEL 1
ADCON1.F4=0;
ADCON0.F5=0;

TRISA.F2=TRISA.F3=0;
INTCON.GIE=1; //global interrupt is enabled
INTCON.INTE=1;
INTCON.INTF=0; //interrupt flag is set to 0

PORTA=PORTD=PORTB=PORTC=0; // Clear PORT A B C D


TRISD = 0; // Configure PORTD and PORT C as output
TRISC=0;

Lcd_Init(); //initialize LCD


Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Turn off cursor

do{
PORTA.F3=1; //Red light for pedestrian is switched on
//indicating to stop walking
radar(); // call radar function

// PHASE1 Signal 1 is green signal 2 is red

PORTC=0;
for(i=9;i>=0;i--) //Counter for the signals
{
PORTD=i; //display count to the 7 seg
led_Green1=1; led_Red2=1;
Delay_ms(800);
radar();
if(flag==1) // we check if pedestrian wants to cross or not
{
pedestrian(); // we call pedestrian function
break;
}

COURSE PROJECT: ROAD TECH 15


}

//PHASE2

PORTC=0;

for(i= 3;i>=0;i--) //Yellow light for both signals //Counter for the signals
{
PORTD=i;
led_Yellow2=1;led_Yellow1=1;
Delay_ms(600);
radar();

if(flag==1)
{
pedestrian();
i=3;
}
}

//PHASE3 Signal 2 is green signal 1 is red

PORTC=0;

for(i=9;i>=0;i--) //Counter for the signals


{
PORTD=i;
led_Green2=1; led_Red1=1;
Delay_ms(600);
radar();
if(flag==1)
{
pedestrian();
break;
}
}

//PHASE4

PORTC=0;

for(i=3;i>=0;i--) //Yellow light for both signals //Counter for the signals
{
PORTD=i;
led_Yellow2=1;led_Yellow1=1;
Delay_ms(600);
radar();
if(flag==1)
{

COURSE PROJECT: ROAD TECH 16


pedestrian();
i=3;
}
}

}while(1); // infinite loop

} // end of program

//---------------------------------------------------------------------------------------

COURSE PROJECT: ROAD TECH 17


SIMULATION CIRCUIT

COURSE PROJECT: ROAD TECH 18


SIMULATION OUTPUT

By default, signal 1 is GREEN and signal 2 is RED. The speed is less than 100 km/hr. Therefore,
only speed is displayed and a smiley emoticon. Pedestrian is not enabled. The countdown
starts at 9.

COURSE PROJECT: ROAD TECH 19


After the first countdown. Both the signals turn into Yellow and counts down from 3 to 0.
Pedestrian is still not enabled. And speed remains the same since no change is made to speed
yet.

COURSE PROJECT: ROAD TECH 20


After the second countdown of Yellow lights. Signal 1 turns RED now and Signal 2 turns Green.
Pedestrian is still not enabled. And speed remains the same since no change is made to speed
yet.

COURSE PROJECT: ROAD TECH 21


When pedestrian button is pushed, both the signals turn YELLOW and a countdown of 3 starts.
While the Pedestrian lights are still RED (STOP).

COURSE PROJECT: ROAD TECH 22


After the countdown both the signals turn RED. And both the pedestrian lights Turn Green
asking the pedestrians to start Walking for 9 seconds. The
Speed is still not changed yet.

COURSE PROJECT: ROAD TECH 23


When the radar sensors sense speed over 100 km/hr. It displays the speed and a sad emoticon
and asks the driver to Slow Down.

COURSE PROJECT: ROAD TECH 24


CONCLUSION
Thus, working of traffic signal, pedestrian and radar system was implemented using one microcontroller. All the
three-application worked together simultaneously. C language for programming. It can further be improved by
using two digit 7-segment display. And 4-way traffic signal can be implemented.

References
• https://www.elprocus.com/lcd-16x2-pin-configuration-and-its-working/
• https://www.electronicsforu.com/technology-trends/learn-electronics/16x2-lcd-pinout-diagram
• https://circuitdigest.com/microcontroller-projects/custom-characters-on-lcd-using-pic16f877a
• https://circuitglobe.com/light-emitting-diode-led.html
• https://www.electronics-tutorials.ws/diode/diode_8.html
• https://www.electrical4u.com/potentiometer/
• https://www.electrical4u.com/what-is-resistor/
• https://www.electronics-tutorials.ws/blog/7-segment-display-tutorial.html
• http://lednique.com/display-technology/7-segment-display-basics/
• https://www.elprocus.com/bcd-to-seven-segment-display-decoder-theory/
• https://www.build-electronic-circuits.com/4000-series-integrated-circuits/ic-4511/
• https://openlabpro.com/guide/push-button-interfacing-with-pic16f877a/
• https://openlabpro.com/guide/push-button-interfacing-with-pic-microcontroller/
• https://embetronicx.com/tutorials/microcontrollers/pic16f877a/pic16f877a-interrupt-
tutorial/#PIC16F877A_Interrupt_Tutorial
• https://hangcafe.wordpress.com/2017/08/30/using-pic16f887-external-interrupt-in-mikroc/
• https://techetrx.com/pic-microcontroller/adc-in-pic16f887-microcontroller/
• https://circuitdigest.com/microcontroller-projects/pic-microcontroller-pic16f877a-adc-
tutorial
• https://internetofthingsagenda.techtarget.com/definition/microcontroller

• https://www.electronics-notes.com/articles/digital-embedded-processing/embedded-
systems/what-is-embedded-microcontroller-mcu.php

• https://components101.com/microcontrollers/pic16f887-microcontroller

• https://www.theengineeringprojects.com/2018/08/introduction-to-pic16f887.html

COURSE PROJECT: ROAD TECH 25

You might also like