Download Servo Motor Kontrolü Servo Motors

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Electronic paper wikipedia , lookup

Pulse-width modulation wikipedia , lookup

Electric motor wikipedia , lookup

AC motor wikipedia , lookup

Brushless DC electric motor wikipedia , lookup

Opto-isolator wikipedia , lookup

Induction motor wikipedia , lookup

Metadyne wikipedia , lookup

Brushed DC electric motor wikipedia , lookup

Variable-frequency drive wikipedia , lookup

Stepper motor wikipedia , lookup

Liquid-crystal display wikipedia , lookup

Transcript
BM-305
Mikrodenetleyiciler
Güz 2016
(9. Sunu)
(Yrd. Doç. Dr. Deniz Dal)
Character LCD (Liquid Crystal Display) Kontrolü
16x2 (16 Sütunlu, 2 Satırlı) Alfanümerik LCD (Liquid Crystal Display) Kontrolü
(White Text on Blue Background/Backlight)
As the name implies, 16x2 LCD has 2 lines with 16 chars on each lines. It supports all
the ASCII chars and is basically used for displaying the alpha numeric characters. Here
each character is displayed in a matrix of 5x7 pixels. Apart from alpha numeric chars, it
also provides the provision to display the custom characters by creating the pattern.
16x2 (16 Sütunlu, 2 Satırlı) Alfanümerik LCD (Liquid Crystal Display) Kontrolü
(White Text on Blue Background/Backlight)
16x2 (16 Sütunlu, 2 Satırlı) Alfanümerik LCD (Liquid Crystal Display) Kontrolü
(White Text on Blue Background/Backlight)
You will notice that pin 5 (RW) is tied to ground. This pin is used to
control whether you are reading or writing to the display. Since
reading from the display is uncommon, most people just tie this
pin to ground.
The potentiometer connected to pin 3 controls the LCD contrast.
Sending Data and Commands
Data and commands are sent to the LCD using the 8 data lines (pins 7-14) and the
RS line (pin 4). The RS lines tells the module whether the 8 data bits relate to data
or a command. The data/command is read on the falling edge of the enable line
(pin 6). This means that when enable transitions from high to low, the values of D0
to D7 and RS are read.
So to send data or a command to the display, you need to
1. Set Enable to high
2. Set RS and D0-D7 desired values
3. Set Enable to low
Hitachi HD44780 based display modules also have a 4 bit interface mode.
Under this mode the data or command is transferred to the module using 2, 4 bit
nibbles.
Bağlantı Şeması
5 V ve 220 Ohm
GND
Arduino LiquidCrystal Kütüphanesi (<LiquidCrystal.h>) ve Hello World Örneği
/*LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
File->Examples->LiquidCrystal
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
Yolundaki Tüm Örnekleri Tek Tek Çalıştırınız.
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor ends to 5 V and ground, wiper to LCD VO pin (pin 3)
*/
#include <LiquidCrystal.h>// include the library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);// initialize the library with the interface pins
void setup()
{
lcd.begin(16, 2);// set up the LCD's number of columns and rows
lcd.print("Hello, World!");// Print a message to the LCD.
}
void loop()
{
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);// (note: line 1 is the second row, since counting begins with 0)
lcd.print(millis()/1000);// print the number of seconds since reset
}
Arduino LiquidCrystal Kütüphanesi (<LiquidCrystal.h>) Fonksiyonları
•LiquidCrystal()
•begin()
•clear()
•home()
•setCursor()
•write()
•print()
•cursor()
•noCursor()
•blink()
•noBlink()
•display()
•noDisplay()
•scrollDisplayLeft()
•scrollDisplayRight()
•autoscroll()
•noAutoscroll()
•leftToRight()
•rightToLeft()
•createChar()
http://arduino.cc/en/Reference/LiquidCrystal?from=Tutorial.LCDLibrary
createChar Fonksiyonu
Creates a custom character (gylph) for use on the LCD. Up to eight characters of 5x8 pixels are supported (numbered 0 to 7). The appearance
of each custom character is specified by an array of eight bytes, one for each row. The five least significant bits of each byte determine the
pixels in that row. To display a custom character on the screen, write() its number.
https://www.hackmeister.dk
/2010/08/custom-lcdcharacters-with-arduino/
Block Diagram of 16x2 LCD
CG means "Character Generation", so CGROM is the character generation ROM that holds the fixed
character set. CGRAM is RAM for storing the bit patterns for the eight user-defined characters.
DD means "Data Display" and DDRAM is where the characters to be displayed are stored. When you
send an ASCII value to DDRAM, how the character is displayed on LCD? The answer is CGROM. The
Character Generator ROM generates 5x8 dot character patterns from 8-bit character codes.
16x2 LCD DDRAM (Display Data RAM)
DDRAM address corresponds to cursor position. The
numbers in each box is the memory address that
corresponds to that screen position.
Thus, the first character in the upper left-hand
corner is at address 00h. The following character
position (character #2 on the first line) is address
01h, etc. This continues until we reach the 16th
character of the first line which is at address 0Fh.
However, the first character of line 2, as shown in
the memory map, is at address 40h. This means if
we write a character to the last position of the first
line and then write a second character, the second
character will not appear on the second line. That is
because the second character will effectively be
written to address 10h--but the second line begins
Referring again to the memory map, we see that the tenth
at address 40h.
character position of the second line is address 4Ah. Thus,
Thus we need to send a command to the LCD that
before writing the word "World" to the LCD, we must send a
tells it to position the cursor on the second line. The
"Set Cursor Position" instruction--the value of this command
"Set Cursor Position" instruction is 80h. To this we
will be 80h (the instruction code to position the cursor) plus
must add the address of the location where we wish
the address 4Ah. 80h + 4Ah = CAh. Thus sending the command to position the cursor. In our example, we said we
wanted to display "World" on the second line on the
CAh to the LCD will position the cursor on the second line at
tenth character position.
the tenth character position.
16x2 LCD Commands
16x2 LCD Commands
Merhaba Dünya (4 Bit Mode)
Merhaba Dünya (4 Bit Mode)
Merhaba Dünya (4 Bit Mode)
Servo Motor Kontrolü
Servo Motors
Servos are the easiest way to start making motion with a
microcontroller.
Servos have integrated gears and a shaft that can be precisely
controlled. Standard servos allow the shaft to be positioned at
various angles, usually between 0 and 180 degrees.
The servo motor has three leads.
The color of the leads varies between servo motors, but
• the red lead is always 5 V,
• GND will either be black or brown.
• The other lead is the control lead and this is usually orange
or yellow. This control lead can be connected to a digital pin.
Servo Motor Applications
http://www.youtube.com/watch?v=lSdylL9qs7o
https://www.youtube.com/watch?v=iOLFP90DneY
https://www.youtube.com/watch?v=bkCg6-8Zuf0
http://www.youtube.com/watch?v=QqaoALks54M
https://www.youtube.com/watch?v=7xgKKiQ_WDE
https://www.youtube.com/watch?v=PoQlW8HbkdQ
Servo motor mechanism is used in a large number
of applications which are critical in position control.
We cannot use DC motor to control a tail of aircraft
because controlling a DC motor for accurate
positioning is not only difficult but almost
impossible.
One of the most popular servo motor applications is robotic. Consider a simple pick and place robot. Pick
and place robot is such a robotic machine which is used to pick an object from one position and place the
object at different position. Now, in order to pick an object from position A and place it in position B the
motors which are used to actuate the joints are servo motors. This is because; we have to plan the
angular movement of each and every joint to complete this task of pick and place. Once this data is fed to
the robot controller, the robot will continuously do its job. The controller will send PWM data to the
individual motors of the robot. This gives precise angular control of the arm which is not possible with a
regular DC motor.
Servo Motor Applications
Conveyors are used in Industrial manufacturing and
assembling units to pass an object from one
assembly station to another. Let’s consider an
example of bottle filling process, in the process the
bottle needs to be filled with the liquid and moved to
the next stage which is mainly the packaging stage.
So in order to achieve this conveyor belts are used
with servo motors so that the bottle moves precisely
to the desired location and stops so that the liquid
can be poured into it and then it is guided to the next
stage. This process continues until stopped. Hence
the precise position control ability of the servo shaft
comes in handy.
Controlling Servo Motors
Servo motors are controlled by a series of pulses and to make it easy to use them,
an Arduino library has been created so that you can just instruct the servo to turn
to a particular angle.
The position of the servo motor is set by the length of a pulse. The servo expects to
receive a pulse roughly every 20 milliseconds (50 Hz). If that pulse is high for 1
millisecond, then the servo angle will be zero, if it is 1.5 milliseconds, then it will be
at its centre position and if it is 2 milliseconds it will be at 180 degrees.
The end points of the servo can vary and many servos only turn through about 170
degrees. You can also buy 'continuous' servos that can rotate through the full 360
degrees.
Servo Motors
Görev Çevrimi (Duty Cycle) değiştirilince açı değişiyor.
Dalganın frekansı f=50 Hz ve periyodu T=20 ms
Servo Motorların İç Yapısı ve Çalışma Prensibi
http://www.electrical4u.com/servo-motor-servo-mechanism-theory-and-working-principle/
The shaft of the servo is connected
to a potentiometer . The circuitry
inside the servo, to which the
potentiometer is connected, knows
the position of the servo. The
current position will be compared
with
the
desired
position
continuously with the help of an
Error Detection Amplifier. If a
mismatch is found, then an error
signal is provided at the output of
the error amplifier and the shaft
will rotate to go the exact location
required. Once the desired location
is reached, it stops and waits.
http://www.youtube.com/watch?v=v2jpnyKPH64
Bağlantı Şeması
Servo Kütüphanesi (<Servo.h>) ve Potansiyometre ile Servo Açısının Kontrolü
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
#include <Servo.h> //include the library
Servo myservo; // create a servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup()
File->Examples->Servo Yolundaki Tüm Örnekleri Tek Tek Çalıştırınız.
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
val=analogRead(potpin); // reads the value of the potentiometer (val between 0 and 1023)
val=map(val,0,1023,0,179); // scale it to use it with the servo (val between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
DC Motor Kontrolü
TIP120 NPN Transistor (60 V, 5 A, TO-220)
A small DC motor is likely to use more power than an Arduino digital output can handle directly. If we
tried to connect the motor straight to an Arduino pin, there is a good chance that it could damage the
Arduino.
A transistor like TIP120 can be used as a switch that uses just a little current from the Arduino digital
output to control the much bigger current of the motor.
Transistor as Current Amplifier
The larger collector current IC is proportional to the base current IB according to the relationship IC =ßIB ,
or more precisely it is proportional to the base-emitter voltage VBE . The smaller base current controls the
larger collector current, achieving current amplification. (ß (beta) -> Tranzistör Akım Kazancı)
The analogy to a valve is sometimes helpful. The smaller current in the base acts as a "valve", controlling
the larger current from collector to emitter. A "signal" in the form of a variation in the base current is
reproduced as a larger variation in the collector-to-emitter current, achieving an amplification of that
signal.
DC Motorların İç Yapısı ve Çalışma Prensibi
Electrical DC Motors are continuous actuators that convert electrical
energy into mechanical energy. A DC motor consists of two parts, a “Stator”
which is the stationary part and a “Rotor” which is the rotating part.
Fleming’s
Arduino ile DC Motor Kontrolü
1N4007
Motor+Diyot
yerine
LED+Direnç bağlayarak
bir sonraki slayttaki
kodu tekrar çalıştırınız.
There is a diode connected
across the connections of the
motor. Diodes only allow
electricity to flow in one
direction (the direction of their
arrow).
When you turn the power off to
a motor, you get a negative
spike of voltage, that can
damage your Arduino or the
transistor. The diode protects
against this, by shorting out any
such reverse current from the
motor.
Arduino ile DC Motor Kontrolü
int motorPin = 9;
void setup(){
pinMode(motorPin, OUTPUT);
}
void loop() {
for(int motorValue = 0 ; motorValue <= 255; motorValue +=5){
analogWrite(motorPin, motorValue);
delay(30);
}
for(int motorValue = 255 ; motorValue >= 0; motorValue -=5){
analogWrite(motorPin, motorValue);
delay(30);
}
}
Şimdi de Motorun Bağlantı Uçlarını Değiştirin…
H-Bridge (H-Köprüsü)
H-bridge is a circuit which allows the high voltage to be flown in either direction. Since voltage should
change its direction to able to rotate the motor in clockwise or anticlockwise direction, H-bridge IC are
ideal for driving a DC motor.
H-Bridge (H-Köprüsü)
L293D Dual H-Bridge Motor Driver
Step Motorların İç Yapısı ve Çalışma Prensibi
http://www.electronics-tutorials.ws/io/io_7.html