You are on page 1of 69

University of KwaZulu-Natal

School of Electrical, Electronic and Computer Engineering

Electrical Design Project


ENEL4EP

Design Project title:


Design and Implementation of Non-Contact Tachometer for Speed
Measurement of Electrical Motor
Phase three: Final report
Supervisor: Dr R. Tiako

SMANGALISO P. MAGWAZA
215020390
Discipline of Electrical, Electronic and Computer Engineering
Electrical Engineering Design Project - 2018
Phase 2: Interim ELO Evidence (Student submission)
Student name: Smangaliso P. Magwaza Student number: 215020390
Project title: Design and Implementation of a Non- Contact Tachometer for Speed Measurement of Electrical Motor

Table 1a: ELO1 - Problem solving: Identify, formulate, analyse and solve complex engineering problems creatively and innovatively

Assessment criteria Location of evidence samples for each item

1. The problem is defined and the criteria for an acceptable solution are identified.  Problem description of the project (page 1).
 Principle of operation (page 3).
 Software design of the system (page 7-8)

2. Relevant information, engineering knowledge and skills are identified for solving the problem.  Literature review (page 1-3).
 Working principle of IR sensors (page 4-5).
 Physics behind infrared radiation (page 5-6)

 Problem description of the project (page 1).


3. Various approaches are considered and formulated.  Design alternative solutions (page 11).
 Software design of the system (page 7-8)
 Principle of operation (page 3).

4. Solutions are assessed in terms of strengths and weaknesses.  Problem description of the project (page 1).
 Design alternative solutions (page 11).

 Principle of operation (page 3).
5. Solutions are prioritised and a feasible solution is selected.
 Design alternative solutions (page 11).

Student Name: Smangaliso P. Magwaza Student Signature: Date:12/10/2018


