Sensorproject

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

DECLARATION

I hereby certify that the work is being presented in this Report work entitled “Switching
regulator using LM723” is an authentic record of my own work carried under the supervision
of Mr. Soumya Jyoti Dan and Mr. Sourav Chatterjee, Department of Electrical
engineering.

Date: 28/11/23

Avijit Jana (DEE 20)

Atanu Senapati (DEE 16)

Sandip Sadhukhan (DEE 19)

Abhijoy Paul (DEE 05)

Moulindu Saha (DEE 02)

1|Page
ACKNOWLEDGEMENT
I would like to convey my heartfelt gratitude to our teacher Mr. Soumya Jyoti Dan and Mr.
Sourav Chatterjee for his tremendous support and assistance in the completion of my
project. We would also like to thank our Department for providing me with this wonderful
opportunity to work on a project with the topic “Distance measurement using Ultrasonic
Sensor and 8051 microcontroller”. The completion of the project would not have been
possible without their help and insights.

Date: 28/11/23

Avijit Jana (DEE 20),

Atanu Senapati (DEE 16),

Sandip Sadhukhan (DEE 19),

Abhijoy Paul (DEE 30)

Moulindu Saha (DEE 02)

………………………………...
(Signature of the project –in-charge)

(Department of Electrical Engineering,3rd year, 5th Sem)

2|Page
TABLE OF CONTENTS

PAGE NO.
ABSTRACT …………………………………………................................................4

OBJECTIVE………………………………………………………………………..........6

THEORY………………………………………………………………………..............6
 ABOUT SWITCHING REGULATOR
………………………………………………..6
 ABOUT HC-SR04…………………………………………………………………..6
 FACTORS TO CONSIDER FOR A SWITCHING
REGULATOR…………………….10
 WORKING PRINCIPLE OF SWITCHING REGULATOR USING
LM723…………….12

COMPONENTS REQUIRED ………………………………………………………...12

CIRCUIT DIAGRAM………………………………………………………………….. 12

EXPERIMENTAL DATA ………………………………………………………………13

CALCULATION……………………………………………………………………….. 14

PRECAUTION……………………………………………………………………….. 14

ADVANTAGES ………………………………………………………………………..14

DISADVANTAGES……………………………………………………………………14

FUTURE SCOPE……………………………………………………………………. 15

CONCLUSION …………………………………………………………………………15

3|Page
OBJECTIVES:

 To design and implement a low-cost and accurate device that can measure the
distance of an object from the sensor using sound waves.
 To learn and demonstrate the working principle and interfacing of the ultrasonic
module HC-SR04 with the 8051-microcontroller using C programming language.
 To compare and analyze the performance and limitations of the ultrasonic sensor with
other distance measurement methods, such as infrared, laser, etc.
 To show the measured distance using a 7 segment LED display and comparing with
the actual distance.

THEORY:

8051 MICROCONTROLLER:

The 8051 microcontroller is a popular 8-bit microcontroller that was introduced by Intel in 1981.
It has a 40-pin dual in-line package (DIP) that provides various inputs and outputs for
communication with external devices. It has four I/O ports, each with 8 pins, that can be
configured as input or output depending on the logic state of the pins. It also has an 8-bit data
bus, a 16-bit address bus, two 16-bit timers, a 16-bit program counter, a 16-bit data pointer, a 8-
bit stack pointer, a 8-bit processor status word, and 128 bytes of on-chip RAM. It also has some
special function registers, such as UART, ADC, Op-amp, etc. The 8051 microcontroller can be
programmed using assembly language or C language. It is widely used in embedded systems,
such as robotics, remote controls, automotive industry, telecom applications, power tools, etc.

4|Page
PIN DESCRIPTION:

The 8051 microcontroller is a 40-pin device that has various inputs and outputs for
interfacing with external devices. The pin description of the 8051 microcontroller is as
follows:

 Pins 1 to 8: These pins are known as Port 1 (P1.0 to P1.7). They are bi-directional
