Beruflich Dokumente
Kultur Dokumente
University
PIR SENSOR for controlling
stepper motor.
by
Falah Al Hassan
Ammar T.Najeeb
Supervisor: Reza Abrishambaf
Presentation Outline
Introduction : PIR sensor and application
and Specifications
Microcontroller 8051 and code .
Power supply circuit
Stepper motor .
Driver and indexer
Project circuit .
Conclusion.
Introduction
Block diagram
PIR SENSOR
UNIT
8051
MICROCONTROLLER
MOTOR
1
MOTOR
2
REGULATED
POWER
SUPPLY
Introduction
Specifications
MOV A, R3
ADD A, R4
MOV R5, A
MOV A, R1
ADD A, R2
5v
Stepper motor
A stepper motor is a brushless, synchronous electric motor that converts digital pulses
into mechanical shaft rotation (movements) which are called steps
Stepper Motor Advantages
1- The rotation angle of the motor is proportional to the input pulse.
2- The motor has full torque at standstill (if the windings are energized).
3- Precise positioning and repeatability of movement since good stepper motors have
an accuracy of 3 to 5% of a step and this error is non-cumulative from one step to
the next.
4- Excellent response to starting/stopping/reversing.
5- Very reliable since there are no contact brushes in the motor. Therefore the life of
the step motor is simply dependant on the life of the bearing.
There are three main types of stepper motors:
1. Permanent Magnet Stepper
2. Variable Reluctance Stepper
3. Hybrid Synchronous Stepper
separate stepper
movement for ap
synchronization,
Multi-Axis Control ( multi step-motor
control ) Many motion applications have more than
The following C source shows how I drive the motor. This is a very simple loop that uses the delay library
to pause for 20 ms between each pulse. The order to pulse the coils is stored in the step array. To cause
the shaft to rotate, the coils must be pulsed as follows:
Step 1
Step 2
Step 3
Step 4
Coil A
ON
ON
OFF
OFF
Coil B
OFF
OFF
ON
ON
Coil C
ON
OFF
OFF
ON
Coil D
OFF
ON
ON
OFF
In this code , I assume that the motor coils are connected to PORT B.
/*
* stepper .c
*
* Drive a stepper motor connected to port B
* RB1: Coil 1
* RB2: Coil 2
* RB3: Coil 3
* RB4: Coil 4
*
* Continually rotates motor
*/
char step[ ] = {5, 9, 10, 6};
void main(void) {
char I ;
set_bit(STATUS, RP0); /* select the register bank 1 */
set_tris_b(0);
/* PORT B is all output */
clear_bit(STATUS, RP0);
i = 0;
while(1) {
output_port_b(step[i]);
delay_ms(20);
i++;
if( i == 4)
i = 0;
}
}
Example 2 - sweep back and forth
Following on from the previous
example, this code will rotate the
motor back and forth 180 degrees
each turn.
/*
* stepper2.c
*
* Drive a stepper motor connected
to port B
*
* RB1: Coil 1
* RB2: Coil 2
* RB3: Coil 3
* RB4: Coil 4
*
* Continually sweeps back and
forth, rotating 180 deg each pass
*
*
*/
#define DELAY 50
#define SWEEP 12
#define NUMSTEPS 4
char step[ ] = {5, 9, 10, 6};
char stepPos = 0;
/* pulse the motor with the current coil setting
* and then wait for delay mS
*/
void pulseMotor(char delay) {
output_port_b(step[stepPos]);
delay_ms(delay);
}
/* Advance the coil settings forward by one step
* stepPos is left pointing to the *next* code to output
to move forward
*/
void stepMotorForw(void) {
stepPos++;
if(stepPos == NUMSTEPS)
stepPos = 0;
}
delay_s(3);
for(i=0; i < SWEEP; i++) {
stepMotorBack();
pulseMotor(DELAY);
}
delay_s(3);
}
}
Below is an example of a program that performs half-stepping and can be used to drive a stepper
motor. The code turns the motor a number of steps (100 half-steps) in one direction, and then turns
the motor back the same number of steps in the opposite direction. One of the advantages of the
code below is that it can be easily modified to keep track of a motors position. It also has the
advantage of having the port states stored in sequential order in an array. Simply cycling through the
states sequentially and placing the state values on port pins will cause a stepper motor to move. This
is written in C.
#define NUM_OF_STATES 8 // There are 8 different states in this particular example.
#define DELAY_MAX 2000 //The maximum # of counts used to create a time delay. void main(void)
{
/*******************CREATE VARIABLES*******************/
int i; //Used in a for loop
char state_array[NUM_OF_STATES] = {0x06, 0x02, 0x0A, 0x08, 0x09, 0x01, 0x05, 0x04};
int steps_to_move;
char next_state;
/********************SET UP PORT U********************/
DDRU = 0xFF;
PTU = 0; //Init Port U by writing a value of zero to Port U.
/******************************************************/
steps_to_move = 100; //Set the # of steps to move. An arbitrary positive # can be used.
next_state = 0;
PTU = state_array[next_state];
for(i = 0; i < DELAY_MAX; i++)
{
//Wait here for a while.
}
while (steps_to_move > 0)
{
if (next_state
> (NUM_OF_STATES - 1))
//If next_state is greater than the highest
//available state, 7, then cycle back to 0
{
next_state = 0;
}
PTU = state_array[next_state]; //Place new value in Port U. Rotation may be observed for(i = 0; i <
DELAY_MAX; i++)
{
//Wait here for a while.
}
next_state++;
//Increment next_state. Cycling though the states causes rotation
//in one direction. Decrementing states causes opposite rotation.
steps_to_move--;
}
//The following code rotates the motor back in the opposite direction. steps_to_move = 100;
while (steps_to_move > 0)
{
if (next_state
< 0)
{
next_state = (NUM_OF_STATES - 1);
}
PTU = state_array[next_state];
for(i = 0; i < DELAY_MAX; i++)
{
//Wait here for a while. next_state--; } steps_to_move--;
}
} //End of Main
Project Circuit
CONCLUSION
PIR sensor is used internally to excellent
performance infrared sensor for use in robot.
And it is also used for alarm burglar systems,
visitor presence monitoring, light switches.
These compact, easy to use sensors can be
easily implemented in the design.
REFERENCES
http://www.posey.com/files/M6183.pd
http://www.makingthings.com/teleo/teleo/c
ookbook/nightlight/index.htm
http://www.electronicapt.com/circuitos/en/pics/87-motiondetector.html
http://www.active-robots.com/pirsensor.html
http://www.omega.com
Thank You!
Questions