Discipline of Electrical, Electronic and Computer Engineering
Electrical Engineering Design Project - 2018
Phase 2: Interim ELO Evidence (Student submission)
Student name: Smangaliso P. Magwaza Student number: 215020390
Project title: Design and Implementation of a Non- Contact Tachometer for Speed Measurement of Electrical Motor

 Software design of the system (page 7-

Table 1b: ELO2 - Application of scientific and engineering knowledge: Apply knowledge of mathematics, natural sciences, engineering fundamentals and an
engineering speciality to solve complex engineering problems.

Assessment criteria Location of evidence samples for each item

1. An appropriate mix of fundamental principles and laws of mathematics, natural and engineering Working principle of IR sensors (page 4-5).
science is brought to bear on the solution of narrowly-defined engineering problems. Physics behind infrared radiation (page 5-6)
Design calculations and IR sensor circuit
(page 6-7)
 Software design of the system (page 8)
 Principle of operation (page 3).
2. Appropriate engineering materials, components or processes are selected with reasoning.  LCD display (page 8).
 Buzzer(page 10).

3. The boundaries of the practice area are identified and work is performed therein.  Physics behind infrared radiation (page 5-6)
 Working principle of IR sensors (page 3-4)
 Software design of the system (page 8)
 Sensitivity of IR sensor

Table 1c: ELO3 - Engineering design: Perform creative, procedural and non-procedural design and synthesis of components, systems, engineering works,
products or processes.

Student Name: Smangaliso P. Magwaza Student Signature: Date:12/10/2018


Discipline of Electrical, Electronic and Computer Engineering
Electrical Engineering Design Project - 2018
Phase 2: Interim ELO Evidence (Student submission)
Student name: Smangaliso P. Magwaza Student number: 215020390
Project title: Design and Implementation of a Non- Contact Tachometer for Speed Measurement of Electrical Motor

Assessment criteria Location of evidence samples for each item


 Sensitivity of IR sensor (page 9-10)
1. The solution is formulated to satisfy user needs, standards, codes of practice and legislation.  IR sensors simulation result(page12-14)
 Non-contact Tachometer simulation
result(page15-18)
 Analysis of simulation results(page 19)

2. The design process is recognises and deals with constraints.  Design specification (page 1)
 IR sensors simulation result (page 12-14)
 Non-contact Tachometer simulation result
(page 15-18)
 Software design of the system (page 7-8)

3. Necessary knowledge, information and resources are acquired to provide a solution.  Literature review (page 1-3).
 Working principle of IR sensors (page 3-4)
 Sensitivity of IR sensor(page)
 Physics behind infrared radiation (page 5-6)
 Design calculations and IR sensor circuit (page 6-
7)
 Design calculations and IR sensor circuit (page 6-
4. Design tasks are performed that include component testing to relevant premises, assumptions 7)
and constraints.  Sensitivity of IR sensors (page 9)
 Non-contact Tachometer simulation

Student Name: Smangaliso P. Magwaza Student Signature: Date:12/10/2018


Discipline of Electrical, Electronic and Computer Engineering
Electrical Engineering Design Project - 2018
Phase 2: Interim ELO Evidence (Student submission)
Student name: Smangaliso P. Magwaza Student number: 215020390
Project title: Design and Implementation of a Non- Contact Tachometer for Speed Measurement of Electrical Motor

result(page15-18)
 IR sensors simulation result (page 14-16)

Student Name: Smangaliso P. Magwaza Student Signature: Date:12/10/2018


Abstract
This report paper discusses the design process of a non-contact tachometer for speed
measurement of electrical motor at given design specification. The design process includes the
problem description of the project, feasibility study of non-contact tachometer and clearly
discussion of design specification. This non-contact tachometer system uses infrared sensors (IR
sensor) to sense to rotational speed. The Atmega16/30 microcontroller and C programming
language is used in the software design of system. The measured rotational speed is displayed on
a LCD display module. This report also covers the simulation results of IR sensors circuit using
Multisim simulating tool, and non-contact tachometer system using Proteus simulating tool. The
alternative solutions of the design of non-contact tachometer are also covered. This report also
covers the study of analysis of the sensitivity of IR sensor. This paper covers the practical results
of IR sensor circuit, non-contact tachometer system and the analysis of sensitivity of IR sensors.
The project management is discussed.

i|Page
List of figures
Figure 1: IR transmitter...................................................................................................................4
Figure 2: IR Receive........................................................................................................................4
Figure 3: Working principle of IR sensor........................................................................................5
Figure 4: Electromagnetic spectrum [8]..........................................................................................5
Figure 5 : Circuit of IR sensor.........................................................................................................6
Figure 6 : Example of square wave signal from IR sensor to microcontroller................................8
Figure 7 : Software design block diagram.......................................................................................8
Figure 8: Further block diagram of the software design..................................................................9
Figure 9 : LCD pin out diagram....................................................................................................10
Figure 10 : Relationship between resistance and voltage on IR transmitter.................................11
Figure 11: Relationship between distance and resistance. [7].......................................................11
Figure 12: Buzzer circuit diagram.................................................................................................12
Figure 13: Circuit diagram of Hall Effect[3].................................................................................12
Figure 14: Simulation model of the IR sensor...............................................................................13
Figure 15 : Square wave at 30 Hz..................................................................................................14
Figure 16 : Square wave at 40 H...................................................................................................14
Figure 17: Square wave at 50Hz....................................................................................................15
Figure 18: Square wave at 60 Hz...................................................................................................15
Figure 19: Simulation model of Non-Contact Tachometer...........................................................16
Figure 20: Result when speed measured is less than 600 rpm......................................................17
Figure 21: Result when speed measured is great that 3600 rpm...................................................17
Figure 22: Speed at frequency of 10 Hz........................................................................................18
Figure 23: Speed measured at the frequency of 30 Hz..................................................................19
Figure 24 : Speed measured at the frequency of 60 Hz.................................................................19
Figure 25 : IR sensor circuit..........................................................................................................21
Figure 26: controller circuit...........................................................................................................22
Figure 27: Display circuit..............................................................................................................23
Figure 28 : Buzzer and LED circuit...............................................................................................24
Figure 29: 12V DC motor..............................................................................................................25
Figure 30: 5V rechargeable battery...............................................................................................25
Figure 31: Alternative power supply.............................................................................................26
Figure 32: IR sensor circuit practical test setup.............................................................................27
Figure 33: IR sensor output signal when measures motor speed running at 0.22V......................28
Figure 34 : IR sensor output signal when measures motor speed running at 2.1 V......................28
Figure 35: IR sensor output signal when measures motor speed running at 3.34 V.....................29
Figure 36: IR sensor output signal when measures motor speed running at 5V...........................29
Figure 37: Non tachometer practical test setup.............................................................................30
Figure 38: When the speed measured is less than 600 rpm...........................................................31
Figure 39: When the speed measured is greater than 3600 rpm....................................................31
Figure 40: When the speed measured is 754 rpm..........................................................................32

ii | P a g e
Figure 41: When the speed measured is 1225 rpm........................................................................32
Figure 42: When the speed measured is 1542 rpm.......................................................................33
Figure 43: When the speed measured is 1810 rpm........................................................................33
Figure 44 : When the speed measured is 2040 rpm.......................................................................34
Figure 45: When the speed measured is 2908 rpm........................................................................34
Figure 46: Sensitivity of IR sensor investigation set up................................................................35
Figure 47: Results when the distance between the pairs is 0 cm...................................................36
Figure 48: Results when the distance between the pairs is 0.5 cm................................................36
Figure 49: Results when the distance between the pairs is 1.5 cm................................................37
Figure 50: Results when the distance between the pairs is 2.5 cm................................................37
Figure 51: Results when the distance between the pairs is 4 cm...................................................38
Figure 52: Current price of non-contact tachometer in a market...................................................42

List of tables
Table 1 : List of components...........................................................................................................3
Table 2: Relationship between frequency of the square wave and the speed measured and
displayed........................................................................................................................................20
Table 3: Results from sensitivity of IR sensors practical test........................................................38
Table 4: Results of comparison of rotational speed measured using UT372 non-contact
tachometer and the designed non-contact tachometer...................................................................39

iii | P a g e
List of Abbreviation
Abbreviation Meaning
V Volts
I Current
A Amperes
R Resistance
Ω Ohms
P Power
W Watts
LED Light Emitting Diode
LCD Liquid Crystal Display
RPM Revolution Per Minutes
RPS Revolution Per Second
IR sensor Infrared sensor
T Temperature
λ Wavelength
F Frequency
Hz Hertz
Op Amp Operational Amplifier
RF Radio Frequency
GSM Global Standards for Mobile Communication

Content
1. Introduction.........................................................................................................................................1

iv | P a g e
Problem description of the project..........................................................................................................1
Design specifications...............................................................................................................................1
Literature review.....................................................................................................................................1
2. Design system description...................................................................................................................3
Principle of operation..............................................................................................................................3
Working principle of Infrared sensors (IR sensor)..................................................................................4
Physics behind Infrared radiation...........................................................................................................5
Design calculations and IR sensor circuit...............................................................................................6
Software design of the system..................................................................................................................7
LCD display module..............................................................................................................................10
Sensitivity of IR sensor..........................................................................................................................10
Buzzer....................................................................................................................................................12
Design alternative solutions..................................................................................................................12
3. Simulation result................................................................................................................................13
IR sensors result....................................................................................................................................13
Non-contact Tachometer result.............................................................................................................16
4. Analysis of simulation results............................................................................................................20
1. IR sensors......................................................................................................................................20
Non-contact tachometer........................................................................................................................20
5. Practical design procedure.................................................................................................................21
IR sensor circuit....................................................................................................................................21
Controller circuit...................................................................................................................................22
Display unit...........................................................................................................................................23
System testing equipment.......................................................................................................................24
Power supply of the system....................................................................................................................25
6. IR sensor circuit practical results.......................................................................................................27
7. Non-contact Tachometer Practical results.........................................................................................30
8. Sensitivity of IR sensor practical tests...............................................................................................35
9. Analysis of Practical results...............................................................................................................39
IR sensors circuit practical results........................................................................................................39
Non-contact tachometer practical results..............................................................................................39
Sensitivity of IR sensor practical tests...................................................................................................40
10. Project management.......................................................................................................................40

v|Page
Budget plan...........................................................................................................................................40
Breakeven analysis................................................................................................................................41
11. Conclusion.....................................................................................................................................43
12. References.....................................................................................................................................43
13. Acknowledgment...........................................................................................................................44
14. Appendix.......................................................................................................................................44

vi | P a g e
1. Introduction
Tachometer is the measuring instrument used to measure rotating speed in a form of rotating
shaft in a machine usually like motor. The first mechanical Tachometer was designed using the
method of measuring the centrifugal force. The method of measuring the centrifugal force was
adapted for the measurement of speed of the machines, around the year 1817. The tachometers
are mostly used in controlling and monitoring the speed of motor, turbines, conveyors, etc. [1]
There are two main types of tachometer, namely contact and non-contact tachometer. Contact
tachometer is the tachometer that is physically attached to a rotational speed object being
measured, usually object like shaft of the electrical motor. Non-contact tachometer is the type of
tachometer that measures the speed of a rotational object without physically touching an object,
this is done using sensors like infrared sensors or hall effect sensor.

Problem description of the project


The method of physical counting the number of revolutions per second or minute is a strenuous
activity and requires lots of time. Therefore, this method evaluated to be not effective, and
associated with errors in determining the correct and accurate rotational speed.
Since contact tachometer is the tachometer that is physically attached to a rotational speed object
being measured. This method is evaluated to have problems of inaccuracy in speed measured and
has raised uncertainty in using the method. Therefore, non-contact tachometer is design to
improve and solve the problem of inaccuracy in speed measurement.

Design specifications
I am required to design and implement the non-contact tachometer. This tachometer measures
the rotational speed between 600 rpm ¿3600 rpm.The rotational speed will be measured using
Infrared sensors (IR sensors). Since It is a non-contact tachometer, the working distance between
the tachometer and the object must be between 5 mm ¿ 100 mm. Atmega16 microcontroller and C
language are used as a software design of the system. The speed measured must be displayed on
the 16 ×2 LCD module.

Literature review
This section covers the feasibility study of historical related project.
Nitin Singh, Raghuvir S. Toma worked on “Design of a Low-Cost Contact-Less Digital
Tachometer with Added Wireless Feature”
This paper proposes a hardware design of an “Digital Contact-less Tachometer” based on
IR sensor for measuring the Revolutions Per Minute of a rotating object. Contact
tachometers require physical contact with the rotating object, and this method affect the
accuracy of the tachometer. This Tachometer design is considered as non-contact
tachometer because it allows the measurement of the speed without physical contact with
the rotating object. To ensure stability and accuracy, a new method is also discussed in
this report, and it allows the results to be displayed every second. This method is also
able to send RF signals which ensures that the measured values to a distant place is sent
1|Page
for its further processing. The radio frequency feature makes it easier for the data logging
for monitoring and controlling the variable values of the RPM. The circuit design is
simple, cheap and provide reliable results. Its stability and reliability have been proven
through practical testing. [3]

Salice Peter and M.N Naveen worked on “Design of a Contactless Tachometer”


 This report paper discusses the design of non-contact tachometer. This tachometer is used
to measure a rotational speed of motor or shaft. The software design of this tachometer is
done using ATMega16 micro-controller. It uses the method of measuring time interval to
ensure accuracy. The Important aspect of this tachometer is that, it measures speed
without being in contact directly with shaft or motor. The system displays the speed in
RPS on the LCD display, and the settings can be controlled throng buttons. This
tachometer uses infrared sensors to ensure low cost. It can measure RPS speed up to the
higher speeds. [2]

Nikhil Kumar and Harshit Morwal worked on “Contactless IR Tachometer”


 This research paper covers the design of non-contact tachometer using IR sensors. Non-
contact tachometer is mostly used in automotive. This tachometer measures the speed in
RPM. The attractive part of the design is that it can measure the speed of a shaft of the
motor without physical contact. This system consists of a microcontroller, a LCD
module, a battery and infrared sensor. If proximity sensor is used in the design, the
counted pulses will detect any reflective element passing in front of it, and this will give
an output pulse for every rotation of the shaft. Those pulses which we get from every
rotation of the shaft will be fed to the microcontroller and counted. [5]
Prateek Mishra and Shikhar Pradhan worked on “Contactless Tachometer with Auto Cut Off”
 This paper provides a detailed method to develop and implement a non-contact
tachometer. Higher voltage surge occurs due to failure to power regulation devices. The
solution to these issues was to monitor the speed of the motor, this system is used to
monitor the running of the motor. This system can be used anywhere from industries to
homes and also from long distances by using a GSM (Global Standards for Mobile
Communication) module. The system would send the current running status of motor to
anyone residing in any part of world. [6]

J. Kathirvelan, Babu Varghese, Ubaid A Ponnary, Fajas Kamar and Renju Thomas Jacob worked
on Hall Effect Sensor Based Portable Tachometer for RPM Measurement
 The research report discusses the design and implementation of the portable tachometer
using the hall effect sensor. The major priority was given for making a portable device,
and be a non-contact tachometer. The prototype gives a similarity with normal tach
generator which is contactable and a rotating shaft inside. A shaft which is supported and

2|Page
rotating over two bearings takes the speed in to the device. The hall element is positioned
stationary over the circuit board and the magnets are closely faced to the sensor. The
sensor used is a digital Hall Effect sensor which gives square pulses. [4]

2. Design system description


Principle of operation
This system consists of three circuit, namely IR sensors circuit, controller circuit and display
unit. IR sensor circuit is used to measure the rotational speed from a distance, or without being in
contact with the electrical motor. This is done using IR transmitter and IR receiver.
The second part of the system is the controller circuit. Atmega16/32 microcontroller is used to
receive signal from the IR sensors and process it. After the signal has been processed, it is
displayed on an LCD display. This is the design solution chosen for the project. The solution is
detailed in the following sections of the report.
Table 1 : List of components

List of electrical components or


devices used in the system
1. IR sensor pairs
2. Resistors
3. Potentiometer
4. OperationalAmplifier
(LM358)
5. LED
6. Buzzer

7. LCD display unit

8. Atmega16/32
microcontroller

3|Page
Working principle of Infrared sensors (IR sensor)
Infrared sensor is an electronic instrument used to sense a certain characteristic at their
surroundings. Infrared sensor is made up of IR transmitter and IR receiver. IR transmitter emits
infrared rays. After the infrared rays get reflected by an obstacle interferes like an object, IR
receiver receives the reflected rays.

Figure 1: IR transmitter

Figure 2: IR Receive

When the IR transmitter emits the infrared rays, it travels in the direction where it is angled.
When an object is placed in front of IR pairs, the IR rays is reflected by an object and it produces
secondary wavelets which travels in an opposite direction opposite to that of the primary waves,
which produces the reflection of infrared rays. [7]

IR receiver absorbs the reflected infrared rays, IR receiver is a two terminal PN junction device,
which operates in a reverse bias. It has a tiny transparent window, which allows light to strike the
PN junction. A photodiode is a type of photodetector capable of converting light into current or
voltage. Most photodiodes will look similar to a light emitting diode. They will have two leads,
or wires. The shorter lead of the two is the cathode/negative, while the longer lead is the
anode/positive. [7]

A photodiode consists of PN junction. When a photon of sufficient energy strikes the diode, it
excites an electron thereby creating a mobile electron and a positively charged electron hole. If
the absorption occurs in the junction's depletion region, or one diffusion length away from it,
these carriers are swept from the junction by the built-in field of the depletion region. Thus, holes
move toward the anode, and electrons toward the cathode, and a photocurrent is produced. [7]

4|Page
Figure 3: Working principle of IR sensor

Physics behind Infrared radiation


Infrared radiation is the section of electromagnetic spectrum having wavelengths smaller than
microwaves but longer than visible light wavelengths. The region that is from the wavelength of
0.75 µm to 1000 µm is called infrared region. Infrared waves are invisible to human eyes which
means they cannot be seen with naked eyes. The wavelength region of 0.75 µm to 3 µm is near
infrared, the region from 3 µm to 6 µm is called mid infrared and the region higher than 6 µm is
called far infrared. [8]

Figure 4: Electromagnetic spectrum [8]

IR sensors working in different regions of the infrared radiation spectrum but the physics
behind IR sensors is governed by three laws
1.  Planck’s radiation law
Every object at a temperature T not equal to 0 K emits radiation. Infrared radiant energy is
determined by the temperature and surface condition of an object. Human eyes cannot detect
differences in infrared energy because they are primarily sensitive to visible light energy from
400 ¿ 700 nm. Our eyes are not sensitive to the infrared energy.

5|Page
2. Stephan Boltzmann Law
The total energy emitted at all wavelengths by a black body is related to the absolute temperature
as

W b =σ ×T 4 … … …(1)

Where: -
W b =total energy emitted

σ =5.67 ×10−8 m−2 K−4 ( constant )


T =temperature of theobject
3. Wein’s Displacement Law
Wein’s Law tells that objects of different temperature emit spectra that peak at different
wavelengths. It provides the wavelength for maximum spectral radiant emittance for a given
temperature.
k 2898
λ max= = … … …(2)
T T

Radiant emittence of an object


Emissivity= body at same temperature ¿ … … …(3)
Radiant emittance of a ¿
Emissivity depends on object color, surface roughness, moisture content, degree of compaction,
field of view, viewing angle & wavelength.

Design calculations and IR sensor circuit


This covers the design calculations, components analysis and working principle of IR sensors circuit. The
IR sensor circuit consist of resistors, IR transmitter, IR receive, potentiometer, LED and
operational amplifier (voltage comparator).

6|Page
Figure 5 : Circuit of IR sensor

When an object is placed in front of IR pairs and 5 V power supply applied on the circuit, the IR
transmitter emits the infrared radiation directed to the object. The infrared radiation gets reflected
by an object and travels to the opposite direction. The IR receiver absorbs the reflected infrared
radiation. This result to drop in voltage across the IR receiver, or photodiode. Then there is an
increase in voltage across resistor R2. The voltage comparator compares the voltage at the
inverting input and non-inverting input. When voltage at non inverting input is higher than the
voltage at inverting input, then the output becomes high and LED (x4 LED) turns ON. When
there is no object place in front of IR pairs, then there is no infrared radiation absorbed by the IR
receiver or photodiode. This result to voltage comparator output being logic zero or low.
IR transmitter operates like a normal LED, it consumes 20 mA current and 3 volts power.
Therefore: -
V 1=R1 × I … … …(4)

V 1 +V LED=Vcc … … …(5)
V1
Therefore R1= … … …(6)
I
For IR transmitter protection R1 must be greater than 100 Ω. Therefore R1=150 Ω
The power consumed by an LED can computed as follows
P=V LED × I … … … …(7)

IR receiver converts the reflected rays into current. Therefore resistor R2 translate current into
voltage. Resistor R2 must be high. Resistor R4 is also chosen to be 330 Ω for protection of LED
(x4 LED).

7|Page
Software design of the system
In the software of the design of the system, Atmega16 as microcontroller and C as the
programing language is used. The microcontroller receives signal from IR sensors, and process
it, where the speed rotational speed in revolution per minute is computed. The speed is displayed
on 16 ×2 LCD module. The code used in the software design is on figure 2 in Appendix.
The microcontroller receives the signal from the IR sensor circuit in a form of a square wave.
The microcontroller atmega16 is programmed such that every time the input in the interrupt pin
(pin 16) is toggling, the interrupt is initiated. In the microcontroller, the timer triggers the
interrupt(INT0). The interrupt is responsible to counts the number of falling edges of the square
wave and sends the value to the LCD display every second. Another timer resets the counter
after each second. Therefore, we get the number of rotations per second of the motor shaft and
convert them to revolutions per minute RPM =RPS × 60.

Figure 6 : Example of square wave signal from IR sensor to microcontroller

8|Page
Figure 7 : Software design block diagram

9|Page
Figure 8: Further block diagram of the software design

10 | P a g e
LCD display module
Liquid Crystal Display (LCD) screen is an electronic display module. A 16x2 LCD display is
very basic module and is very commonly used in various devices and circuits. In this system is
also used for same function, which is to display the speed measured.

Figure 9 : LCD pin out diagram

Sensitivity of IR sensor
This section discusses the analysis the sensitivity of IR sensor. The sensitivity of sensors refers to
the degree of effectiveness of functioning of sensors. The sensitivity of IR sensor is an important
factor in the design. In IR sensor circuit, the sensitivity of IR sensors is adjusted using
potentiometer. Turning up the potentiometer increases the sensitivity of the IR sensors.
 The sensitivity of the IR sensor is influenced by the output voltage in IR transmitter. The
output voltage in the transmitter depends on the resistance in the IR transmitter and the
amount of infrared rays reflected from the object (rotational object).
This is a relationship between resistance and output voltage in infrared transmitter. the study
shows that the resistance is inversely proportional to the voltage in the infrared transmitter.

11 | P a g e
Figure 10 : Relationship between resistance and voltage on IR transmitter.

The relationship between the distance be the Infrared radiation pairs and the resistance. The
distance between the infrared pairs influences the sensitivity of IR sensors. The resistance used at
the sensor influences the intensity of the infrared radiation emitted by infrared transmitter. The
study shows that the resistance applied is inversely proportional to the distance of IR Receiver
capable to detect IR ray emitted from IR Transmitter due to lower light intensity of IR
Transmitter. [7]

Figure 11: Relationship between distance and resistance. [7]

 The distance between IR transmitter and IR receiver influences the sensitivity of the IR
sensor. The short the distance between IR transmitter and IR receiver result to higher
sensitivity of IR sensors, hence the longer distance of the object can be sensed. [8]
 The colour of the object also influences the sensitivity of the IR sensor. The white object
reflects more IR rays than a black or darker object. Hence white or lighter object result to
higher sensitivity of IR sensors.

12 | P a g e
Buzzer
A buzzer is a sound producing electronic component, which may be mechanical,
electromechanical, or piezoelectric. Buzzer is powered by a DC power source, and it is made up
of electronic transducers in structure. Buzzer is mostly used in computers, telephones, alarms,
electronic toys, automotive electronic equipment, other electronic products for sound devices. In
this design, the buzzer is used to make this non-contact tachometer more user friendly. When the
speed measured is less than 600 rpm or greater than 3600 rpm, the buzzer will be stimulated.

Figure 12: Buzzer circuit diagram

Design alternative solutions


 There are numerous design solutions to non-contact tachometer. The non-contact
tachometer can be designed using hall effect sensors. Hall effect uses magnetic field to
varies the output voltage. Hall effect sensors are mostly used for positioning, speed
detection, switching etc. they operate as a transducer in the presence of magnetic field to
determine the distance of magnetic field and hall plate. [3]
Hall effect sensors uses a rotating target attached to an electrical motor. This target may
contain magnets, or it may be a toothed wheel. The teeth on the wheel vary the flux of a
magnet inside the sensor head.
Since the hall effect sensor are highly dependent on magnet, therefore the disadvantages
of using them is that they can easily be demagnetized, and they start to lose magnetism in
high temperature.

Figure 13: Circuit diagram of Hall Effect[3]

13 | P a g e
 The measurement of rotational speed can be done contact tachometer. This is done by
physical contact of tachometer with a rotational object. However, this design method is
evaluated to have inaccurate reading of a speed and reducing the rotational speed.

 There are also many solutions in software design of non-contact tachometer. This
tachometer can also be designed using the solution of Arduino Uno. The equipment for
Arduino Uno is expensive compared to Atmega16/30 microcontroller.

3. Simulation result
IR sensors result
This is the simulation of IR sensor circuit using multisim-simulating tool. The IR sensor circuit
consist of resistors, IR transmitter, IR receive, potentiometer, LED and operational amplifier
LM358AD.

Figure 14: Simulation model of the IR sensor

The results of IR sensor are the square wave at a certain frequency. The frequency corresponds
to the rotational speed measured. The following results shows the rotational speed measured at a
frequency of 30 Hz, 40 Hz, 50 Hz and 60 Hz.

14 | P a g e
Rotational speed at frequency of 30Hz

Figure 15 : Square wave at 30 Hz

Rotational speed at frequency of 40Hz

Figure 16 : Square wave at 40 H

15 | P a g e
Rotational speed at frequency of 50Hz

Figure 17: Square wave at 50Hz

Rotational speed at frequency of 60Hz

Figure 18: Square wave at 60 Hz

16 | P a g e
Non-contact Tachometer result
This section covers the simulation result of the non-tachometer system, simulated using Proteus
simulating tool. The simulation consists of two LED, clock with variable frequency,
microcontroller Atmega16/30 and LCD module. Clock represent the output signal from the IR
sensor.
This non-contact tachometer is design to measure the rotational speed between
600 rpm ¿3600 rpm, therefore to make this tachometer be user friendly, the system is further
designed to indicate when the speed is below or above the range. When the speed is less than
600 rpm, the LED D2 light up and the message “Speed below minimum” is displayed on LCD.
When the speed is above the 3600 rpm, LED D1 light up and the message “Speed above
maximum” is displayed on LCD.

Figure 19: Simulation model of Non-Contact Tachometer

17 | P a g e
When the speed measured is less than 600 rpm, the results are shown in figure 19.

Figure 20: Result when speed measured is less than 600 rpm

When the speed measured is great than 3600 rpm, the results are shown in figure 20.

Figure 21: Result when speed measured is great that 3600 rpm

18 | P a g e
The system is designed such that the clock with a variable frequency represent the output signal
from IR sensor, so the frequency represents the speed in revolution per minutes. The
microcontroller receives the signal and process it. In the microcontroller the method of counter
and timers is used to process the signal into the speed in revolution per seconds, the
microcontroller further computes the speed into revolution per minute RPM =RPS × 60
When speed measured is 600 rpm. This minimum speed, this tachometer can measure. shown in
figure 21.

Figure 22: Speed at frequency of 10 Hz

19 | P a g e
When speed measured is 1800 rpm. Results shown in figure 22.

Figure 23: Speed measured at the frequency of 30 Hz

20 | P a g e
When speed measured is 3600 rpm. This maximum speed, this tachometer can measure. Results
shown in figure 21.

Figure 24 : Speed measured at the frequency of 60 Hz

4. Analysis of simulation results


This section covers the analysis and discussion of simulation results of IR sensor circuit and non-
contact tachometer system.
1. IR sensors
The frequency is equivalent to the total number of falling edges in the square wave in second.
The number of the falling edges in a square wave represent the number of revolutions of the
rotational speed. At higher frequency, the output square wave is narrower. At lower frequency,
the output wave is wider in width.
The sensitivity of the IR sensors is influenced by the colour of the object and the distance
between the IR pairs. Therefore, to measure the rotational speed of the object at longer distance,
the distance between the IR pairs must smaller, and the colour of the object must be white or
lighter. This analysis satisfies the design specification of a working distance of 5 mm ¿ 100 mm.

Non-contact tachometer
This non-contact tachometer is design to measure the rotational speed between
600 rpm ¿3600 rpm. When the speed is less than 600 rpm, the LED D2 light up and the message
“Speed below minimum” is displayed on LCD. When the speed is above the 3600 rpm, LED D1
light up and the message “Speed above maximum” is displayed on LCD. The clock with a

21 | P a g e
variable frequency represents the output signal from IR sensor. The frequency is directly
proportional to both revolutions per minute and revolutions per seconds.
Table 2: Relationship between frequency of the square wave and the speed measured and displayed.

The frequency of the square from IR sensor Rotational speed measured and displayed on
circuit (Hz) the LCD display (RPM)
10 600
20 1200
30 1800
40 2400
50 3000
60 3600

5. Practical design procedure


This section of the report discusses the practical design procedure of the non-contact tachometer
system. Initially, the IR sensor circuit is designed and implemented. On the IR sensor circuit, the
test is conducted to ensure that the circuit gives the output of the square wave when the electrical
motor is placed in front of IR sensor pairs on the circuit. The output square wave is viewed using
the digital oscilloscope. The output square wave is used to initiate the interrupt in the Atmega16
microcontroller. The output of IR sensor circuit is connected at interrupt pin (pin 16).
Secondly, the code shown at the appendix is loaded on microcontroller Atmega16 using eXtreme
burner software. Then the configuration of Atmega16 microcontroller with 2 ×16 LCD display is
done.

IR sensor circuit
 IR transmitter (blue LED) emits infrared radiation.
 IR receiver (white LED) absorbs the reflected infrared radiation.
 Normal LED (green LED) turns ON when the object is sensed.
 Potentiometer controls the sensitivity of the sensors.
 Resistors acts as a protection for LED.

22 | P a g e
 Operational amplifier acts voltage comparator

Figure 25 : IR sensor circuit

Controller circuit
This circuit contains Atmega16 controller programmed using C programming language.
Microcontroller receives the signal from IR sensor circuit. The signal is processed and sent to the
display unit.

23 | P a g e
Figure 26: controller circuit

Display unit
The 2 ×16 LCD display receives the information from the microcontroller and displays it.

24 | P a g e
Figure 27: Display circuit

There are additional subsystems for indication when the speed measures the rotational speed
below the minimum of 600 rpm and above maximum of 3600 rpm. The aim of these subsystems
is to make the design more user friendly and less complicated. These subsystems are made up of
circuit for buzzer and LED. The 5v buzzer turns ON and the LED flashes each time the
tachometer measures the speed outside the boundaries of a design specification, which is
between 600 rpm and 3600 rpm.

25 | P a g e
Figure 28 : Buzzer and LED circuit

System testing equipment


This non-contact tachometer is designed to measure a rotational speed between 600 rpm and
3600 rpm of an electrical motor, hence this tachometer is designed to measure low speeds. For
testing this speed measurement system, a 12 V DC motor is used. The rotational speed of this
motor is dependent on the input voltage. This motor is used to measure its speed at certain input
voltage.

26 | P a g e
Figure 29: 12V DC motor

Power supply of the system


This non-contact tachometer system works with low voltage, the system is supplied with 5 V .
This tachometer is designed to be portable, therefore 5 V rechargeable battery is used as a power
supply of the system. This supply provides a stable and DC voltage.

Figure 30: 5V rechargeable battery

27 | P a g e
The other power supply alternative when the rechargeable battery is discharged, the power
supply of 5 V using rectification design where the AC power from the mains is converted to a
stable DC voltage.

Figure 31: Alternative power supply

28 | P a g e
6. IR sensor circuit practical results
The section discusses the practical result of IR sensor circuit using the 12 V DC motor as the
testing equipment. The output signal of IR sensor circuit is square wave. The results are recorded
from the digital oscilloscope. The speed of the electrical motor is changed through the input
voltage, and the behavior of the square wave is observed and recorded. The square wave is
recorded at 0.92 V , 2.1 V , 3.34 V and 5 V . White paper was attached on the shaft of the motor.

Figure 32: IR sensor circuit practical test setup

29 | P a g e
The output of IR sensor circuit when the electrical motor is running at the input voltage of 0.22 V

Figure 33: IR sensor output signal when measures motor speed running at 0.22V

The output of IR sensor circuit when the electrical motor is running at the input voltage of 2.1 V

Figure 34 : IR sensor output signal when measures motor speed running at 2.1 V

30 | P a g e
The output of IR sensor circuit when the electrical motor is running at the input voltage of 3.34 V

Figure 35: IR sensor output signal when measures motor speed running at 3.34 V

The output of IR sensor circuit when the electrical motor is running at the input voltage of 5 V

Figure 36: IR sensor output signal when measures motor speed running at 5V

31 | P a g e
7. Non-contact Tachometer Practical results
This section covers the practical results of non-contact tachometer. This practical test setup
consist of non-contact tachometer designed, UT372 non-contact tachometer, 12 V DC motor,5 V
rechargeable battery to supply the system, and 30 V variable power supply to power the motor. In
this test, the rotational speed of a DC motor is measured using the designed non-contact
tachometer, and the speed measured using UT372 non-contact tachometer are compared.
This non-tachometer is designed to measure the rotational speed of a motor between 600 rpm and
3600 rpm and displays it on a 2 ×16 LCD display. When the measured speed is less than 600 rpm
, the system displays “Speed below minimum” and when the speed measured is greater than
3600 rpm, the system displays “Speed above maximum”. The UT372 non-contact tachometer
measures the rotational speed from 10 rpm to 99999 rpm.

Figure 37: Non tachometer practical test setup

32 | P a g e
When the speed measured is less than 600 rpm, the results are shown in figure 38 below.

Figure 38: When the speed measured is less than 600 rpm

When the speed measured is greater than 3 600 rpm, the results are shown in figure 39 below.

Figure 39: When the speed measured is greater than 3600 rpm

33 | P a g e
When speed measured by UT372 is 754 rpm. The designed tachometer measures 720 rpm. the
results are shown on figure 40 below.

Figure 40: When the speed measured is 754 rpm

When speed measured by UT372 is 1225 rpm. The designed tachometer measures 1020 rpm. the
results are shown on figure 41 below.

Figure 41: When the speed measured is 1225 rpm

34 | P a g e
When speed measured by UT372 is 1542 rpm. The designed tachometer measures 1560 rpm. the
results are shown on figure 42 below.

Figure 42: When the speed measured is 1542 rpm

When speed measured by UT372 is 1810 rpm. The designed tachometer measures 1800 rpm. the
results are shown on figure 43 below.

Figure 43: When the speed measured is 1810 rpm

35 | P a g e
When speed measured by UT372 is 2040 rpm. The designed tachometer measures 2040 rpm. the
results are shown on figure 44 below.

Figure 44 : When the speed measured is 2040 rpm

When speed measured by UT372 is 2908 rpm. The designed tachometer measures 2880 rpm. the
results are shown on figure 45 below.

Figure 45: When the speed measured is 2908 rpm

36 | P a g e
8. Sensitivity of IR sensor practical tests
This section discusses the practical investigation of the sensitivity of IR sensor. The investigation
is about the relationship between the distance between the IR pairs and the maximum distance
between the IR sensors and the object being sensed. The investigation set up consists of IR
sensor circuit connected on the breadboard, ruler to measure the distances, 5v rechargeable
battery to power up the IR sensor circuit and white paper used as boundary object. The test was
done by setting up the distance between the IR pairs and measure the maximum distance
between the IR sensors and the object being sensed. The yellow LED light up to show that the
object is sensed. The test was conducted at room temperature environment.

Figure 46: Sensitivity of IR sensor investigation set up

37 | P a g e
When the distance between the IR pairs is 0 cm, the maximum distance between the IR sensors
and the object being sensed is 12.1 cm. The result is shown in figure 37 below.

Figure 47: Results when the distance between the pairs is 0 cm

When the distance between the IR pairs is 0.5 cm, the maximum distance between the IR sensors
and the object being sensed is 11.5 cm. The results are shown in figure 38 below.

Figure 48: Results when the distance between the pairs is 0.5 cm

38 | P a g e
When the distance between the IR pairs is 1.5 cm, the maximum distance between the IR sensors
and the object being sensed is 10.2 cm. The results are shown in figure 39 below.

Figure 49: Results when the distance between the pairs is 1.5 cm

When the distance between the IR pairs is 2.5 cm, the maximum distance between the IR sensors
and the object being sensed is 8.3 cm. The results are shown in figure 40 below.

Figure 50: Results when the distance between the pairs is 2.5 cm

39 | P a g e
When the distance between the IR pairs is 4 cm, the maximum distance between the IR sensors
and the object being sensed is 5.4 cm. The results are shown in figure 41 below.

Figure 51: Results when the distance between the pairs is 4 cm

The results in a table form.


Table 3: Results from sensitivity of IR sensors practical test.

Distance between the IR pairs(cm) Maximum distance between the IR sensors


and the object being sensed(cm)
0 12.1

0.5 11.5

1.5 10.2

2.5 8.3

4 5.4

40 | P a g e
9. Analysis of Practical results
This section covers the analysis and discussion of the practical of the IR sensors circuit, non-
contact tachometer and sensitivity of IR sensors.

IR sensors circuit practical results


The IR sensor circuit is used to sensor the rotational object. The output signal of IR sensor circuit
is a square wave. This test was done using 12 V DC motor. The input voltage of the motor is
directly proportional the speed of the motor. The motor was place in front of the IR pairs. The
input voltage of the motor was varied.
As the input voltage of motor is increases, the speed of the motor also increases, and the output
square of the IR sensor circuit moves faster, and the square wave becomes small. At the lower
input voltage of the motor, the speed of the motor is slow, and the output square wave is wider in
width. At a higher input voltage of the motor, the speed of the motor is faster, and the output
square wave of the IR sensor is narrower.

Non-contact tachometer practical results


This non-tachometer is designed to measure the rotational speed of a motor between 600 rpm and
3600 rpm and displays it on a 2 ×16 LCD display. The UT372 non-contact tachometer measures
the rotational speed from 10 rpm to 99999 rpm, the working distance between 50 mm and
200 mm, and it is used to test the accuracy and effectiveness of the designed non-contact
tachometer by comparing the measured speed of DC motor running at varied input voltage. For
often measurements of speed, the speed measured using UT372 non-contact tachometer is
slightly higher than the speed measured using the designed tachometer.

Table 4: Results of comparison of rotational speed measured using UT372 non-contact tachometer and
the designed non-contact tachometer

Speed measured using UT372 non-contact Speed measured using the design non-contact
tachometer (RPM) tachometer (RPM)
52 “Speed below minimum”
754 720
1225 1020
1542 1560
1810 1800
2040 2040
2908 2880
5689 “Speed above maximum”

41 | P a g e
Sensitivity of IR sensor practical tests
The test was done by setting up the distance between the IR pairs and measure the maximum
distance between the IR sensors and the object being sensed. As the distance between the IR
pairs increases, the maximum distance between the IR sensors and the object being sensed
decreases. In conclusion, the higher sensitivity of the IR sensors is achieved by setting the IR
pairs so close to each other, at the distance of zero.

10. Project management


This section covers the management of the project. The project management consists of budget
plan and breakeven analysis of the project.

Budget plan
Labour Costs
Time (hour) Cost per hour Cost (Rands)
(Rands)
Design and 3 100 300
calculation of the
Tachometer
Design simulation 5 100 500

PCB Design 2 50 100

Microcontroller 4 50 250
Coding
Prototype Building 6 150 600

Total Labour Cost 1 700

Design Components Cost


Per Unit Cost Quantity Cost (Rands)
(Rands)
IR sensors 12.00 1 12.00

Atmega16/32 51.39 1 51.39


microcontroller
LCD display 148.74 1 148.74
LED 1.00 2 2.00
Resistors 1.00 6 6.00
Potentiometer 3.00 1 3.00
Operational Amplifier 5.00 1 5.00

42 | P a g e
Jumper wires 35.40 1 35.40
Dc motor (for testing) 215.46 1 215.46

Design component 478.99


cost

Other Design Costs


Per Unit Cost Quantity Cost (Rands)
(Rands)
Transportation 100 1 100
(travelling)
Equipment 70 1 70
maintenance
Power costs 5 1 5
Total Other Design 175
Cost

Breakeven analysis

Figure 52: Current price of non-contact tachometer in a market

Selling Price (Rand) 1600


Quantity 100
43 | P a g e
Task Per unit cost Number of units Costs (R)
Design and 300 1 300
calculation of a
Buck
Design 500 1 500
simulation
PCB Design 100 1 100
Microcontroller 150 1 150
coding
Component total 479.00 100 47 900
cost
Transportation 100 1 100
(travelling)
Equipment 70 3 210
Power cost 5 100 100
Building of 600 100 60 000
prototype
Total cost 109 360
Total sales 1600 100 160 000
Profits / loss 50 640 profit

In the breakeven analysis, it was discovered that this non-contact tachometer could be able to
compete in the market and make a good profit, given that the design process costs are followed
as they are discussed in the budget plan. The estimated profit is R 50 640 per 100 sales.

11. Conclusion
Under the specification given, feasibility study discussed, design calculation performed, system
analyzed, simulation performed, and simulation result recorded. The non-contact tachometer
using infrared sensor (IR sensors) can be design and operate as expected in practical conditions.
The challenge in the design process of non-contact tachometer is that the system does not have
44 | P a g e
much mathematical description because of the nature of the project. In simulation result analysis,
the frequency is equivalent to the total number of falling edges in the square wave in second. At
higher frequency, the output square wave is narrower and at lower frequency, the output wave is
wider in width. The sensitivity of the IR sensors is influenced by the colour of the object and the
distance between the IR pairs. The comparison of UTS372 non-contact tachometer and the
designed tachometer is slightly the same for measuring the rotational speed in RPM. Practically
the distance between the IR pairs is inversely proportional to the sensitivity of IR sensors. In a
market, this tachometer has a potential of generating an estimated profit is R 50 640 per 100
sales, given the design process is followed as in this report paper.

12. References
1. D. Tisaj, "Design and Construction of a Tachometer," Murdoch University , Perth,
Western Australia , 2014.
2. P. Salice, N. Naveen. (2014). Design of a Contactless tachometer. International Journal
of Advanced Research in Electrical, Electronics and Instrumentation Engineering
(IJAREIE), 7663 – 7665

3. N. Singh, R. T. (2013). Design of a Low-Cost Contact-Less Digital Tachometer with


Added Wireless Feature. International Journal of Innovative Technology and Exploring
Engineering (IJITEE), 21-23.

4. J. Kathirvelan, "Hall Effect Sensor Based Portable Tachometer for RPM Measurement,"
International Journal of Computer Science and Engineering Communications-, vol.2, no.
1 February 2014, pp. 100-105, 2014

5. N. Kumar, H. Morwal. (2018). Contactless IR Tachometer. IJARIIE, 45- 49.

6. P. Mishra, S. Pradhan, Contactless Tachometer with Auto Cut Off. (2017). International
Research Journal of Engineering and Technology (IRJET), 369 - 371.

7. B. S. Teknikal, B.A. Sekitar. (2016). Sensitivity Range Analysis of Infrared (IR)


Transmitter & Receiver Sensor to Detect Sample Position in Automatic Sample Changer.
Bangi, Malaysia.

8. R. K Mollah. (2016). Effect of Infrared Radiation on Coloured surface . International


Journal of Physics and Applications. , 59-64

9. R. Bonert, "Design of a High-Performance Digital Tachometer with a Microcontroller,"


IEEE transactions on instrumentation and measurement, vol. 38(6), no. December 1989,
pp. 1104-1108, 1989

45 | P a g e
13. Acknowledgment
I would like to express my special thanks of gratitude to my project supervisor Dr R. Tiako for
guidance and encouragement throughout the course of the project and my external examiner Mr
J. McKelvin for positive criticism and encouraging comment, Dr A. Saha as well as our project
course coordinate who gave me the golden opportunity to do this wonderful project on the topic,
Design and Implementation of Non-Contact Tachometer for Speed Measurement of Electrical
Motor, which also helped me in doing a lot of Research, and I came to know about so many new
things I am really thankful to them. Secondly I would also like to thank my parents and friends
who helped me a lot in finalizing this project within the limited time frame.

14. Appendix
The Gantt chart discusses the time planning of the project.

Gantt Chart
31-Dec-17 10-Apr-18 19-Jul-18 27-Oct-18 4-Feb-19

Study and research about non contact tachometer 22

First progress report submission 0

Develop design specifications 48

Design and simulation of block diagram using Proteus and multsim 63

Interim Report submission 0


Task

Oral presentation preparations 1

Oral presentation 0

Finalize the design and implementatin of non contact tachometer 22

Final report submission 0

Oral presentation preparations 2

Final oral examination and demonstration of final project work 0

Date

Start Date duration

Figure1: Cantt chart

Figure 2: Code from software design. Microcontroller Atmega16 simulated using Proteus
simulating tool.
#include <inttypes.h>

46 | P a g e
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <util/delay.h>
#define F_CPU 1000000UL
#define LCD_DATA_PORT PORT(LCD_DATA)
#define LCD_E_PORT PORT(LCD_E)
#define LCD_RS_PORT PORT(LCD_RS)
#define LCD_RW_PORT PORT(LCD_RW)
#define LCD_DATA_DDR DDR(LCD_DATA)
#define LCD_E_DDR DDR(LCD_E)
#define LCD_RS_DDR DDR(LCD_RS)
#define LCD_RW_DDR DDR(LCD_RW)
#define LCD_DATA_PIN PIN(LCD_DATA)
#define SET_E() (LCD_E_PORT|=(1<<LCD_E_POS))
#define SET_RS() (LCD_RS_PORT|=(1<<LCD_RS_POS))
#define SET_RW() (LCD_RW_PORT|=(1<<LCD_RW_POS))
#define CLEAR_E() (LCD_E_PORT&=(~(1<<LCD_E_POS)))
#define CLEAR_RS() (LCD_RS_PORT&=(~(1<<LCD_RS_POS)))
#define CLEAR_RW() (LCD_RW_PORT&=(~(1<<LCD_RW_POS)))
#ifndef _LCD_H
#define _LCD_H
#define LCD_DATA D //Port PD3-PD6 are connected to D4-D7
#define LCD_E D //Enable/strobe signal
#define LCD_E_POS PD7 //Position of enable in above port
#define LCD_RS B
#define LCD_RS_POS PB2
#define LCD_RW B
#define LCD_RW_POS PB0
#define LCD_DATA_POS 3

47 | P a g e
/***********************************************
LCD Type Selection
Uncomment Just one of them
************************************************/
//#define LCD_TYPE_202 //For 20 Chars by 2 lines
#define LCD_TYPE_204 //For 20 Chars by 4 lines
//#define LCD_TYPE_162 //For 16 Chars by 2 lines
//#define LCD_TYPE_164 //For 16 Chars by 4 lines
//************************************************
#define LS_BLINK 0B00000001
#define LS_ULINE 0B00000010
#define LS_NONE 0B00000000
/***************************************************
FUNCTIONS END
****************************************************/
/***************************************************
MACROS
***************************************************/
#define LCDClear() LCDCmd(0b00000001)
#define LCDHome() LCDCmd(0b00000010);
#define LCDWriteStringXY(x,y,msg) {\
LCDGotoXY(x,y);\
LCDWriteString(msg);\
}
#define LCDWriteIntXY(x,y,val,fl) {\
LCDGotoXY(x,y);\
LCDWriteInt(val,fl);\
}
#endif
#ifndef MYUTILS_H