I/O pins that can be configured as input or output depending on the logic state of the
pins. They do not have any other functions.
 Pin 9: This pin is known as Reset (RST). It is an active-high input pin that is used to
reset the microcontroller to its initial values. It is also called “power-on-reset” pin
because it resets the microcontroller when power is turned on.
 Pins 10 to 17: These pins are known as Port 3 (P3.0 to P3.7). They are bi-directional
I/O pins that can be configured as input or output depending on the logic state of the
pins. They also have some additional functions, such as serial communication,
external interrupts, timers, and control signals.
 Pins 18 and 19: These pins are known as Crystal 1 and Crystal 2 (XTAL1 and
XTAL2). They are used to connect an external crystal oscillator that provides the
clock frequency for the microcontroller. The frequency of the crystal oscillator
determines the speed of the microcontroller.
 Pin 20: This pin is known as Power Supply (VCC). It is connected to the positive
terminal of the power supply, usually 5V.
 Pins 21 to 28: These pins are known as Port 2 (P2.0 to P2.7). They are bi-directional
I/O pins that can be configured as input or output depending on the logic state of the
pins. They also serve as the higher order address bus for accessing external memory.
 Pin 29: This pin is known as Program Store Enable (PSEN). It is an active-low
output pin that is used to read the code from the external program memory when the
External Access pin is low.
 Pin 30: This pin is known as External Access (EA). It is an active-low input pin that
is used to enable or disable the external memory interfacing. If the EA pin is low, the
microcontroller will execute the code from the external memory. If the EA pin is high,
the microcontroller will execute the code from the internal memory.
 Pin 31: This pin is known as Address Latch Enable (ALE). It is an active-high output
pin that is used to latch the lower byte of the address from the multiplexed
5|Page
address/data bus to an external latch. This is done because the lower byte of the
address/data bus is shared with Port 0.
 Pins 32 to 39: These pins are known as Port 0 (P0.0 to P0.7). They are bi-directional
I/O pins that can be configured as input or output depending on the logic state of the
pins. They also serve as the lower order address/data bus for accessing external
memory.
 Pin 40: This pin is known as Ground (GND). It is connected to the negative terminal
of the power supply, usually 0V.

APPLICATIONS OF 8051 MICROCONTROLLER:

The 8051 microcontroller is a popular and versatile 8-bit microcontroller that was designed
by Intel in 1981. It has many features and applications in various fields of electronics and
robotics. Some of the applications of 8051 microcontroller are:

 Industrial control systems: Speed, pressure, Level, flow.


 Home automation: Lighting, security, appliances.
 Robotics
 Automotive industry: Engine management, Fuel injection, Anti-lock braking
 Medical devices: Blood pressure monitoring, Glucose meter, Pulse Oximeter.

WORKING PRINCIPLE OF 8051 MICROCONTROLLER:

The working principle of 8051 microcontroller is based on the Harvard architecture, which
means that it has separate memory spaces for program and data. The 8051 microcontroller
consists of an 8-bit CPU, 4 KB of ROM, 128 bytes of RAM, four 8-bit I/O ports, two 16-bit
timers, a serial port, and an interrupt system. The 8051 microcontroller executes the
instructions stored in the ROM using the CPU, which has an 8-bit accumulator, an 8-bit B
register, and several other 8-bit and 16-bit registers. The 8051 microcontroller can
communicate with external devices using the I/O ports, which can be configured as input or
output depending on the logic state of the pins. The 8051 microcontroller can also perform
various operations using the timers, the serial port, and the interrupt system, which can
handle internal and external events.

HC-SR04 ULTRASONIC SENSOR:

