Assignment Benc2423

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

SEMESTER II SESSION 2020/2021

FACULTY OF ELECTRONICS AND COMPUTER ENGINEERING (FKEKK)

COURSE: 2 BENR S1
SUBJECT: MICROPROCESSOR TECHNOLOGY

SUBJECT CODE: BENC 2423

GROUP PROJECT:
INTEGRATED PROJECT

PREPARED BY:

STUDENT MATRIC NO

1 ARFAN BIN AZMAN B021910012

2 MUHAMMAD ZHAFFUAN BIN MOHD SHAH B021910044

3 MUHAMMAD IKHWAN BIN ROZAIDI B021910033

4 MUHAMAD ILHAM FAHMI BIN AZMI B021910022

PREPARED FOR:

DR. MUHAMMAD IDZIHAR BIN IDRIS


1. INTRODUCTION

The idea of this product come from the social distancing that we have been practicing
since the start of the outbreak of the Covid-19. As we all know keeping the distance will at
least lower the percentage of us to get infected by others. So, this product came in to make sure
that we always keeping the distance of 1 meter with everyone.

HC-SR04 Ultrasonic (US) sensor is a 4 pin module, whose pin names are Vcc,
Trigger, Echo and Ground respectively. The Vcc pin powers the sensor, typically with +5V.
Secondly, Trigger pin is an Input pin. This pin has to be kept high for 10us to initialize
measurement by sending ultrasonic (US) wave. Thirdly, Echo pin is an Output pin. This pin
goes high for a period of time which will be equal to the time taken for the US wave to return
back to the sensor. Last but not least, Ground pin is used to be connected to the Ground of the
system.

This sensor is a very popular sensor used in many applications where measuring
distance or sensing objects are required. The module has two eyes like projects in the front
which forms the Ultrasonic transmitter and Receiver. The sensor works with the simple formula
that Distance = Speed × Time. The Ultrasonic transmitter transmits an ultrasonic wave, this
wave travels in air and when it gets objected by any material it gets reflected back toward the
sensor this reflected wave is observed by the Ultrasonic receiver module as shown in the picture
below
Now, to calculate the distance using the above formulae, we should know the Speed
and time. Since we are using the Ultrasonic wave we know the universal speed of US wave at
room conditions which is 330m/s. The circuitry inbuilt on the module will calculate the time
taken for the US wave to come back and turns on the echo pin high for that same particular
amount of time, this way we can also know the time taken. Now simply calculate the distance
using a microcontroller or microprocessor.

HC-SR04 distance sensor is commonly used with both microcontroller and


microprocessor platforms like Arduino, ARM, PIC, Raspberry Pie etc. The following guide is
universally since it has to be followed irrespective of the type of computational device used.
Power the Sensor using a regulated +5V through the Vcc ad Ground pins of the sensor. The
current consumed by the sensor is less than 15mA and hence can be directly powered by the
on board 5V pins (If available). The Trigger and the Echo pins are both I/O pins and hence
they can be connected to I/O pins of the microcontroller. To start the measurement, the trigger
pin has to be made high for 10uS and then turned off. This action will trigger an ultrasonic
wave at frequency of 40Hz from the transmitter and the receiver will wait for the wave to
return. Once the wave is returned after it getting reflected by any object the Echo pin goes high
for a particular amount of time which will be equal to the time taken for the wave to return
back to the sensor. The amount of time during which the Echo pin stays high is measured by
the MCU/MPU as it gives the information about the time taken for the wave to return back to
the Sensor. Using this information the distance is measured as explained in the above heading.

There are a few applications of HC-SR04 Ultrasonic (US) sensor. One of them is used
to avoid and detect obstacles with robots like biped robot, obstacle avoider robot, path finding
robot etc. Next, it is used to measure the distance within a wide range of 2cm to 400cm and
also to map the objects surrounding the sensor by rotating it. Finally, HC-SR04 sensor can
measure depth of certain places like wells since the waves can penetrate through water. The
equivalent distance measuring sensors for HC-SR04 sensor are US transmitter Receiver pair,
IR sensor module, IR sensor pair, IR Analog distance sensor.