48 | P a g e
#define MYUTILS_H
#define _CONCAT(a,b) a##b
#define PORT(x) _CONCAT(PORT,x)
#define PIN(x) _CONCAT(PIN,x)
#define DDR(x) _CONCAT(DDR,x)
#endif
#define LCDCmd(c) (LCDByte(c,0))
#define LCDData(d) (LCDByte(d,1))
#define MYUTILS_H
#define _CONCAT(a,b) a##b
#define PORT(x) _CONCAT(PORT,x)
#define PIN(x) _CONCAT(PIN,x)
#define DDR(x) _CONCAT(DDR,x)
/***************************************************
FUNCTIONS
****************************************************/
void LCDInit(uint8_t style);
void LCDWriteString(const char *msg);
void LCDWriteInt(int val,unsigned int field_length);
void LCDGotoXY(uint8_t x,uint8_t y);
void LCDByte(uint8_t,uint8_t);
void LCDBusyLoop();
void LCDByte(uint8_t c,uint8_t isdata)
{
//Sends a byte to the LCD in 4bit mode
//cmd=0 for data
//cmd=1 for command
//NOTE: THIS FUNCTION RETURS ONLY WHEN LCD HAS PROCESSED THE COMMAND
uint8_t hn,ln; //Nibbles
uint8_t temp;

49 | P a g e
hn=c>>4;
ln=(c & 0x0F);
if(isdata==0)
CLEAR_RS();
else
SET_RS();
_delay_us(0.500); //tAS
SET_E();
//Send high nibble
temp=(LCD_DATA_PORT & (~(0X0F<<LCD_DATA_POS)))|((hn<<LCD_DATA_POS));
LCD_DATA_PORT=temp;
_delay_us(1); //tEH
//Now data lines are stable pull E low for transmission
CLEAR_E();
_delay_us(1);
//Send the lower nibble
SET_E();
temp=(LCD_DATA_PORT & (~(0X0F<<LCD_DATA_POS)))|((ln<<LCD_DATA_POS));
LCD_DATA_PORT=temp;
_delay_us(1); //tEH
//SEND
CLEAR_E();
_delay_us(1); //tEL
LCDBusyLoop();
}