6|Page
The HC-SR04 ultrasonic sensor is a device that can measure the distance to an object by
using sound waves. It works on the principle of sonar, which is a technique that uses sound
navigation and ranging to detect objects. The sensor consists of two ultrasonic transducers:
one that acts as a transmitter and one that acts as a receiver. The transmitter emits a high-
frequency sound pulse (40 kHz) and the receiver listens for the echo. The time difference
between the transmission and reception of the sound pulse is proportional to the distance of
the object from the sensor. The sensor can measure distances from 4 cm to 255 cm with an
accuracy of 0.3 cm. The sensor has four pins: VCC, TRIG, ECHO, and GND. The VCC pin
provides power supply (5V) to the sensor, the TRIG pin triggers the sound pulse, the ECHO
pin outputs the echo signal, and the GND pin connects to the ground. The sensor can be
interfaced with 8051 or other microcontrollers to perform various applications, such as
obstacle detection, parking sensor, liquid level measurement, distance measurement etc.

RATING OF HC-SR04 ULTRASONIC SENSOR:

Serial No. Parameters Rating

1 Operating voltage DC - 5V
2 Operating current 15mA
3 Operating frequency 40Khz

4 Farthest range 2.55m


5 Nearest range 4cm
6 Measuring angle 15 degree
7 Input trigger signal 10uS TTL Pulse
8 Output echo signal Output TTL Level signal, proportional with range

9 Dimensions 45*20*15 mm

COMPONENTS LIST AND ESTIMATION:

7|Page
Sl no. Component name Qty. Price

1. AT89S52 microcontroller IC 1 120

2. HCSR04 ultrasonic sensor 1 60

3. 11.0592 Crystal oscillator 1 12

4. 7 segment display 3 30

5. 9V battery and connector 1 25

6. LM7805 voltage regulator IC 1 12

7. BC547 transistor 3 6

8. 1K resistor 3 3

9. 220Ω resistor 3 3

10. 10µF capacitor 1 1

11. 10K resistor 1 1

12. 100Ω resistor 8 8

13. 33pF capacitor 2 2

14. Vero board 1 40

15. Push switch 1 1

WORKING OF THE CIRCUIT ;

The working of distance measurement using ultrasonic sensor using 8051 microcontroller and
display the result in 7 segment common anode 3 digit display can be explained as follows:

8|Page
 The ultrasonic sensor module (HC-SR04) is connected to the 8051 microcontroller
using two pins: the trigger pin (P3.5) and the echo pin (P3.2). The trigger pin is used
to send a high-frequency sound pulse (40 kHz) and the echo pin is used to receive the
reflected sound wave.
 The 7 segment display module is connected to the 8051 microcontroller using four
pins: the data pin (P2.0), the clock pin (P2.1), the latch pin (P2.2), and the enable pin
(P2.3). The data pin is used to send the binary data for each digit, the clock pin is used
to synchronize the data transfer, the latch pin is used to store the data in the shift
register, and the enable pin is used to turn on or off the display.
 The 8051 microcontroller is programmed using C language to perform the following
tasks:
o Initialize the timer 0 module as a 16-bit timer with gate bit as 1. This will
allow the timer to start and stop counting based on the external interrupt from
the echo pin.
o Initialize the serial port module for displaying the distance on the serial
monitor (optional).
o Send a 10 us pulse to the trigger pin to initiate the ultrasonic transmission.
o Wait for the echo pin to go high and start the timer 0.
o Wait for the echo pin to go low and stop the timer 0.
o Read the value of the timer 0 and calculate the distance using the formula:
distance in cm = (timer 0 / 59).
o Display the distance on the 7 segment display by sending the binary data for
each digit to the data pin and toggling the clock, latch, and enable pins
accordingly.
o Repeat the above steps in a loop.

PROGRAMMING IN EMBEDDED C:

// include the header file for 8051

#include <reg51.h>

9|Page
// define the pins for trigger and echo

#define TRIG P3_5

#define ECHO P3_2

// define the lookup table for 7 segment display

unsigned char code LUT[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D,
0x7D, 0x07, 0x7F, 0x6F};

// declare the functions

void delay1(void); // 10 us delay