LPC1768 Microcontroller are a series of ARM microcontroller development boards


designed for rapid prototyping all sorts of devices, especially those including Ethernet, USB,
and the flexibility of lots of peripheral interfaces and FLASH memory. It is packaged as a small
DIP form-factor for prototyping with through-hole PCBs, stripboard and breadboard, and
includes a built-in USB FLASH programmer.

It is based on the NXP LPC1768, with a 32-bit ARM Cortex-M3 core running at
96MHz. It includes 512KB FLASH, 32KB RAM and lots of interfaces including built-in
Ethernet, USB Host and Device, CAN, SPI, I2C, ADC, DAC, PWM and other I/O interfaces.
The pinout above shows the commonly used interfaces and their locations. Note that all the
numbered pins (p5-p30) can also be used as DigitalIn and DigitalOut interfaces.

The LPC1768 Microcontroller provide experienced embedded developers a powerful


and productive platform for building proof-of-concepts. For developers new to 32-bit
microcontrollers, LPC1768 Microcontroller provides an accessible prototyping solution to get
projects built with the backing of libraries, resources and support shared in the mbed
community. LPC1768 is packaged as a small 40-pin DIP, 0.1-inch pitch form-factor making it
convenient for prototyping with solderless breadboard, stripboard, and through-hole PCBs. It
includes a built-in USB programming interface that is as simple as using a USB Flash Drive.
Plug it in, drop on an ARM program binary, and its up and running.
2. CIRCUIT DESIGN

In this circuit we use HC-SR04 as the most crucial part of this project. HC-SR04 is an
ultrasonic sensor consist of two membrane. Each of the membrane works differently, one
membrane act as speaker that produce sound while the other one act as microphone that catch
the reflected sound.

Some features of the sensors are :


NXP LPC1768 MCU
• Operating voltage: +5V
• Theoretical Measuring Distance: 2cm to 450cm
• Practical Measuring Distance: 2cm to 80cm
• Accuracy: 3mm
• Measuring angle covered: <15°
• Operating Current: <15mA
• Operating Frequency: 40Hz
In this project, we use LPC1768 micro
controller. Some features of the microcontroller :
NXP LPC1768 MCU
• High performance ARM® Cortex™-M3 Core
• 96MHz, 32KB RAM, 512KB FLASH
• Ethernet, USB Host/Device, 2xSPI, 2xI2C,
3xUART, CAN, 6xPWM, 6xADC, GPIO
Prototyping form-factor
• 40-pin 0.1" pitch DIP package, 54x26mm
• 5V USB or 4.5-9V supply
• Built-in USB drag 'n' drop FLASH programmer
mbed.org Developer Website
• Lightweight Online Compiler
• High level C/C++ SDK
• Cookbook of published libraries and projects

Piezo Buzzer is a small system that produces simple beeps and shades. Piezo crystal, a
special material that enables the buzzer to work by adjusting its shape when the voltage is
applied to it. If the crystal moves against the diaphragm, like a tiny speaker cone, it can produce
a pressure wave that the human ear picks up as a sound. The following figures show the piezo
buzzer and its construction.
Figure above is how all the component is constructed. When the ultrasonic sensor
receive the input, it will trigger the buzzer to produce a simple beep sound that will alert the
user that there are close to someone. So, by this project it can help us to practice social
distancing in a better way and prevent the outbreak of the Covid-19.
3. FLOWCHART

START

HC-SR04 READ TRIGGER

NO
<1 METER

YES

TRIGGER BUZZER TO
LED TRIGGER TO ON
PRODUCE BEEP SOUND

