0% found this document useful (0 votes)
11 views10 pages

INTERFACE

The document describes an automatic vehicle braking system using an ultrasonic sensor, LPC2148 microcontroller, DC motor and LCD display. The system measures distance to obstacles using ultrasonic sensor and controls motor speed or stops if distance is below a threshold, to prevent collisions. It also displays real-time speed information on the LCD.

Uploaded by

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

INTERFACE

The document describes an automatic vehicle braking system using an ultrasonic sensor, LPC2148 microcontroller, DC motor and LCD display. The system measures distance to obstacles using ultrasonic sensor and controls motor speed or stops if distance is below a threshold, to prevent collisions. It also displays real-time speed information on the LCD.

Uploaded by

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

ADDIS ABABA UNIVERSITY

ADDIS ABABA INSTITUTE OF TECHNOLOGY

SCHOOL OF ELECTRICAL AND COMPUTER ENGINEERING


ELECTRONICS STREAM

Microcomputers and Interfacing: ECEG-4181


Semester Project

Title: Automatic Vehicle Breaking by using LPC2148

Members
1. Ezra Mohammed—---------------UGR/6735/13
2. Ermiyas Birhanu—----------------UGR/5714/13
3. Rahel Brhanie—-------------------URG/8220/13
4. Biruk Kumlachew—---------------UGR/0727/13
5. Tsion Asmare—--------------------UGR/5275/13

Submitted to: Instructor Kinde M.


Submission Date: May 23, 2024
Abstract
This project presents the design and implementation of an automatic vehicle braking system
utilizing an ultrasonic sensor, the LPC2138 microcontroller, a DC motor, and an LCD display. The
system aims to enhance vehicular safety by automatically controlling the speed of the vehicle in
response to the proximity of obstacles.
The core functionality of the system involves the ultrasonic sensor continuously measuring the
distance to potential obstacles in the vehicle's path. The LPC2138 microcontroller processes this
distance data and determines whether the vehicle is at a safe distance from any detected obstacle.
If the distance falls below a predefined safety threshold, the microcontroller commands the motor
to reduce its speed or stop completely, thereby preventing collisions.
In addition to the braking functionality, the system includes an LCD display that provides real-
time information on the vehicle's speed. This feedback ensures that the user is constantly informed
of the vehicle's operational status.
Introduction
LPC2148
a single-chip 16 bit or 32 bit ARM7 family based microcontroller 16/32-bit RISC
Microcontroller with 512KB on-chip Flash ROM with In-System Programming (ISP) and Two
10bit ADCs with 14 channels, Two UARTs.

Figure 1. LPC2148.
LPC2148 is an incredible powerful device that stand out among other microcontrollers. It is
remarkable features and advantages make it popular choice for various application in the field of
embedded Systems.
Features of LPC2148
ROM 512 KB
RAM 32KB
IO PORTS 2 (P0, P1)
Timers 2 (32 bit)
Serial comm 2 UART, 2 I2C, 1 SSP, 1 SPI
USB RAM 2 KB

Ultrasonic sensor
An ultrasonic sensor is an instrument that measures the distance to an object using ultrasonic
sound waves. An ultrasonic sensor uses a transducer to send and receive ultrasonic pulses that
relay back information about an object's proximity.
Ultrasonic sensors work by sending out a sound wave at a frequency above the range of human
hearing. The transducer of the sensor acts as a microphone to receive and send the ultrasonic
sound.

Figure 2. Ultrasonic Sensor


Common obstructions include
 Dirt
 Snow
 Ice
 Other Condensation.

L293D Motor Driver


L293D is a quadruple high-current half-H driver designed to provide bidirectional drive currents
of up to 600 mA at voltages from 4.5 V to 36 V. It is an ideal choice for driving DC motors in an
embedded system.

Figure 3. L293D Motor Driver

DC Motors
Which drive the vehicles. And controlled by L293D.

A 20x4 LCD display


is alphanumeric dot matrix display is capable of displaying it can display 16 characters per line
and there are 2 such lines.

Figure 4. LCD Display


Algorithm of the Code
1. Initialization
 Configure the PCLK (Peripheral Clock) to 60 MHz by setting VPBDIV.
 Configure certain pins (10, 12, 13, 16-23) of port 0 and pins 16 and 17 of port 1 as
outputs.
 Initialize the ultrasonic sensor, LCD, and display the initial message "Distance :" on the
LCD.
 Set the enable bits EN on port 1 to high.
2. Main Loop:
 Continuously measure the distance to the nearest obstacle using the ultrasonic sensor.
 Display the measured distance on the LCD in centimeters.
 Based on the measured distance, take appropriate actions to control the motor and display