void LCDBusyLoop()
{
//This function waits till lcd is BUSY
uint8_t busy,status=0x00,temp;

50 | P a g e
//Change Port to input type because we are reading data
LCD_DATA_DDR&=(~(0x0f<<LCD_DATA_POS));
//change LCD mode
SET_RW(); //Read mode
CLEAR_RS(); //Read status
//Let the RW/RS lines stabilize
_delay_us(0.5); //tAS
do
{
SET_E();
//Wait tDA for data to become available
_delay_us(0.5);
status=(LCD_DATA_PIN>>LCD_DATA_POS);
status=status<<4;
_delay_us(0.5);
//Pull E low
CLEAR_E();
_delay_us(1); //tEL
SET_E();
_delay_us(0.5);
temp=(LCD_DATA_PIN>>LCD_DATA_POS);
temp&=0x0F;
status=status|temp;
busy=status & 0b10000000;
_delay_us(0.5);
CLEAR_E();
_delay_us(1); //tEL
}while(busy);
CLEAR_RW(); //write mode
//Change Port to output

51 | P a g e
LCD_DATA_DDR|=(0x0F<<LCD_DATA_POS);
}
void LCDInit(uint8_t style)
{
/*****************************************************************

This function Initializes the lcd module


must be called before calling lcd related functions
Arguments:
style = LS_BLINK,LS_ULINE(can be "OR"ed for combination)
LS_BLINK :The cursor is blinking type
LS_ULINE :Cursor is "underline" type else "block" type
*****************************************************************/
//After power on Wait for LCD to Initialize
_delay_ms(30);
//Set IO Ports
LCD_DATA_DDR|=(0x0F<<LCD_DATA_POS);
LCD_E_DDR|=(1<<LCD_E_POS);
LCD_RS_DDR|=(1<<LCD_RS_POS);
LCD_RW_DDR|=(1<<LCD_RW_POS);
LCD_DATA_PORT&=(~(0x0F<<LCD_DATA_POS));
CLEAR_E();
CLEAR_RW();
CLEAR_RS();
//Set 4-bit mode
_delay_us(0.3); //tAS
SET_E();
LCD_DATA_PORT|=((0b00000010)<<LCD_DATA_POS); //[B] To transfer 0b00100000 i was
using LCD_DATA_PORT|=0b00100000
_delay_us(1);

52 | P a g e
CLEAR_E();
_delay_us(1);
//Wait for LCD to execute the Functionset Command
LCDBusyLoop(); //[B] Forgot this delay
//Now the LCD is in 4-bit mode
LCDCmd(0b00101000); //function set 4-bit,2 line 5x7 dot format
LCDCmd(0b00001100|style); //Display On
}
void LCDWriteString(const char *msg)
{
/*****************************************************************
This function Writes a given string to lcd at the current cursor
location.
Arguments:
msg: a null terminated string to print
*****************************************************************/
while(*msg!='\0')
{
LCDData(*msg);
msg++;
}
}
void LCDWriteInt(int val,unsigned int field_length)
{
/***************************************************************
This function writes a integer type value to LCD module
Arguments:
1)int val : Value to print
2)unsigned int field_length :total length of field in which the value is printed
must be between 1-5 if it is -1 the field length is no of digits in the val

53 | P a g e
****************************************************************/
char str[7]={0,0,0,0,0,0,0};
int i=6,j=0;
while(val)
{
str[i]=val%10;
val=val/10;
i--;
}
if(field_length==-1)
while(str[j]==0) j++;
else
j=7-field_length;
if(val<0) LCDData('-');
for(i=j;i<7;i++)
{
LCDData(48+str[i]);
}
}
void LCDGotoXY(uint8_t x,uint8_t y)
{
if(x>=20) return;
#ifdef LCD_TYPE_204 OR LCD_TYPE_162 //OR LCD_TYPE_202
switch(y)
{
case 0:
break;
case 1:
x|=0b01000000;
break;

54 | P a g e
case 2:
x+=0x14;
break;
case 3:
x+=0x54;
break;
}
#endif
#ifdef LCD_TYPE_164
switch(y)
{
case 0:
break;
case 1:
x|=0b01000000;
break;
case 2:
x+=0x10;
break;
case 3:
x+=0x50;
break;
}
#endif
x|=0b10000000;
LCDCmd(x);
}
volatile uint16_t count=0; //Main revolution counter
volatile uint16_t rpm=0;//Revolution per minute
volatile uint16_t rps=0; //Revolution per second

