EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper...
Transcript of EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper...
![Page 1: EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper motor (or step motor) is a brushless DC electric motor that divides a full rotation](https://reader031.fdocuments.us/reader031/viewer/2022022718/5c41856593f3c338b94e1317/html5/thumbnails/1.jpg)
Sayfa 1
Department of
Engineering Physics
University of Gaziantep
Nov 2013
Topic 6
Step & Servo Motors
Joystick & Water
Sensors
EP486 Microcontroller Applications
![Page 2: EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper motor (or step motor) is a brushless DC electric motor that divides a full rotation](https://reader031.fdocuments.us/reader031/viewer/2022022718/5c41856593f3c338b94e1317/html5/thumbnails/2.jpg)
Sayfa 2
Step Motor
http://en.wikipedia.org/wiki/Stepper_motor
A stepper motor (or step motor) is a brushless
DC electric motor that divides a full rotation into
a number of equal steps.
The motor's position can
then be commanded to
move and hold at one of
these steps without any
feedback sensor.
![Page 3: EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper motor (or step motor) is a brushless DC electric motor that divides a full rotation](https://reader031.fdocuments.us/reader031/viewer/2022022718/5c41856593f3c338b94e1317/html5/thumbnails/3.jpg)
Sayfa 3
Step Motor
There are two types of steppers,
Unipolars and Bipolars.
It is very important to know which type you are working with: http://www.tigoe.net/pcomp/code/circuits/motors/stepper-motors
Stepper motors can be drived by tansistors or (as in our
case) by and ULN2003 integrated circuit.
Our step motor has 64 steps per one revolution.
That is the angular resolution is:
![Page 4: EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper motor (or step motor) is a brushless DC electric motor that divides a full rotation](https://reader031.fdocuments.us/reader031/viewer/2022022718/5c41856593f3c338b94e1317/html5/thumbnails/4.jpg)
Sayfa 4
Step Motor (circuit)
![Page 5: EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper motor (or step motor) is a brushless DC electric motor that divides a full rotation](https://reader031.fdocuments.us/reader031/viewer/2022022718/5c41856593f3c338b94e1317/html5/thumbnails/5.jpg)
Sayfa 5
Step Motor (code)
int motorPin1 = 8;
int motorPin2 = 9;
int motorPin3 = 10;
int motorPin4 = 11;
int delayTime = 50;
void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
}
// . . .
void loop() {
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(delayTime);
}
![Page 6: EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper motor (or step motor) is a brushless DC electric motor that divides a full rotation](https://reader031.fdocuments.us/reader031/viewer/2022022718/5c41856593f3c338b94e1317/html5/thumbnails/6.jpg)
Sayfa 6
Step Motor Library
/* The turns of a potentiometer (or other sensor) on analog input 0 are
used to control the movement of a stepper motor while using the Arduino
Stepper Library.*/
#include <Stepper.h>
// change this to the number of steps on your motor
#define STEPS 100
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's attached to
Stepper stepper(STEPS, 8, 9, 10, 11);
// the previous reading from the analog input
int previous = 0;
void setup(){
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
}
void loop(){
// get the sensor value (potnetiometer)
int val = analogRead(0);
// move a number of steps equal to the change in the sensor reading
stepper.step(val - previous);
// remember the previous value of the sensor
previous = val;
}
http://arduino.cc
![Page 7: EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper motor (or step motor) is a brushless DC electric motor that divides a full rotation](https://reader031.fdocuments.us/reader031/viewer/2022022718/5c41856593f3c338b94e1317/html5/thumbnails/7.jpg)
Sayfa 7
Servo Motor
http://en.wikipedia.org/wiki/Servomotor
A servomotor is a rotary actuator that allows
for precise control of angular position,
velocity and acceleration.
![Page 8: EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper motor (or step motor) is a brushless DC electric motor that divides a full rotation](https://reader031.fdocuments.us/reader031/viewer/2022022718/5c41856593f3c338b94e1317/html5/thumbnails/8.jpg)
Sayfa 8
Servo Motor Library
This library allows an Arduino board to control
Simply servo motors.
Standard servos allow the shaft to be positioned at
various angles, usually between 0 and 180 degrees.
Functions:
attach()
write()
writeMicroseconds()
read()
attached()
detach()
http://arduino.cc
![Page 9: EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper motor (or step motor) is a brushless DC electric motor that divides a full rotation](https://reader031.fdocuments.us/reader031/viewer/2022022718/5c41856593f3c338b94e1317/html5/thumbnails/9.jpg)
Sayfa 9
Servo Motor Library (code)
#include <Servo.h>
Servo myservo;
void setup (){
// only digital pin 9 or 10 are available
myservo.attach(9);
}
void loop (){
myservo.write(0); delay(1000); // rotate 0 deg
myservo.write(45); delay(1000); // rotate 45 deg
myservo.write(90); delay(1000); // rotate 90 deg
myservo.write(135); delay(1000); // rotate 135 deg
myservo.write(180); delay(1000); // rotate 180 deg
}
![Page 10: EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper motor (or step motor) is a brushless DC electric motor that divides a full rotation](https://reader031.fdocuments.us/reader031/viewer/2022022718/5c41856593f3c338b94e1317/html5/thumbnails/10.jpg)
Sayfa 10
Game joystick axis sensor module
A simple joystick is a system
consisting of two potentiometers
and a button switch.
X-Y : 2-axis analog output,
Z : 1 digital output channel button.
![Page 11: EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper motor (or step motor) is a brushless DC electric motor that divides a full rotation](https://reader031.fdocuments.us/reader031/viewer/2022022718/5c41856593f3c338b94e1317/html5/thumbnails/11.jpg)
Sayfa 11
Game joystick axis sensor module (code)
// VRx <---> A0
// VRy <---> A1
// SW <---> D7
int value = 0;
void setup () {
pinMode (7, INPUT);
Serial.begin(9600);
}
void loop () {
value = analogRead (A0);
Serial.print ("X= ");
Serial.print (value);
value = analogRead(A1);
Serial.print ("| Y=");
Serial.print (value);
value = digitalRead (7);
Serial.print ("| Z= ");
Serial.println (value);
delay (100);
}
![Page 12: EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper motor (or step motor) is a brushless DC electric motor that divides a full rotation](https://reader031.fdocuments.us/reader031/viewer/2022022718/5c41856593f3c338b94e1317/html5/thumbnails/12.jpg)
Sayfa 12
Water Sensor Module
This is basically measures amount of water droplets exposed
through a series of parallel wires.
![Page 13: EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper motor (or step motor) is a brushless DC electric motor that divides a full rotation](https://reader031.fdocuments.us/reader031/viewer/2022022718/5c41856593f3c338b94e1317/html5/thumbnails/13.jpg)
Sayfa 13
Water Sensor Module
![Page 14: EP486 Microcontroller Applications - gantep.edu.trbingul/ep486/docs/ep486-topic6.pdf · A stepper motor (or step motor) is a brushless DC electric motor that divides a full rotation](https://reader031.fdocuments.us/reader031/viewer/2022022718/5c41856593f3c338b94e1317/html5/thumbnails/14.jpg)
Sayfa 14
Water Sensor Module (code)
// level sensor connected A0
int analogPin = A0;
int led = 13;
int value = 0;
void setup (){
pinMode (led, OUTPUT);
Serial.begin (9600);
}
void loop (){
value = analogRead(analogPin);
if (value> 300) digitalWrite (led, HIGH);
else digitalWrite (led, LOW);
Serial.println (value);
delay (100);
}