warnings.
3. Distance Measurement:
 Range = get_range(): Measure the distance using the ultrasonic sensor.
 Display the distance on the LCD using dat() to send individual characters and show() for
strings.
4. Distance Evaluation:
 If Distance < 50 cm
 Clear the enable bits EN to stop the motor.
 Display "CRASH WARNING" on the LCD.
 If Distance Between 50 and 100 cm
 If the motor is running (checked using IOSET1 & EN):
 Display "CRASH WARNING" on the LCD.
 Adjust cent to the current distance and iterate 50 times to check and adjust the
buffer register.
 For each iteration
 If the buffer register status (get_bufreg(buffer)) matches the current range
status (get_bufreg(range)), do nothing.
 Otherwise, decrease cent gradually while the distance remains between 50
and 100 cm.
 During each iteration, control the motor by alternating between enabling
and disabling EN with appropriate delays using timer1delay ().
 Clear the enable bits EN to stop the motor.
 If the motor is not running, clear the enable bits EN and display "CRASH WARNING"
on the LCD.
 Update the buffer with the current range.
 If Distance > 100 cm
 Set the enable bits EN to keep the motor running.
 Display "You are safe :)" on the LCD.
Source Code

#include <lpc214x.h> // Include LPC214x microcontroller definitions


#include "TIMER.H" // Include timer functions
#include "ULTRASONIC.H" // Include ultrasonic sensor functions
#include "LCD.H" // Include LCD functions

#define EN (1<<16)|(1<<17) // Define enable bits for motor control


int cent = 100; // Initialize cent variable for motor control
unsigned int range, i; // Variables for distance range and loop counter
unsigned char* warn; // Pointer for warning message (unused)
unsigned int value; // Value variable (unused)
unsigned int buffer = 0; // Buffer to store previous range
// Function to get buffer register value based on range

unsigned int get_bufreg(unsigned int trange) {


if (trange <= 100 && trange >= 50) {
return 1; // Return 1 if range is between 50 and 100 cm
} else if (trange < 50) {
return 0; // Return 0 if range is less than 50 cm
} else {
return 2; // Return 2 if range is greater than 100 cm
}
}
int main() {
VPBDIV = 0x01; // Set PCLK to 60MHz
IO0DIR |= 0x00FF3400; // Set pins 10, 12, 13, 16-23 of port 0 as outputs
IO1DIR |= EN; // Set pins 16 and 17 of port 1 as outputs
ultrasonic_init(); // Initialize ultrasonic sensor
lcd_init(); // Initialize LCD
show("Distance :"); // Display initial message on LCD
IOSET1 = EN; // Set enable bits to high

while (1) {
cmd(0x8A); // Set cursor position on LCD
range = get_range(); // Get distance from ultrasonic sensor
// Display distance on LCD
dat((range / 100) % 10 + 48);
dat((range / 10) % 10 + 48);
dat((range % 10) + 48);
show("cm");

if (range < 50) {


IOCLR1 = IOCLR1 | EN; // Clear enable bits to stop motor
cmd(0xC0); // Move cursor to second line on LCD
show("CRASH WARNING "); // Display crash warning message
} else if (range <= 100 && range >= 50) {
if ((IOSET1 & EN) == EN) {
cmd(0xC0); // Move cursor to second line on LCD
show("CRASH WARNING "); // Display crash warning message
cent = range; // Set cent to current range
for (i = 0; i < 50; i++) {
if (get_bufreg(buffer) == get_bufreg(range)) {
// Do nothing if buffer register value matches range
} else {
while (cent != 0) {
range = get_range(); // Get updated range
if (range <= 100 && range >= 50) {
IOSET1 = IOSET1 | EN; // Set enable bits to high
timer1delay(cent * 200); // Delay
range = get_range(); // Get updated range
if (range <= 100 && range >= 50) {
IOSET1 = IOSET1 | EN; // Set enable bits to high
timer1delay(cent * 200); // Delay
IOCLR1 = IOCLR1 | EN; // Clear enable bits
timer1delay((100 - cent) * 200); // Delay
cent = cent - 1; // Decrement cent
} else {
break; // Exit loop if range is out of bounds
}
}
}
}
IOCLR1 = IOCLR1 | EN; // Clear enable bits to stop motor
} else {
IOCLR1 = IOCLR1 | EN; // Clear enable bits to stop motor
cmd(0xC0); // Move cursor to second line on LCD
show("CRASH WARNING "); // Display crash warning message
}
buffer = range; // Update buffer with current range
range = get_range(); // Get updated range
}

if (range > 100) {


IOSET1 = IOSET1 | EN; // Set enable bits to keep motor running
cmd(0xC0); // Move cursor to second line on LCD
show("You are safe :) "); // Display safe message
}
}

return 0;
Simulation Result

Figure 5. Simulation

You might also like