END
4. ASSEMBLY LANGUAGE
Coding implementation link: https://web.microsoftstream.com/video/3d1d3b39-0d3e-452e-
9067-4893ccd54aa3

AREA MYCODE,CODE, READONLY


ENTRY
EXPORT SystemInit
SystemInit
EXPORT __main

PINSEL1 EQU 0x4002C004


PINSEL3 EQU 0x4002C010

FIO0DIR EQU 0x2009C000


FIO1DIR EQU 0x2009C040

FIO0SET EQU 0x2009C018


FIO1SET EQU 0x2009C058

FIO0PIN EQU 0x2009C014

FIO0CLR EQU 0x2009C01C


FIO1CLR EQU 0x2009C05C

TC EQU 0x40004004
TR EQU 0x40004008

LDR R0,=PINSEL1
LDR R1,=0x00
STR R1,[R0]

LDR R0,=PINSEL3
LDR R1,=0x000
STR R1,[R0]
LDR R0,=FIO0DIR
LDR R1,=0x08000000
STR R1,[R0]

LDR R0,=FIO1DIR
LDR R1,[R0]
MOV R1,#0x0000007
STR R1,[R0]

LDR R8,=FIO0PIN
LDR R5,=FIO0SET
LDR R6,=FIO1SET
LDR R9,=FIO0CLR
LDR R10,=FIO1CLR
LDR R11,=TC
LDR R12,=TR

AGAIN ;START TRIGGER

LDR R7,=0x800000
STR R7,[R5]

;DELAY
LDR R1,=0x96900000
DELAY SUB R1,R1,#1
CMP R1,#01
BNE DELAY

;STOP TRIGGER
STR R7,[R9]

;START READING ECHO


LDR R1,=0x1000000
READ LDR R2,[R8]
AND R2,R2,R1
CMP R2,R1
BNE READ

;START TIMER
LDR R0,=0x1
STR R0,[R11]
READ1 LDR R2,[R8]
AND R2,R2,R1
CMP R2,R1
BEQ READ1

;STOP TIMER
LDR R0,=0x0
STR R0,[R11]

;READ TIMER
LDR R3,[R12]

;CLR TIMER
STR R14,[R12]

;CALCULATE DISTANCE
CMP R3,#900
BGT FAR
CMP R3,#600
BGT LT1_5
CMP R3,#300
BGT LT1_0
B FAR

LT1_5 LDR R3,=0x00000002


LDR R4,=0x00000005
STR R4,[R10]
STR R3,[R6]
LDR R14,=0x0FFFF000 ;DELAY FOR LED mid
DELAY4 SUB R14,R14,#0x01000000
CMP R14,#0x01000000
BNE DELAY4
B AGAIN

LT1_0 LDR R3,=0x00000004


LDR R4,=0x00000003
STR R4,[R10]
STR R3,[R6]
LDR R14,=0x0FFFF000 ;DELAY FOR LED near
DELAY3 SUB R14,R14,#0x01000000
CMP R14,#0x01000000

BNE DELAY3
B AGAIN

FAR LDR R3,=0x00000001


LDR R4,=0x00000006
STR R4,[R10]
STR R3,[R6]
LDR R14,=0x0FFFF000 ;DELAY FOR LED far.
DELAY5 SUB R14,R14,#0x01000000
CMP R14,#0x01000000

BNE DELAY5
B AGAIN

DONE
ALIGN
END
5. CODING EXPLANATION
CODE EXPLANATION
PIN1SEL EQU 0x4002C004
PIN3SEL EQU 0x4002C010

FIO0DIR EQU 0x2009C000


FIO1DIR EQU 0x2009C040

FIO0SET EQU 0x2009C018


FIO1SET EQU 0x2009C058 Settings of ultrasonic (trigger and echo)
and led output with the address refer from
FIO0PIN EQU 0x2009C014 GPIO table.

FIO0CLR EQU 0x2009C01C


FIO1CLR EQU 0x2009C05C