55 | P a g e
void Wait()
{
uint8_t i;
for(i=0;i<2;i++)
{
_delay_loop_2(0);
}
}
int main()
{
LCDInit(LS_NONE);
LCDWriteStringXY(0,0,"Tachometer");
LCDWriteStringXY(0,1,"-By Smangaliso-");
Wait();
Wait();
Wait();
Wait();
Wait();
LCDClear();
LCDWriteStringXY(0,0,"Ready To measure");
LCDWriteStringXY(0,1,"****************");
Wait();
Wait();
//Init INT0
MCUCR|=(1<<ISC01); //Falling edge on INT0 triggers interrupt.
GICR|=(1<<INT0); //Enable INT0 interrupt
//Timer1 is used as 1 sec time base
//Timer Clock = 1/1024 of sys clock
//Mode = CTC (Clear Timer On Compare)
TCCR1B|=((1<<WGM12)|(1<<CS12)|(1<<CS10));

56 | P a g e
//Compare value=976
OCR1A=976;
TIMSK|=(1<<OCIE1A); //Output compare 1A interrupt enable
//Enable interrupts globaly
sei();
//LED Port as output
//DDRB|=(1<<PB1);
//DDRB|=(3<<PB3);
LCDClear();
//LCDWriteStringXY(0,0,"Rev/m=");
//LCDWriteStringXY(0,1,"Rev/s=");
Wait();
while(1)
{
if (rps>60){
LCDClear();
DDRB|=(1<<PB1);
PORTB|=(1<<PB1);
LCDWriteStringXY(0,0,"Speed Above");
LCDWriteStringXY(0,1,"maximum");
Wait();
PORTB&=(~(1<<PB1));
}
else if (rps<10){
if (rps >1){
LCDClear();
DDRB|=(3<<PB3);
PORTB|=(1<<PB3);
LCDWriteStringXY(0,0,"Speed below");
LCDWriteStringXY(0,1,"minimum");

57 | P a g e
Wait();
PORTB&=(~(1<<PB3));
}
}
else {
LCDClear();
LCDWriteStringXY(0,0,"Rev/m=");
LCDWriteStringXY(0,1,"Rev/s=");
LCDWriteIntXY(6,0,rpm,7);
LCDWriteIntXY(6,1,rps,7);
}
Wait();
LCDClear();
}
return (0);
}
ISR(INT0_vect)
{
//CPU Jumps here automatically when INT0 pin detect a falling edge
count++;
}
ISR(TIMER1_COMPA_vect)
{
//CPU Jumps here every 1 sec exactly!
rps=count;
rpm=rps*60;
count=0;}

58 | P a g e

You might also like