Professional Documents
Culture Documents
Elevator Control Logic Design PDF
Elevator Control Logic Design PDF
Elevator Control Logic Design PDF
Supervisor: PROF.OUMA
Examiner: MR. OMBURA
Date of Submission
13 MAY 2016
DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING
DECLARATION OF CERTIFICATION
This is my original work and has not been presented for a degree award
in this or any other university.
Signature………………………………Date……………………………….
ACHEBE BERNARD.
F17/1468/2011.
i
This report has been submitted to the Department of Electrical and Information
Engineering, University of Nairobi with my approval as supervisor:
………………………………………………..
Prof. Absaloms Heywood Ouma.
Date:
ii
DEDICATION
To God for his divine purpose in my life.
To my mum, for her continued support.
iii
ACKNOWLEDGEMENTS
We are created for a purpose and therefore I must be grateful to my
God for such a time, his divine power has always been the source of my energy.
I also appreciate my supervisor, Pro. Absaloms Heywood Ouma for his constant
dedication, support and guidance.
My appreciation too goes to my parents, lecturers, classmates, and non-
teaching staff at Electrical and Electronic department, University of Nairobi and
friends whose contribution cannot be underestimated.
Special thanks to My friend David Kariuki whose advice and motivation provided
a great jumpstart to see me continue even amidst challenges.
iv
Table of Contents
COVER PAGE
DECLARATION OF CERTIFICATION……………………………….………………………...…..………i
LIST OF FIGURES…………………………………………………………………………………………………ii
DEDICATION……………………………………………………………………………………………………...iii
ACKNOWLEDGEMENTS……………………………………………………………………………….……..IV
1. CHAPTER 1: INTRODUCTION…………………………………………………………….……..1
1.1 General Background……………………………………...……………………………….….………1
1.2 Main Objectives
1.2.1 Overall Objective…………………………………………………………………………..……………2
1.2.2 Specific Objectives…………………………………………………………………….…………..……2
1.3 Project Justification…………………………………………………………………………….………2
1.4 Project scope………………………………………………………………………………………………3
2. CHAPTER2: LITERATURE REVIEW…………….………………………………………....……..4
2.1 Introduction…………………………………………………………………………………………………....…….4
2.2 Elevators………………………………………………………………………………………………………...…….4
2.3 Stepper Motors………………………………………………………………………………….…………....……4
2.3.1 Application of Stepper Motor…………………………………………………………..…..……..5
2.3.2 Types of Stepper Motors…………………………………………………………..………….…….5
2.3.3 Stepper Motor Drive Circuits…………………………………………………………….…………8
2.3.3.1 Unipolar drive……………………………………………………………………………….….…..…….9
2.3.3.2 Resistance/Limited drive………………………………………………………………...………….9
2.3.3.3 Bipolar drive………………………………………………………………………………….………….10
2.3.4 Selection Criteria for stepper motor……………………………………..…………………..11
2.4 Stepper Motor Controllers…………………………………………………………………..……..………11
2.4.1 Microcontrollers and Microprocessors…………………………………………..………………..11
2.4.2 Programmable Logic Controller(PLC)…………………………………………….…………….….15
2.4.3 Relay Based Controllers……………………………………………………………….………….……..19
2.5 Electronic Display Devices………………………………………………………………..……….………20
2.5.1. Types of electronic displays………………………………………………………………20
2.5.2. Seven segment display……………………………………………………………………..21
2.5.3. LCD(Liquid Crystal Display)………………………………………………………….……24
2.6 Power Supply……………………………………………………………………………….…………………..26
2.6.1. Transformer………………………………………………………………………………………………….27
2.6.2. Voltage regulators………………………………………………………………………………….……27
2.6.3. Diode bridge………………………………………………………………………………………….…....27
2.6.4. Filter circuit……………………………………………………………………………………………….…28
2.7 Switches………………………………………………………………………………………….…….………..29
2.8 Conclusion……………………………………………………………………………………………………….31
3. CHAPTER 3:DESIGN…………………………………………………………………….……..32
3.1 Introduction………………………………………………………………………….….…..32
3.2 System definition…………………………………………………………….…….……..32
3.2.1.Inputs………………………………………………………………………………….….……33
V
3.2.2.Motor……………………………………………………………………………….…………35
3.2.3.Cab……………………………………………………………………………………….………35
3.2.4.Controller…………………………………………………………………………….…….…35
4. CHAPTER 4: IMPLEMENTATION……………………………………………..….….….…38
4.1 Components used…………………………………………………………………....……40
4.1.1 Connection of 28BYJ48…………………………………………………….…….….40
4.1.2 Power supply circuit……………………………………………………….………...41
4.1.3 Arduino mega 2560…………………………………………………………….……..42
4.1.4 7 segment display………………………………………………………………..…….43
4.1.5 Pushbuttons……………………………………………………………………………….45
4.1.6 Project overview…………………………………………………………………….…..46
4.2 The general hardware circuit diagram…………………………………….…….48
4.3 The software implementation………………………………………………….……..51
5. CHAPTER 5:RESULTS AND EVALUATION……………………………………………..52
5.1 Introduction……………………………………………..……………………..52
5.2 Achievements…………………………………………………………………………….…52
5.3 Challenges……………………………………………………………………………….…..53
5.4 Recommendations……………………………………………………………………….53
5.5 Conclusion………………………………………………………………………….………..54
5.6 Appendix………………………………………………………………………….………….54
5.6.1 The code used………………………………………………………………….….……..54
5.6.2 Time budget………………………………………………………………………...……65
5.6.3 References………………………………………………………………….………………66
V
TABLE OF FIGURES
FIGURE DESCRIPTION PAGE
2.1 Unipolar stepper motor 7
2.2 Bipolar stepper 8
2.3 Unipolar stepper driver 9
2.4 Bipolar stepper driver 10
2.5 Microprocessor system 13
2.6 Basic PLC structure 16
2.7 Relay based controller 19
2.8 Seven segment display 21
2.9 Power supply circuit 28
3.1 System design flow chart 33
3.2 Outer door button design 34
3.3 Controller flow chart 38
3.4 Door opening and closing logic 39
3.5 Power supply circuit 41
3.6 Arduino mega 2560 42
3.7 Project structure 47
3.8 Hardware circuit diagram 48
3.9 Complete model 49
3.10 Control circuit 50
V
1.2 Main Objectives
1.2.1. Overall Objective
The main objective of this project is to design and implement logic for a 4 level elevator using a
stepper motor and demonstrate on a model
In accomplishment of the main objective, the following areas need to be properly understood.
i. To study and understand the types, the operation principles and applications of
elevators, stepper motors and the controllers.
ii. Application of above concepts in design and implementation a control logic for
elevator model.
iii. Integration, building and testing of a 4 level elevator control logic.
Technological shift in building and construction has led to development of high structures like
skyscrapers which have made it necessary for an even more efficient access system. As a
results of this there is a need to develop a cost effective and efficient logic control system that
assures safety and simplicity to the users without compromising on the quality. This has
therefore prompted for a more research and development of better control systems for
elevators.
2
1.4 Project scope.
This project aims at building a control logic which takes commands from users and act on its own to
enable operation of the elevator. It uses a stepper motor and a controller to implement an elevator
system
3
CHAPTER 2:LITERATURE REVIEW
2.1 Introduction
This chapter includes a detailed description of elevators, stepper motors, the drives that run them and
also the controls involved in elevator operation.
2.2 Elevators
An elevator (a lift in British English) is a type of vertical transportation that moves people or good
between floors, levels or decks of a buildings, vessels or other structures. They normally powered by
motors that drive traction cables or or counterweight systems like hoist or pump hydraulic fluid to
raise a cylindrical piston like a jack.
This is an electromechanical device with ability to convert electrical pulse into discrete
mechanical movements. The shaft of this motor rotates in a discrete step increment when electrical
pulses are applied in a proper sequence. It is a brushless DC electric motor that divides a full rotation
into a number of equal steps. Sizing of the motor depends on its torque and speed which determines
its applications. This motor converts its train of input pulses into precisely defined increment in the
shaft position with each pulses moving through a particular angle.
Stepper motors have multiple ‘toothed’ electromagnets arranged around center gear shaped piece of
iron. An external drive circuit e.g. a microcontroller energizes the motor. To make the shaft rotate,
one electromagnet is given power thus attracting the gear teeth. When these teeth are aligned to the
first electromagnet, they are slightly offset from the next electromagnet. Thus when the next is turned
4
on and the first turned off, the gear rotates slightly to align with the next one. The process is repeated
with each rotation called a ‘step’ with an integer number of steps making up a full rotation. Thus
motor is turned with precise angle. This angle through which the motor shaft rotates for each
command pulse is the step angle
This motors find applications in operation controls in computer peripherals, textile industries, IC
fabrications and robotics. They have advantage since position information can be obtained by keeping
count of pulses sent to the motor thus eliminating the need for expensive position sensors and
feedback controls. They also find application in commercial, military and medical fields for mixing,
cutting, striking, metering and blending. However due to their good control over speed and position,
they are used today in elevators since have a robust design, no brushes and a good speed control.
5
They use a combination of PM and VR characteristics to achieve maximum power in a small
package size.
The two basic winding arrangement for electromagnetic coils in a two phase stepper motor can be
used to classify this motors into
i. Unipolar Motors.
This motor has two windings per phase, one for each direction of magnetic field i.e. one winding with
a center tap per phase. Each section of windings is switched on for each direction of magnetic field.
Magnetic pole can be reversed here without switching the direction of the current and hence the
commutation circuit can be made very simple (e.g. a single transistor) for each winding. Typically,
given a phase, one end of each winding is made common: giving three leads per phase and thus six
leads for a two phase motor.
6
Fig2.1
Bipolar motors have a single winding per phase. The current in a winding needs to be reversed in
order to reverse a magnetic pole, thus the driving circuit must be more complicated; typically with an
H-bridge arrangement (however there are several off the shelve drive chips that simplify this). There
are two leads per phase, non are common. The static friction effects using an H-bridge have been
observed with certain drive topologies.
Since the windings are better utilized, they are powerful compared to unipolar motors of the same
weight. This is due to the physical space occupied by the windings. A unipolar stepper motor has
twice the amount of wires in the same space but with only half of them used at any point in time thus
is 50% efficient with only around 70% output torque available. Though bipolar one is more
complicated to drive, it’s more efficient since the drive chips are abundance and easy to achieve.
7
Fig.2.2
The performance of a stepper motor is dependent on the drive circuit. This drives receive low level
signals from the control system and converts them into electrical pulses to run the motor. One step
pulse may be required for each step of the motor shaft. In a full mode with a standard 200 step motor,
200 step pulses are required to complete one revolution. In micro stepping mode the driver may be
required to generate 50000 or more steps pulses per revolution.
Speed and torque performance of a stepper motor is based on the current flow from the driver to the
motor winding. The lower the inductance the faster the current to the windings and the better the
performance of the motor. Most drivers are designed to supply a voltage greater than the motor rated
voltage. This however leads to a necessity of limiting the current that this high voltages may induce.
The stepper motor needs a low voltage dc source free from harmonics.
a. Unipolar drive
b. R/L drive
c. Bipolar chopper drive
8
2.3.3.1 UNIPOLAR DRIVE
It is called a unipolar drives since current flow is limited to one direction. The switch set is simple
and inexpensive. However the drawbacks are limited capability to energize all the windings at the
same time thus low efficiency. Here the torque is proportional to the square of the current,
direction of the current in the phase windings being unimportant. Therefore, the four windings A,
B, C and D are excited in the appropriate manner. The phase windings have large inductance,
therefore in series in each phase winding a forcing resistance is inserted so as to reduce the circuit
time constant. A resistance is also placed in series with the freewheeling diode in order to
dissipate the energy stored in the phase winding inductance.
Fig2.3
They are also called constant voltage drives since a constant positive or negative voltage is applied to
each winding to set the step positions. However, it is winding current that applies toque to the stepper
motor shaft. They make it possible to control low voltage resistive motor with a high voltage drive
9
through addition of an external resistor on each winding. These drives are too old as compared to
today’s driver technology. They only exist due to the simplicity and affordability. There main
drawback is due to reliance on “dropping resistance” to achieve almost 10 times the amount of motor
current rating necessary to maintain a useful speed increase. This generates a lot of heat and must rely
on dc power supply as the current source.
There are mostly used in industrial applications. This drives though more expensive they offer high
performance and efficiency. Here, the torque is proportional to phase current. The direction of
rotation in the motors is dependent on the direction of current in the phase windings. Thus for rotation
in one direction bi-polar drive circuit for each phase is necessary. In diagram below T1 and T4 are
controllable semiconductor switches. When the switches are closed, current flows in the direction of
arrows associated with them. Diodes in parallel with each semiconductor controllable switch protect
these controllable switches from voltage spikes produced from switching of the inductor.
10
2.3.4 SELECTION CRITERIA FOR A STEPPER MOTOR
When a stepper motor is to be used for a particular task, this factors must be considered. Operating
speed in steps/second according to the need of the task. Torque produced by the motor in N-m, load
inertia of the motor and the required step angle resolution. Also the time to accelerate in ms and time
to decelerate in ms, the type of drive to be used and size and weight consideration. This are important
to ensure proper operation depending on the particular task.
However, in designing of this motors, it is important to consider inductance which increase torque
and reduce speed upon increase, motor stiffness and motor heat to avoid damage on the insulation
and winding
This are systems responsible for coordinating all the aspects of elevator services such as travel, speed,
accelerating and decelerating, door opening speed and delay, levelling and hall lantern signals. It
accepts inputs (e.g. button signals) and produces outputs (e.g. elevator car moving and door opening).
11
Microcontrollers are for to send pulses to the stepper motor drives. It controls both the speed and
position of the stepper motor. The speed of the motor depends on the frequency of the drive input
pulses which is controllable with the help of microcontrollers and the rotation is proportional to the
number of output pulses.
A digital microcontroller has 3 main components: Central Processing Unit (CPU), program and data
memory and input/output (I/O) system. The CPU controls the flow of information among the
components of a computer. It also processes the data by performing digital operations. Most of
processes is performed in Arithmetic- Logic Unit (ALU) within the CPU. When the CPU is built on
the single printed circuit board, the computer is called a minicomputer.
A microprocessor is a CPU compacted into a single-chip semiconductor device. They are general
purpose devices suitable for many applications. A computer build around microprocessor is called a
microcomputer. Application determines the choice of I/O devices and memory. A microcontroller is
thus an entire computer manufactured on a single chip. They are usually dedicated devices embedded
within an application. For example, microcontroller are used in engine controller in automobile
applications and exposure and focus controllers in cameras. To do this, they have a high
concentration of on-chip facilities such as serial port, parallel input output ports, timers, counters,
interrupt control, analogue to digital converters, random access memory and read on memory. The
I/O, memory and on chip peripheral of a microcontroller are selected depending on the specification
of the target application. Since microcontrollers are powerful digital processors, the degree of control
and programmability they provide enhances the effectiveness of the application.
12
Microprocessor System.
Microcontroller System
Microcontroller Structure.
A microcontroller is a small computer on a single Integrated circuit containing a
processor core, memory and programmable input/output peripherals designed for
embedded applications. They have a CPU in addition to a fixed amount of RAM, ROM,
I/O ports and a timer on a single chip. The fixed amount of RAM, ROM, and I/O ports
in microcontroller makes them feel ideal for many applications in which cost and
13
space is critical. They have 8bit data bus and are capable of addressing 64k of code
memory implemented on a chip.
POWER CHARACTERISTICS
Supply Voltage (Vcc): The value as specified by level (Min-Typ-Max) of the direct supply
voltage, applied to an IC.
Supply Current: The continuous current (in A) required by this item during normal operation.
Power Dissipation: The maximum permissible power dissipation per output (in W) of
this item at specified ambient temperature
TIMERS
The timer type(s), and the number of bits and number of channels provided.
14
24 Bits The microcontroller has a 8-bit timer
32 Bits The microcontroller has a 8-bit timer
It also specify the number of timers embedded in the microcontroller
Morden elevators are PLC controlled since relays are more expensive than electronic component.
Besides a PLC makes simple the electrical connections and reduces the chances of failure. On old
elevator the direction of the car is controlled by selectors mounted on the shaft, one at each floor. On
the modern elevators there maybe one impulse switch only, mounted on the top of the car. When the
elevator moves the impulse switch detects a sequence of magnets placed on a shaft, then sends the
signal to the PLC.
Programmable Logic Controller (PLC) is an “industrial’’ computer since its hardware and
software are adapted to Industrial Environment to handle repetitive sequences of operation with logic
steps. It continuously monitors the state of input devices and makes decisions based upon a custom
program to control the state of output devices. Almost any production line, machine function, or
process can be greatly enhanced using this type of control system. However, the biggest benefit in
using a PLC is the ability to change and replicate the operation or process while collecting and
communicating vital information.
15
Another advantage of a PLC system is that it is modular. That is, you can mix and match the types of
Input and Output devices to best suit your application.
fig2.6
While Ladder Logic is the most commonly used PLC programming language, it is not the only
one. Below are more of the languages used to program a PLC
Ladder Diagram (LD) Traditional ladder logic is graphical programming language. Initia lly
programmed with simple contacts that simulated the opening and closing of relays, Ladder Logic
programming has been expanded to include such functions as counters, timers, shift registers, and
math operations.
16
Function Block Diagram (FBD) - A graphical language for depicting signal and data flows through
re-usable function blocks. FBD is very useful for expressing the interconnection of control system
algorithms and logic.
Structured Text (ST) – A high level text language that encourages structured programming. It has
a language structure (syntax) that strongly resembles PASCAL and supports a wide range of
standard functions and operators.
17
Instruction List (IL): A low level “assembler like” language that is based on similar instructions
list languages found in a wide range of today’s PLCs.
Sequential Function Chart (SFC) a method of programming complex control systems at a more highly
structured level. A SFC program is an overview of the control system, in which the basic building
blocks are entire program files. Each program file is created using one of the other types of
programming languages. The SFC approach coordinates large, complicated programming tasks into
smaller, more manageable tasks.
Special attention needs to be given to inputs and outputs since here you find protection needed to
isolate CPU blocks from damaging influence that industrial environment brings to a CPU via input
lines. Programing by ladder diagrams is the most used and the program unit is usually the computer
for writing the program for PLC control. They also served to replace relay control i.e. hardwired
control.gs
Advantages of PLCs
i) Contributes to a less intensive wiring compared to relays. Thus modifying applications and
correcting errors is easier.
ii) Smaller physical size than hard-wired solutions.
iii) Easier and faster to make changes.
iv) They have integrated diagnostics and override functions.
v) Can be duplicated faster and less expensively.
PLC Operations
18
a) INPUT SCAN: scans the state of the input (sensing devices, switches and pushbuttons,
proximity sensors and pressure switches).
b) PROGRAM SCAN: executes the program logic.
c) OUTPUT SCAN: energizes and DE energizes the output (valves, solenoid, motor, actuators,
and pumps).
d) HOUSEKEEPING: communication checking with the software and performs other requests
according to their preference.
A relay is a very dependable device consisting of an electromagnet that opens and closes contacts,
routing the logic to various circuits. A simple elevator with a few stops and manual door operation
19
can be served well by a relay controller. Relays can also be used for more complex elevators, and in
fact were used until the 1980's. However, the number of relays required can make it difficult to
troubleshoot should there ever be a problem.
The following applications may be recommended as suitable for controllers using electromagnetic
relay technology:
This are output devices for information presentation in visual or tactile form(information presentation
for blind people). Supplying the input as an electrical signal makes the display an electronic display.
Some display can show only digits or alphernumeric characters and are called segment display due to
the several displays that switch on and off to give an appearance of desired glyph. The segments are
either single leds and liquid crystals. Most of them are driven by multiplexed display technique.
20
iii. Electro luminous display(ELD).
iv. Electronic paper, E ink.
v. Plasma display panel
vi. Liquid crystal display
vii. Surface conduction electron-emitter display(SED)
viii. Field emitting display(FED).
ix. Quantum modular display
x. Laser display.
xi. Light field display. (wikipedia, 2016)
A Seven Segment Display (SSD) is one of the most common, cheap and simple to use display. It
looks as below:
fig2.8
21
SSD consists of a total of 8 segments, out of which 7 are for displaying numbers, and one is for
decimal point. Each segment has 1 led inside it.
Common cathode here, the negative terminal of all the LEDs is commonly connected to the ‘COM’
pin. A segment can be lighted up when ‘1’ is given to the respective LED segment and ground is
connected to the common. The internals are given as below:
1. Common anode – here, the positive terminal of all the LEDs is commonly connected to the
‘COM’ port of the SSD. A segment can be lighted up when the ‘COM’ port is connected to the
positive battery supply, and ground is given to the respective segment.
22
A common cathode SSD is simpler to use with an MCU thus preffered.
For multiplexing, we often have to use a BJT, so here is how a BJT works:
For the simple use of a BJT as a switch, the emitter-collector junctions get shorted when there is an
input signal at the base terminal, else it remains cut-off. The input should be given through a suitable
resistor.
Sometimes we need to use several SSD on only a single MCU, however, one problem that we face is
the lack of I/O pins in the MCU enough to connect all of them.
To solve this a bigger MCU can be used or a much better and recommended solution to this problem
is to multiplex the Seven Segment Displays. In telecommunications and computer networks,
multiplexing is a method by which multiple analogue message signals or digital data streams are
combined into one signal over a shared medium. The aim is to share an expensive resource.
23
2.5.3. LCD (Liquid Crystal display)
The LCDs are used for displaying purposes. In recent years the LCD is finding widespread use
replacing LED‟s due to many reasons. The declining prices of LCD as compared to LED increase
the demand of LCD in many applications. The LCD has ability to display numbers, characters and
graphics. The LCD has ease to programming for characters, numbers and graphics. LCD has a
incorporated refreshing controller.
LCD has many features make it useful for many applications like 5x8 dots with curser and built
in controller to control the LCD. LCD required only 5V DC supply for working which is easy
driven from a battery or from a rectifier. It has 16x2 ability for character, number and graphics
display. The LCD with more features are also in the market but 16x2
LCD find more useful in many applications due to the low prices and compact structure .
MEHANICAL DATA
PIN DESCRIPTION
25
Interfacing LCD
LCD Connector
A power supply is a device which delivers an exact voltage to another device as per its needs.
The many types include regulated, unregulated and variable supply and the decision to pick the correct
one depends on the device in operation. Power supplies, often called power adapters, or simply
adapters, are available in various voltages, with varying current capacities, which is nothing but the
maximum capacity of a power supply to deliver current to a load i.e the device you are supplying power
to.
Building one makes us have it designed according to our needs depending on our load requirements.
26
Same Basic Concepts related to Power Supply Design
2.6.1 Transformers
Transformers are devices which step down a relatively higher AC input Voltage into a lower AC output
voltage. There are two sides in a transformer where the coil winding inside the transformer ends. Both
ends have two wires. On the transformer, one side will have three terminals and the other will have
two. The one with the three terminals is the stepped down output of the transformer, and the one with
the two terminals is where the input voltage is to be provided.
The 78XX series of voltage regulators are commonly used all over today. The XX denotes regulated
output voltage. For example, 7805, will regulate the voltage to 5V and 7812 will regulate the voltage
to 12V. The thing to remember with these voltage regulators is that they need at least 2 volts more
than their output voltage as input. For instance, 7805 will need at least 7V, and 7812, at least 14 volts
as inputs. This excess voltage is called dropout voltage.
This is important in choosing the correct step down voltage for the transformer. since voltage regulator
needs 2 Volts more than its output voltage. For the sake of explanation, let’s assume that we are making
a 12V adapter. So the voltage regulator needs at least 14 Volts as input. So the output of the diodes
(which goes into the voltage regulator) will have to be more than or equal to 14 Volts. Now for the
diodes’ input voltage. They’ll drop 1.4 Volts in total, so the input to them has to be greater than or
equal to 14.0 + 1.4 = 15.4Volts. So I would probably use a 220 to 18 Volt step down transformer for
that.
27
2.6.4 Filter Circuit
This helps to give us a smooth dc voltage output voltage. Capacitors are applied for this purpose since
they are the simplest current filters, they let AC current pass through and block DC, so they are used in
parallel to the output. Also, if there is a ripple in the input or output, a capacitor rectifies it by
discharging the charge stored in it.
The working.
28
The AC mains are fed to the transformer, which steps down the 230 Volts to the desired voltage. The
bridge rectifier follows the transformer thus converting AC voltage into a DC output and through a
filtering capacitor feeds it directly into the input Pin 1 of the voltage regulator. The common pin2 of
the voltage regulator is grounded. The output Pin 3 of the voltage regulator is first filtered by a
capacitor, and then the output is taken.
Optional Additions
Addition of an led with a current limiting resistor in series helps to indicate that the power supply is
working. The resistance value is calculated as follows:
R = (Vout – 3)/0.02 Ω
Where, R is the series resistance value, and Vout is the output voltage of the voltage. The value of the
resistor does not have to be exactly as calculated, it can be anything close to the calculated value,
preferably greater.
In addition to an LED, you can also add a switch to control the ON/OFF mode of the power supply.
You can also use a Heat Sink, which is a metallic heat conductor attached to the voltage regulator with
a bolt. It is used in case we need high current outputs from the power supply and the voltage regulator
heats up.
2.7 SWITCHES
29
This is a component that controls opening and closing of a circuit. They allow control over current
flow and require user interaction. They only exist in 2 states i.e. open or closed. There are many types
of switches such as toggle, rotary DIP and pushbutton.
Actuation (switching) can either be by pushing, rotating, sliding, pulling and rocking.
They can also be classified into Maintained and Momentary switches depending on whether they stay
in that state same state or not respectively. (Swich Basics, 2016)
Push-buttons
Are used for connecting two points in a circuit upon pressing them to allow an input signal to be send
in this case to the Arduino.
connecting three wires to the board. The first goes from one leg of the pushbutton through a pull-up
resistor to the 5-volt supply. The second goes from the other limb through the pushbutton to ground.
The third connects to a digital input-output pin which reads the button's state. When the pushbutton is
open i.e. not pressed there is no connection between the two legs of the pushbutton, so the pin is
connected to 5 volts (through the pull-up resistor) and we read a HIGH. When the button is closed
(pressed), it makes a connection between its two legs, connecting the
30
The Arduino chip has an internal pull-up resistor which can be activated in code. When this is done
the buttons need to be connected to ground not 5V Vcc thus checks when the pin is low not high. The
button pin is declared a digital input and a high written to it.
2.8 CONCLUSION
Stepper motors provide a good control over speed and position. They find applications in making
elevators today due to their robust design, absence of brushes and good control over position and speed.
A microcontroller has been preferred in this thesis due to ease to connect with the stepper motor for to
allow control pulses to be send to motor. These control pulses are not sufficient to drive the motor thus
the need for stepper motor drives. These drivers are better compared to semiconductor switches which
requires a firing circuit.
The microcontroller is found as a best method of controlling a stepper motor. Unipolar stepper motor
has been preferred here due reduced step angle and simplicity since there is no need for reversal of
the current in the unipolar drive for changing the rotation of stepper motor.
31
CHAPTER 3 DESIGN
3.1 INTRODUCTION
The elevator design process involves description of a series of steps taken to make the logic for the 4 level
elevator. Since design depends on the particular designer’s interests and objectives, there is no single
universally accepted design procedure thus each engineer has their own twist for how the process
works. However, the most important thing is provision of a solution to a defined issue, in this case design of a
logic for a 4 level elevator.
In this particular design, the following assumptions will be taken as a preference and also to simplify the
project and keep it to the scope.
i. The elevator starts and rests on the last floor of destination whenever there no more requests to be
serviced.
ii. This is a one-way elevator thus it operates on a first come first serve basis ensuring that the first person
to make request is attended to together with those in same direction but on the way of cab (UPWARD
and DOWNWARD).
iii. Speed used is constant since floor number is small (4 levels).
iv. This a sensor less elevator. Though sensors are used in the case of real life lifts to ensure safety for
users. The stepper motor has given it this ability.
v. This elevator accepts multiple requests and destinations while at rest on a floor.
Below is a diagrammatic representation of the concepts and steps involves in the system design.
32
Input
Controller
Cab Motor
Fig3.1
The input sends signals to the controller which processes the signal send to determine the necessary action.
The action taken depends on the command issues at input and also the input signal received from the motor
and the cab i.e. cab level/floor information which determines the necessary action by the controller. Thus all
the logic operations are performed by the controller to enable up and down elevator motion, inoder to
determine the priorities in servicing the requests. The motor is connected to the cab through a belt-pulley
system. This ensures movement of the cab to effect the logic operations of the elevator.
3.2.1. Inputs
An input here refers to the data sent into the controller through a command issued from a particular
component device. In this case the commands sent to the controller are from push buttons described below.
The elevator whose logic I am designing has 5 doors with 4 outer doors each on the 4 levels i.e. floors and a
cab (elevator hoist) door.
33
The outer doors have direction buttons on each floor. This buttons summon the elevator depending on the floor
and direction pressed according to the intended destination.
Third floor(D)
Second floor(C)
First floor(B)
Ground floor(A)
Fig3.2. Buttons on outer doors systems for making requests and directions.
The inner door i.e. the cab-door is only one and according to this particular project the
floor buttons appear as shown below. This are floor destination buttons used by people to request for
particular floors of their destination. This are only operated when someone is already in the cab to request for a
particular destination
G F1
N
D
D
F2 F3
34
However other inputs are received from the motor and cab which determine speed and directions depending on
the particular commands from the controller.
3.2.2. Motor
The motor i.e. the stepper motor runs depending on the pulses received from the controller. The number of
steps to particular flow levels are constant. The motor is coupled to the cab using a belt system to ensure
movement up and down for servicing the floor request. Coupling is done by a belt drive mechanism.
3.2.3. Cab
This is the part that lifts the passengers up and down the particular flows of interests. Thus services the
requests and destinations of passengers.
The Controller system is the system responsible for coordinating all aspects of elevator service such as travel,
speed, and accelerating, decelerating, door opening speed and delay and levelling. It receives the inputs and
responds to them by sending impulses to the motor via drives.
The controller also receives in formation like floor level, position and speed from the motor and the cab and
process and displays the information on displays like lcd or 7-segment or sensors.
35
The controller can be a microcontroller, a relay or a PLC controller. This acts as the heart of logic control in
elevator system.
It accepts inputs (e.g. button signals) and produces outputs (elevator cars moving, doors opening, etc.).
The main aims of the elevator control system are:
This project involves control logic design thus the major part lies here hence the need for a controller
logic design as indicated below
CONTROLLER DESIGN
A number of actions are performed in the process to ensure proper elevator system operation. Below is a flow
diagram describing a control logic design involved in operation of my elevator.
The following points are to be noted about the flowchart representation of logic design indicated above.
36
vi. Closing and opening of the doors is automated using delays and for this case LEDS (red and green)
indicate same on the model.
vii. A request allows someone to get into the cab and indicates direction while a destination request allows
user to select the particular floor of their interest.
viii. A check on the next floor happens when the elevator is still on other floor.
37
Yes
Yes
No
Yes
No
Yes No
Yes
No Yes
No
Yes
38
Fig:3.4 General logic control diagram
Attempt to close
the door
Is there any
No Close the door
obstruction?
Yes
Yes
In real elevators a motion sensor is used to detect obstructions on the door way to ensure safety i.e. the door
closes only when there is no obstacle on the way. However, in this project, door opening and closing
mechanism will be achieved by led with a set delay.
39
CHAPTER 4: IMPLEMENTATION
The elevator is connected with the unipolar stepper motor which receives the control pulses from the
microcontroller through the ULN2003 stepper motor driver to control stepper motor position. All these
components have different DC current requirements. The LM7805 IC and LM7809 IC are used for regulation
to ensure the right voltage is provided to drive components in need of the same.
40
The 28-BYJ48 Even comes with Breakout using ULN2003 As a Motor driver chip as in the figure above.
Rated voltage : 5V DC Number of Phase 4, Speed Variation Ratio 1/64, Stride Angle 5.625° /64. Frequency
100Hz, DC resistance 50Ω±7%(25℃), Idle In-traction Frequency > 600Hz, Idle Out-traction Frequency >
1000Hz, In-traction Torque >34. 3mN.m(120Hz), Self-positioning Torque >34.3mN, Friction torque 600-1200
gf.cm, Pull in torque 300 gf.cm, Insulation grade A.
TR2 D2 U4
78L09
1N4007 3 1
VI GND VO
D7 C2
2
1000uF
TRAN-2P3S 1N4007
Fig3.5
Since the the regulators to be used are 9V and 5V, the input to them must be 2V high to account for losses thus
input to 9V is 9V+2V=11V. atleast 11V rectified input. The drop in IN4007 is 0.7 per diode in forward bias
and since two diodes conduct per cycle, then
0.7x2=1.4V is drop across them. Thus input to diodes has to be greater or equal to
41
1.4+11=12.4V. this will be provided by the 220/24V step down transformer which is able to give around
15.26V dc upon rectification i.e
2
24x𝜋 =15.26V
This was preferred due to the many pins available for both inputs and outputs i.e. 54 in number with a different
functionality. Since this project needs 10pins for pushbuttons, 7pins for 7segment display, 4 for lighting leds
used in the circuit, 1 for buzzer control and 4 for connecting to the ULN2003 driver for stepper motor, a
necessity for an Arduino with more available pins was important. In addition, the unused pins were necessary
to ensure a provision for addition of more functionality as need arise.
DUINO2
ARDUINO MEGA2560 R3
RESET
AREF
13
PB7/OC0A/OC1C/PCINT7
12
PB6/OC1B/PCINT6
11
A0 PB5/OC1A/PCINT5
PF0/ADC0 10
A1 PB4/OC2A/PCINT4
PF1/ADC1 9
A2 PH6/OC2B
PF2/ADC2 8
A3 PH5/OC4C
PWM
PF3/ADC3
A7
PF7/ADC7/TDI 7
A6 PH4/OC4B
ANALOG IN
PF6/ADC6/TDO 6
A5 PH3/OC4A
ATMEGA2560
PF5/ADC5/TMS 5
16AU 1126
A4 PE3/OC3A/AIN1
PF4/ADC4/TCK 4
PG5/OC0B
3
A8 PE5/OC3C/INT5
PK0/ADC8/PCINT16 2
tittothomas.blogspot.in
A9 PE4/OC3B/INT4
PK1/ADC9/PCINT17 1
A10 TX0 PE1/TXD0/PDO
PK2/ADC10/PCINT18 0
A11 RX0 PE0/RXD0/PCINT8
PK3/ADC11/PCINT19
COMUNICATION
A12
PK4/ADC12/PCINT20 14
A13 TX3 PJ1/TXD3/PCINT10
PK5/ADC13/PCINT21 15
A14 RX3 PJ0/RXD3/PCINT9
PK6/ADC14/PCINT22 16
A15 TX2 PH1/TXD2
PK7/ADC15/PCINT23 17
RX2 PH0/RXD2
18
TX1 PD3/TXD1/INT3
19
RX1 PD2/RXD1/INT2
20
PB2/MOSI/PCINT2
PB3/MISO/PCINT3
SDA PD1/SDA/INT1
PB1/SCK/PCINT1
21
PB0/SS/PCINT0
SCL PD0/SCL/INT0
DIGITAL
PL5/OC5C
PL3/OC5A
PL4/OC5B
PL0/ICP4
PL1/ICP5
PG2/ALE
PA7/AD7
PA6/AD6
PA5/AD5
PA4/AD4
PA3/AD3
PA2/AD2
PA1/AD1
PA0/AD0
PC2/A10
PC4/A12
PC5/A13
PC6/A14
PC7/A15
PG0/WR
PC3/A11
PG1/RD
PC0/A8
PC1/A9
PD7/T0
PL2/T5
PL6
PL7
53
52
51
50
49
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
42
Fig3.6This is a summary of requirements for proper functioning of this Arduino.
Microcontroller ATmega2560
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limits) 6-20V
Digital I/O Pins 54 (of which 14 provide PWM output)
Analog Input Pins 16
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 256 KB of which 8 KB used by bootloader
SRAM 8 KB
EEPROM 4 KB
Clock Speed 16 MHz
43
The common anode configuration has been chosen for use in this project. This is due to the simplicity since only one
resistor is used to limit the current.
(2) Reverse biasing of the dot matrix is not recommend, will cause damage to the leds
10mA)
LEDS5612AUR1C AlGaAs Red 660 10 1.8 2.3 10,000 ucd
LEDS5612TB1C InGaN Blue 468 10 3.3 4.0 28,000 ucd
LEDS5612YG1C GaP Green 568 10 1.9 2.3 12,000 ucd
LEDS5612UY1C AlInGaP 590 10 1.8 2.3 12,000 ucd
Amber
LEDS5612TW1C InGaN White 5,500K 10 3.3 4.0 28,000 ucd
Therefore the resistor rating for connecting the 7 segment to the Arduino can be calculated as:
Output of Arduino pins(V)=5V
Forward current per segment=20mA
Forward voltage(Vf)=1.8. To ensure they all use same resistor for current limiting.
44
𝑉−𝑉𝑓 5𝑣−1.8𝑣
𝑅= = =160Ω the standard resistor value choosen for use was 220Ω.
𝐼 20𝑚𝐴
Pull-down resistors have been preferred in this particular circuit since there operate is in the same
way as pull-up resistors. A pushbutton switch is connected between the supply voltage and a
microcontroller pin. In the circuit, on closing the switch, the microcontroller input is at a logical high
value but when open, the pull down resistor pulls the input voltage to the ground to prevent
unrequired state at the input. The resistor value is made high than the impedance of the logic circuit,
lest it pulls the voltage down by too much and the input voltage at the pin would remain at a constant
logical low value – regardless of the switch position.
The resistor chosen is at least 10 times smaller than input impedance value. Bipolar families that
operate at 5V can have range of 1-5V. thus the standard value chosen for this project is 4.7K.
45
pull down resistor connection
The p r o je c t is divided into four floors of equal distance ground floor, Ist floor, second floor
and third floor. The stepper motor is connected to the elevator lifting pulley with belt as shown in
the below figure. The stepper motor pulley will take 2 full rotations to lift the elevator to cover the
distance from one floor to another. The 7 segment displays the following information; floor
position of the cab and whether its ascending or descending.
46
The pushbuttons are used to select the desired location for elevator. After reaching at destinatio n
floor after some delay green LED glow which represents the opening of elevator door and
afterwards green LED off and red LED glow which represents closing of the cab door. The lift
model is made from cardboard material. Below is the structure representation.
47
4.2 The General Hardware Circuit Diagram
RESET
AREF
13
PB7/OC0A/OC1C/PCINT7
12
PB6/OC1B/PCINT6
11
A0 PB5/OC1A/PCINT5
PF0/ADC0 10
A1 PB4/OC2A/PCINT4
PF1/ADC1 9
A2 PH6/OC2B
PF2/ADC2 8
A3 PH5/OC4C
PWM
PF3/ADC3
A7
PF7/ADC7/TDI 7
A6 PH4/OC4B
ANALOG IN
PF6/ADC6/TDO 6
A5 PH3/OC4A U4
ATMEGA2560
PF5/ADC5/TMS 5
16AU 1126
A4 PE3/OC3A/AIN1
PF4/ADC4/TCK 4 9
PG5/OC0B COM
3 1 16
A8 PE5/OC3C/INT5 1B 1C
PK0/ADC8/PCINT16 2 2 15
tittothomas.blogspot.in
A9 PE4/OC3B/INT4 2B 2C
PK1/ADC9/PCINT17 1 3 14
A10 TX0 PE1/TXD0/PDO 3B 3C
PK2/ADC10/PCINT18 0 4 13
A11 RX0 PE0/RXD0/PCINT8 4B 4C
+88.8
PK3/ADC11/PCINT19 5 12
COMUNICATION
A12 5B 5C
PK4/ADC12/PCINT20 14 6 11
A13 TX3 PJ1/TXD3/PCINT10 6B 6C
PK5/ADC13/PCINT21 15 7 10
A14 RX3 PJ0/RXD3/PCINT9 7B 7C
PK6/ADC14/PCINT22 16
A15 TX2 PH1/TXD2
PK7/ADC15/PCINT23 17 ULN2003A
RX2 PH0/RXD2
18
TX1 PD3/TXD1/INT3
19
RX1 PD2/RXD1/INT2
20
PB2/MOSI/PCINT2
PB3/MISO/PCINT3
SDA PD1/SDA/INT1
PB1/SCK/PCINT1
21
PB0/SS/PCINT0
SCL PD0/SCL/INT0
DIGITAL
PL5/OC5C
PL3/OC5A
PL4/OC5B
PL0/ICP4
PL1/ICP5
PG2/ALE
PA7/AD7
PA6/AD6
PA5/AD5
PA4/AD4
PA3/AD3
PA2/AD2
PA1/AD1
PA0/AD0
PC2/A10
PC4/A12
PC5/A13
PC6/A14
PC7/A15
PG0/WR
PC3/A11
PG1/RD
PC0/A8
PC1/A9
PD7/T0
PL2/T5
PL6
PL7
53
52
51
50
49
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22 R16
D7 220 R9
U3 220
78L08 D8 R2 R1
220 220
TR1 D9 LED-YELLOW
3 1
VI VO
LED-BLUE
D2
GND
1N4007
D3
C2 LED-RED
2
1000uF
D10 R3
LED-GREEN 220
TRAN-2P3S 1N4007
Fig.3.8
48
Fig.3.9 Model
49
Fig3.10 control circuit
50
4.3 The Software Implementation.
The code was written in c programming language on an Arduino Integrated Development Environment that
has a text editor, a message area, a text console, a tool bar with buttons for common functions and a series of
menu. The different code modules were created for running;
i. The stepper motor
ii. The 7 segment display
iii. Inputs from the button commands
iv. The leds that simulate the door opening and elevator up-down movement
v. The buzzer.
In summary the written code implement the logic designed. The motor receives commands from button inputs
to initiate the logic. The written code was loaded onto Arduino mega controller using a usb cable. The
different modules are also integrated allowing for particular response whenever the request or destination
commands are issued.
The complete written code is attached at APPENDIX section.
51
CHAPTER 5: RESULTS AND EVALUATION
5.1 INTRODUCTION
The aim of the project was achieved. The logic for a 4 level elevator was designed, implemented, build and
tested. The components used were;
i. The Arduino mega 2560 which was the controller device.
ii. The 7 segment display for indicating floor level of the elevator and floor movements (floor display).
iii. Button inputs to send control commands for particular desired elevator response.
iv. Leds for simulating door opening and closing and up-down elevator cab movement.
v. The buzzer which gives sound to simulate door closed and cab movement scenarios.
vi. The stepper motor connected to cab for up-down motion of elevator.
5.2 ACHIEVEMENTS
5.3 CHALLENGES
The limited nature of atmega 2560 which has only 6 interrupt pins thus could not support all the 10 input
pins to allow for interrupt use. This makes the selection of multiple requests and destination only possible at
floors during delay period.
52
The use of a stepper motor
5.4 RECOMMENDATIONS
The use of high level controllers like Programmable Logic Controller(PLC) to allow for a better control,
market applicable.
The use of positon and motion sensors to allow for detection of flow levels and also opening of the door in
case of interrupts.
5.5 CONCLUSION
The main objective of this project was to design and implement logic for a 4 level elevator using a stepper
motor and demonstrate on a model. This was achieved as documented in this project
53
5.6 APPENDIX
#include <Stepper.h>
//Global variables
int CF=0; // Current floor
int DF=0; //destination floor
int DF0=0; // Destination floor boolean
int DF1=0; // Destination floor boolean
int DF2=0; // Destination floor boolean
int DF3=0; // Destination floor boolean
int Direction=1;
int move_to_request=1;
int time_count=25;//5000/200 (5000msec delay with each key press cycle taking 200ms : 5000/200: 25 keypress cycle wait before door closes)
// Motor
//Requests
int GFU=0; //boolean
int FFU=0; //boolean
int FFD=0; //bolean
int SFU=0;//bolean
int SFD=0;//bolean
int TFD=0;//bolean
// Declare pins
// Seven segment pins
int pina = 22;
int pinb = 23;
int pinc = 24;
int pind = 25;
int pine = 26;
int pinf = 27;
54
int ping = 28;
// Buttons pins
int pinGF = 53;//connected to ground floor
int pinFF = 52;
int pinSF = 51;
int pinTF = 50;
int pinGFU = 49;
int pinFFU = 48;
int pinFFD = 47;
int pinSFU = 46;
int pinSFD = 45;
int pinTFD = 44;
// LED pins
int pinLedOpen = 30;
int pinLedClose = 31;
int pinLedUp = 32;
int pinLedDown = 33;
// buzzer pins
int pinBuzzer=2;
void initButtons()
{
pinMode(pinGF, INPUT);
pinMode(pinFF, INPUT);
pinMode(pinSF, INPUT);
pinMode(pinTF, INPUT);
pinMode(pinGFU, INPUT);
pinMode(pinFFU, INPUT);
pinMode(pinFFD, INPUT);
pinMode(pinSFU, INPUT);
pinMode(pinSFD, INPUT);
pinMode(pinTFD, INPUT);
}
int keyScan()
{
delay(200);
if (digitalRead(pinGF) == HIGH)
{
return 0;
}
if (digitalRead(pinFF) == HIGH)
{
return 1;
}
if (digitalRead(pinSF) == HIGH)
{
return 2;
}
if (digitalRead(pinTF) == HIGH)
{
return 3;
}
if (digitalRead(pinGFU) == HIGH)
{
return 4;
}
55
if (digitalRead(pinFFU) == HIGH)
{
return 5;
}
if (digitalRead(pinFFD) == HIGH)
{
return 6;
}
if (digitalRead(pinSFU) == HIGH)
{
return 7;
}
if (digitalRead(pinSFD) == HIGH)
{
return 8;
}
if (digitalRead(pinTFD) == HIGH)
{
return 9;
}
else
{
return -1;
}
}
void disp_init()
{
// set pins as output
pinMode(pina, OUTPUT);
pinMode(pinb, OUTPUT);
pinMode(pinc, OUTPUT);
pinMode(pind, OUTPUT);
pinMode(pine, OUTPUT);
pinMode(pinf, OUTPUT);
pinMode(ping, OUTPUT);
// Indicator LEDs
pinMode(pinLedOpen, OUTPUT);
pinMode(pinLedClose, OUTPUT);
pinMode(pinLedDown, OUTPUT);
pinMode(pinLedUp, OUTPUT);
digitalWrite(pina, HIGH);
digitalWrite(pinb, HIGH);
digitalWrite(pinc, HIGH);
digitalWrite(pind, HIGH);
digitalWrite(pine, HIGH);
digitalWrite(pinf, HIGH);
digitalWrite(ping, HIGH);
56
digitalWrite(pinLedDown, LOW);
// Initialize buzzer to LOW
digitalWrite(pinBuzzer, LOW);
disp(0);
}
}
void Up(int i)
{
if(i==1)
{
//lift going upwards
digitalWrite(pinLedUp, HIGH);
digitalWrite(pinLedDown, LOW);
}
else if(i==0)
{
//lift at rest
digitalWrite(pinLedUp, LOW);
digitalWrite(pinLedDown, LOW);
}
57
else
{
//lift moving downwards
digitalWrite(pinLedUp, LOW);
digitalWrite(pinLedDown, HIGH);
}
}
void Open(int i)
{
if(i==1)
{
//door opening
digitalWrite(pinLedOpen, HIGH);
digitalWrite(pinLedClose, LOW);
digitalWrite(pinBuzzer, LOW);
}
else
{
//door closing
digitalWrite(pinLedOpen, LOW);
digitalWrite(pinLedClose, HIGH);
digitalWrite(pinBuzzer,HIGH);
}
}
58
DF=0;
}
}
}
//attending requests if no destinations set
if(move_to_request==1){
if(DF0==0 && DF1==0 && DF2==0 && DF3==0){
if(GFU==1){
move_to_request_floor(0);
}else if(FFU==1){
move_to_request_floor(1);
}else if(FFD==1){
move_to_request_floor(2);
}else if(SFU==1){
move_to_request_floor(3);
}else if(SFD==1){
move_to_request_floor(4);
}else if(TFD==1){
move_to_request_floor(5);
}
}
}
}//end of set destination method
59
// simulates door opening
Open(0);//closing the door //open
}else if(CF<des){
DF=CF+1;
Direction=1;// lift moves up
}else{
DF=CF-1;
Direction=2;//lift moves down
}
break;
case 3:
case 4:
des=2;
if(CF==des){
//OPENING DOOR
Up(0);// at rest for opening door
Open(1);//opening door
move_to_request=0;
// simulates door opening
do{
unsigned int count=0;
while(count<time_count){
get_key_press();
count++;
}
}while(DF0==0 && DF1==0 && DF2==0 && DF3==0);
Open(0);//closing the door //open
}else if(CF<des){
DF=CF+1;
Direction=1;
}else{
DF=CF-1;
Direction=2;
}
break;
case 5:
des=3;
if(CF==des){
//OPENING DOOR
Up(0);// at rest for opening door
Open(1);//opening door
move_to_request=0;
// simulates door opening
do{
unsigned int count=0;
while(count<time_count){
get_key_press();
count++;
}
}while(DF0==0 && DF1==0 && DF2==0 && DF3==0);
Open(0);//closing the door //open
}else if(CF<des){
DF=CF+1;
Direction=1;
}
break;
}
}
}
void setup() {
//stepper motor speed set
myStepper.setSpeed(120);
//destination and current floor are equal
DF = CF = 0;
60
disp_init();
initButtons();
Serial.begin(9600);
}
void get_key_press(){
int key;
delay(5);
key = keyScan();
switch(key)
{
//cab key select
case 0://destination GF
if(CF>0 && Direction==2 && (TFD==1 || SFD==1 || FFD==1)){
DF0=1; //dest to groundflo allowed
set_destination();
}else{
if(Direction==1 && CF>0 && (FFD==1 || SFD==1)){
DF0=1; //dest to thirdflo allowed
Direction=2;
set_destination();
}
}
break;
case 1:
if((CF<1 && Direction==1 && GFU==1) || (CF>1 && Direction==2 && (TFD==1 || SFD==1))){
DF1=1;//dest to firstflo allowed
set_destination();
}else{//turning point
if((CF<1 && Direction==2 && GFU==1) || (CF>1 && Direction==1 && (TFD==1 || SFD==1))){
DF1=1; //dest to secondflo allowed
if(Direction==1){
Direction=2;
}else if(Direction==2){
Direction=1;
}
set_destination();
}
}
break;
case 2:
if((CF<2 && Direction==1 && (FFU==1 || GFU==1)) || (CF>2 && Direction==2 && TFD==1)){
DF2=1;//dest to secondflo allowed
set_destination();
}else{//turning point
if((CF<2 && Direction==2 && (FFU==1 || GFU==1)) || (CF>2 && Direction==1 && TFD==1)){
DF2=1; //dest to secondflo allowed
if(Direction==1){
Direction=2;
}else if(Direction==2){
Direction=1;
}
set_destination();
}
}
break;
case 3:
if((CF<3 && Direction==1 && (GFU==1 || FFU==1 || SFU==1))){
DF3=1; //dest to thirdflo allowed
set_destination();
}else{//turning point
if(Direction==2 && CF<3 && (FFU==1 || SFU==1)){
DF3=1; //dest to thirdflo allowed
61
Direction=1;
set_destination();
}
}
break;
case 4:
// GFU=1;
if((CF > 0 && Direction==2) || (CF==0 && Direction==1) || (DF0==0 && DF1==0 && DF2==0 && DF3==0)){
GFU=1;
move_to_request_floor(0);
}
break;
case 5:
if((CF<= 1 && Direction==1) || (DF0==0 && DF1==0 && DF2==0 && DF3==0)){
FFU=1;
move_to_request_floor(1);
}
break;
case 6:
if((CF >= 1 && Direction==2) || (DF0==0 && DF1==0 && DF2==0 && DF3==0)){
FFD= 1;
move_to_request_floor(2);
}
// Serial.print("DF = ");Serial.print(key);Serial.println("");
break;
case 7:
//SFU=1;
if((CF <= 2 && Direction==1) || (DF0==0 && DF1==0 && DF2==0 && DF3==0)){
SFU= 1;
move_to_request_floor(3);
}
break;
case 8:
// SFD=1;
if((CF >= 2 && Direction==2) || (DF0==0 && DF1==0 && DF2==0 && DF3==0)){
SFD= 1;
move_to_request_floor(4);
}
break;
case 9:
// TFD=1;
if((CF< 3 && Direction==1) || (CF==3 && Direction==2) || (DF0==0 && DF1==0 && DF2==0 && DF3==0)){
TFD=1;
move_to_request_floor(5);
}
break;
default:
break;
}//end of switch()
void set_lift_motion(){
if(DF==CF){
Serial.print("IDLE @ ");Serial.println(CF);
}else if(DF>CF)//up movements
{
Serial.println("NTMU");
int flr =1; //(DF - CF);
int l = 2222 * flr;
if((CF==0 && GFU==1) || (CF==1 && FFU==1) || (CF==2 && SFU==1)){
Up(0);// at rest for opening door
Open(1);//opening door
do{
unsigned int count=0;
62
while(count<time_count){
get_key_press();
count++;
}
}while(DF0==0 && DF1==0 && DF2==0 && DF3==0);
//clearing a served request
if(CF==0){
GFU=0;
}else if(CF==1){
FFU=0;
}else if(CF==2){
SFU=0;
}
// simulates door opening
Open(0);//closing the door
}
Up(Direction);//moving up display
disp(CF);
delay(400);
// Move motor a floor up
myStepper.step(intersteps * flr);
//delay(l);
CF = CF+1;//DF;
disp(CF);
delay(400);
if((CF==1 && DF1==1) || (CF==2 && DF2==1) || (CF==3 && DF3==1)){
Up(0);// at rest for opening door
Open(1);//opening door
//clearing a served request
if(CF==1){
DF1=0;
}else if(CF==2){
DF2=0;
}else if(CF==3){
DF3=0;
}
if(DF0==0 && DF1==0 && DF2==0 && DF3==0){
move_to_request=1;
}else{
move_to_request=0;
}
// simulates door opening
do{
unsigned int count=0;
while(count<time_count){
get_key_press();
count++;
}
}while(DF0==0 && DF1==0 && DF2==0 && DF3==0 && GFU==0 && FFD==0 && FFU==0 && SFU==0 && TFD==0);
Open(0);//closing the door
}
if(CF==3){
Direction=2;
}
//Setting the next destination
set_destination();
}else if(DF<CF) // down movements
{
Serial.println("NTMD");
int flr =-1; //(DF - CF);
int l = 2222 * flr;
move_to_request=1;
if((CF==1 && FFD==1) || (CF==2 && SFD==1) || (CF==3 && TFD==1)){
Up(0);// at rest for opening door
Open(1);//opening door
63
do{
unsigned int count=0;
while(count<time_count){
get_key_press();
count++;
}
}while(DF0==0 && DF1==0 && DF2==0 && DF3==0);
//clearing a served request
if(CF==1){
FFD=0;
}else if(CF==2){
SFD=0;
}else if(CF==3){
TFD=0;
}
//delay
//delay(3000); // simulates door opening
Open(0);//closing the door
}
//down moving
Up(Direction);//moving up display
disp(CF);
delay(400);
// Move motor
myStepper.step(intersteps * flr);
//delay(l);
CF = CF-1;
disp(CF);
delay(400);
if((CF==0 && DF0==1) || (CF==1 && DF1==1) || (CF==2 && DF2==1)){
Up(0);// at rest for opening door
Open(1);//opening door
//clearing a served request
if(CF==0){
DF0=0;
}else if(CF==1){
DF1=0;
}else if(CF==2){
DF2=0;
}
if(DF0==0 && DF1==0 && DF2==0 && DF3==0){
move_to_request=1;
}else{
move_to_request=0;
}
do{
unsigned int count=0;
while(count<time_count){
get_key_press();
count++;
}
}while(DF0==0 && DF1==0 && DF2==0 && DF3==0 && GFU==0 && FFD==0 && FFU==0 && SFU==0 && TFD==0);
//delay
//delay(3000); // simulates door opening
Open(0);//closing the door
}
//direction change on ground
if(CF==0){
Direction=1;
}
//Setting the next destination
set_destination();
}
}//end of set_lift_motion
64
void loop() {
get_key_press();
// Lift Logic
set_lift_motion();
65
Testing and 9/3/2016- 2
presentation 25/3/2016
References
(Swich Basics, 2016)
(n.d.).
A guide to Robotics,Embedded electronics and Computer visions. (2016, february wednesday). Retrieved from
maxEmbedded.com: http://maxembedded.com/2013/02/how-to-build-your-own-power-supply/
AMCI. (2016, january 21). AMCI-Advanced Micro Controls Inc. Retrieved from Programmable Logic Controllers:
http://www.amci.com/tutorials/tutorials-what-is-programmable-logic-controller.asp
Clock, A. (2016, january 21). stepper. Retrieved from Stepper Motor Controller:
http://rhinoman.org/AtomicClock/stepper.html
Dubey, G. K. (14th Ed). Fundermentals of Electrical Drives. New Delhi, India: Narosa Publishing House.
wikipedia. (2016, february 4th). display devices. Retrieved from wikipedia the free encyclopedia:
http//en.m.wikipedia.org/wiki/Display-devices
66
67
68