void delay(void); // 1 ms delay

void display(unsigned char); // display function

void main(void)

unsigned char distance; // variable to store the distance

DPTR = LUT; // load the address of LUT to DPTR

P1 = 0x00; // set P1 as output port

P0 = 0x00; // set P0 as output port

TRIG = 0; // set TRIG as output

ECHO = 1; // set ECHO as input

TMOD = 0x20; // set timer1 as mode 2 auto reload timer

while(1) // main loop

10 | P a g e
{

TL1 = 0x7D; // load the initial value to start counting from

TH1 = 0x7D; // load the reload value

ACC = 0x00; // clear accumulator

TRIG = 1; // start the trigger pulse

delay1(); // give 10 us width for the trigger pulse

TRIG = 0; // end the trigger pulse

while(ECHO == 0); // wait until echo is received

do

TR1 = 1; // start the timer1

while(TF1 == 0); // wait until timer overflows (48


count)

TR1 = 0; // stop the timer

TF1 = 0; // clear timer flag 1

ACC++; // increment ACC for every timer1 overflow

} while(ECHO == 1); // repeat until echo is low

distance = ACC; // save the value of ACC to distance

display(distance); // call the display function

11 | P a g e
}

void delay1(void) // 10 us delay function

unsigned char i = 45; // load the delay count

while(i--); // decrement and loop until zero

void delay(void) // 1 ms delay function

unsigned char i = 250; // load the delay count

while(i--); // decrement and loop until zero

void display(unsigned char x) // display function

unsigned char i, j, k; // declare the variables

for(i = 0; i < 100; i++) // repeat the display loop 100 times

j = x / 100; // isolate the first digit

P1_0 = 1; // activate LED display unit D1

ACC = j; // load the first digit to ACC

display(LUT[ACC]); // get the digit drive pattern from LUT

12 | P a g e
CPL A; // complement the digit drive pattern

P0 = A; // move the digit drive pattern to P0

delay(); // 1 ms delay

delay(); // 1 ms delay

k = x % 100; // get the remainder of the first division

j = k / 10; // isolate the second digit

P1_0 = 0; // deactivate LED display unit D1

P1_1 = 1; // activate LED display unit D2

ACC = j; // load the second digit to ACC

display(LUT[ACC]); // get the digit drive pattern from LUT

CPL A; // complement the digit drive pattern

P0 = A; // move the digit drive pattern to P0

delay(); // 1 ms delay

delay(); // 1 ms delay

j = k % 10; // isolate the third digit

P1_1 = 0; // deactivate LED display unit D2

P1_2 = 1; // activate LED display unit D3

ACC = j; // load the third digit to ACC

display(LUT[ACC]); // get the digit drive pattern from LUT

CPL A; // complement the digit drive pattern

13 | P a g e
P0 = A; // move the digit drive pattern to P0

delay(); // 1 ms delay

delay(); // 1 ms delay

P1_2 = 0; // deactivate LED display unit D3

PROGRAMMING FLOWCHART:

14 | P a g e
PROGRAM DESCRIPTION:

The program is an embedded C code that is used to measure the distance of an object using
an ultrasonic sensor and display the result on a 7 segment display. The program performs the
following steps:

 It includes the header file for 8051 microcontroller and defines the pins for trigger and
echo of the ultrasonic sensor module (HC-SR04).
 It declares the lookup table for 7 segment display and the functions for delay and
display.
 It initializes the data pointer, ports, timer, and serial port modules of the 8051
microcontroller.
 It enters a main loop where it sends a 10 us pulse to the trigger pin of the ultrasonic
sensor and waits for the echo pin to go high.
 It starts and stops the timer 0 based on the echo pin and calculates the distance in cm
using the formula: distance = (timer 0 / 59).
 It displays the distance on the 7 segment display by sending the binary data for each
digit to the data pin and toggling the clock, latch, and enable pins accordingly.
 It repeats the main loop indefinitely.