TC EQU 0x40004004
TR EQU 0x40004008
LDR R0,=PIN1SEL
LDR R1,=0x00
STR R1,[R0]
LDR R0,=PIN3SEL
LDR R1,=0x000
STR R1,[R0]
LDR R0,=FIO0DIR This is to assign the pin number as
LDR R1,=0x0800000 input/output; input=0 and output =1
STR R1,[R0]
LDR R0,=FIO1DIR
LDR R1,[R0]
MOV R1,#0x0000007
STR R1,[R0]
LDR R8,=FIO0PIN
LDR R5,=FIO0SET
LDR R6,=FIO1SET Load the assigned register as R5, R6,
LDR R9,=FIO0CLR R8, R9, R10, R11 and R12.
LDR R10,=FIO1CLR
LDR R11,=TC
LDR R12,=TR
AGAIN ;START TRIGGER
LDR R7,=0x800000
STR R7,[R5]
Start the ultrasonic trigger pin to
;DELAY release a ultrasonic waveform and
LDR R1,=0x969 delay is for how long the waveform
DELAY SUB R1,R1,#1 will be release. After delay, stop
CMP R1,#01 trigger.
BNE DELAY
;STOP TRIGGER
STR R7,[R9]
;START READING ECHO
LDR R1,=0x1000000
READ LDR R2,[R8]
AND R2,R2,R1
CMP R2,R1
BNE READ

;START TIMER
LDR R0,=0x1
STR R0,[R11]
READ1 LDR R2,[R8]
AND R2,R2,R1 Read the echo and start the timer in the
CMP R2,R1 same time, once the trigger waveform
BEQ READ1 reflex to the echo, the timer will stop,
and we read the time
;STOP TIMER
LDR R0,=0x0
STR R0,[R11]

;READ TIMER
LDR R3,[R12]

;CLR TIMER
STR R14,[R12]
;CALCULATE DISTANCE
CMP R3,#900
BGT FAR The timer is compare if the waveform
CMP R3,#600 received by echo is =900 which is far;
BGT LT1_5 if =600 then is at middle range; and the
CMP R3,#300 danger zone is =300; else is consider as
BGT LT1_0 far.
B FAR
LT1_5 LDR R3,=0x00000002
LDR R4,=0x00000005
STR R4,[R10]
STR R3,[R6]
LDR R14,=0x0FFFF
In the middle range, the led yellow in
;DELAY FOR LED mid pin25 will light up and clear the pin 24
and 26 to avoid wrong output. And
DELAY4 SUB R14,R14,#0x01 delay is to given the led not to changing
CMP R14,#0x01 to fast.
BNE DELAY4
B AGAIN
LT1_0 LDR R3,=0x00000004
LDR R4,=0x00000003
STR R4,[R10]
STR R3,[R6]
LDR R14,=0x0FFFF ;DELAY
FOR LED near In the danger range, the led yellow in
DELAY3 SUB R14,R14,#0x01 pin24 will light up and clear the pin 25
CMP R14,#0x01 and 26 to avoid wrong output. And
BNE DELAY3 delay is to given the led not to changing
B AGAIN to fast
FAR LDR R3,=0x00000001
LDR R4,=0x00000006
STR R4,[R10]
STR R3,[R6] In the danger range, the led yellow in
LDR R14,=0x0FFFF ;DELAY pin26 will light up and clear the pin 24
FOR LED far. and 25 to avoid wrong output. And
DELAY5 SUB R14,R14,#0x01 delay is to given the led not to changing
CMP R14,#0x01 to fast.
BNE DELAY5
B AGAIN

CONCLUSION

All in all, by completing this project, we can improve the practice of social distancing
among the society. This can make a difference in preventing the spread of Covid-19 in
Malaysia. Thus, the risk of people getting infected by the pandemic Covid-19 that is spreading
around the country can be reduced.

You might also like