The program uses some functions and variables that are explained below:

 delay1(): This function provides a 10 us delay by using a loop with a delay count of
45.
 delay(): This function provides a 1 ms delay by using a loop with a delay count of
250.
 display(): This function displays the digit drive pattern for the content in the
accumulator by using the lookup table and complementing the pattern.
 LUT: This is an array that contains the digit drive patterns for the digits 0 to 9 in
hexadecimal format.

15 | P a g e
 ACC: This is the accumulator register of the 8051 microcontroller that is used to store
and manipulate data.
 DPTR: This is the data pointer register of the 8051 microcontroller that is used to
access the external data memory.

RESULT:

Sl No. Scale Measured Value

1 10 010

2 20 020

3 30 030

4 40 040

5 50 050

6 60 059

7 70 069

8 80 079

9 90 089

10 100 100

11 110 109

12 120 119

13 130 129

14 140 139

15 150 149

16 160 159

17 170 169

18 180 179

19 190 189

20 200 199

16 | P a g e
21 210 209

22 220 218

23 230 228

24 240 238

25 250 247

26 260 255

GRAPH BETWEEN SCALE V/S MEASURED VALUE:

Scale vs Measured value


300

250

200

150

100

50

0
0 50 100 150 200 250 300

CALCULATIONS :

17 | P a g e
The formula for distance using HC-SR04 ultrasonic sensor is:

distance in cm = (time in us / 58)

The time in microseconds is the time taken by the ultrasonic wave to hit the object and return
back to the receiver which can be obtained by using the a timer of 10us.

where time in us is the time difference between the trigger pulse and the echo signal in
microseconds, and 58 is a constant factor that converts the time to distance based on the
speed of sound (340 m/s) and the round-trip of the sound wave.

This formula assumes that the air temperature is 20°C and the air pressure is normal. If the air
temperature or pressure changes, the speed of sound will also change, and the formula will
need to be adjusted accordingly.

PRECAUTIONS:

 Make sure the power supply is stable and within the range of 5V for both the sensor
and the microcontroller.
 Avoid placing the sensor near any loud noise sources or reflective surfaces, as they
may interfere with the accuracy of the measurement.
 Ensure that the sensor is mounted at a proper angle and height, and that there are no
obstacles in front of the sensor within the minimum and maximum range.
 Use proper connectors and wires to interface the sensor, the microcontroller, and the
display module. Avoid loose connections and short circuits.
 Test the circuit and the code before using it for any practical applications. Debug any
errors or issues that may arise.

ADVANTAGES:

 The project is low-cost and easy to implement using readily available components and
code.
 The project can measure the distance of an object from 4 cm to 255 cm with an
accuracy of 0.3 cm using sound waves.
 The project can display the distance on a 7 segment display module using a simple
interface and logic.

18 | P a g e
 The project can be used for various applications, such as obstacle detection, parking
sensor, liquid level measurement, etc.

DISADVANTEGES:

 The project is sensitive to variations in temperature, as they affect the speed of sound
and the accuracy of the measurement.
 The project has difficulties in reading reflections from soft, curved, thin, and small
objects, as they may absorb or scatter the sound waves.
 The project has a limited range and angle of measurement, as the sensor has a
minimum and maximum distance and a 15 degree cone of detection.
 The project requires careful calibration and alignment of the sensor and the display
module, as well as proper wiring and coding.

FUTURE SCOPE:

 The range can be considerably increased by using a high-power drive circuit.


 Using temperature compensation, it can be used over a wide temperature range.
 The resolution of the measurement can be improved by incorporating phase shift
method along with time-of-flight method.
 The project can be integrated with other sensors, such as infrared, laser, or camera, to
enhance the accuracy and reliability of the measurement.
 The project can be modified to measure the speed, direction, or angle of the object, as
well as the distance.
 The project can be used for various applications, such as obstacle detection, parking
sensor, liquid level measurement, etc.

19 | P a g e

You might also like