bm-305 mikrodenetleyiciler güz 2015 (10. sunu) (yrd. doç. dr. deniz dal)

25
BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Upload: tracy-davis

Post on 29-Jan-2016

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

BM-305

Mikrodenetleyiciler

Güz 2015

(10. Sunu)(Yrd. Doç. Dr. Deniz Dal)

Page 2: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

16x2 (16 Sütunlu, 2 Satırlı) Alfanümerik LCD (Liquid Crystal Display) Kontrolü

(White Text on Blue Background/Backlight)

Page 3: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

16x2 (16 Sütunlu, 2 Satırlı) Alfanümerik LCD (Liquid Crystal Display) Kontrolü

(White Text on Blue Background/Backlight)

Page 4: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

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.

Page 5: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Sending Data and CommandsData 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 to1. Set Enable to high2. Set RS and D0-D7 desired values3. 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.

Page 6: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Bağlantı Şeması

5 V

GND

Page 7: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

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 * LCD D5 pin to digital pin 4 * LCD D6 pin to digital pin 3 * 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 libraryLiquidCrystal lcd(12, 11, 5, 4, 3, 2);// initialize the library with the interface pinsvoid 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}

File->Examples->LiquidCrystal

Yolundaki Tüm Örnekleri Tek Tek Çalıştırınız.

Page 8: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Arduino LiquidCrystal Kütüphanesi (<LiquidCrystal.h>) Fonksiyonları

http://arduino.cc/en/Reference/LiquidCrystal?from=Tutorial.LCDLibrary

•LiquidCrystal() •begin() •clear() •home() •setCursor() •write() •print() •cursor() •noCursor() •blink() •noBlink() •display() •noDisplay() •scrollDisplayLeft() •scrollDisplayRight() •autoscroll() •noAutoscroll() •leftToRight() •rightToLeft() •createChar()

Page 9: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

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.

Page 10: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Servo Motor Applications

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.

http://www.youtube.com/watch?v=lSdylL9qs7ohttp://www.youtube.com/watch?v=QqaoALks54Mhttp://www.youtube.com/watch?v=IYjI_1zLZVchttp://www.youtube.com/watch?v=hz8IGxsELiEhttps://www.youtube.com/watch?v=iOLFP90DneYhttps://www.youtube.com/watch?v=PoQlW8HbkdQhttps://www.youtube.com/watch?v=bkCg6-8Zuf0

Page 11: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

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.

Page 12: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

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.

Page 13: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Servo Motors

Dalganın frekansı f=50 Hz ve periyodu T=20 ms

Görev Çevrimi (Duty Cycle) değiştirilince açı değişiyor.

Page 14: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Servo Motorların İç Yapısı ve Çalışma Prensibi

http://www.youtube.com/watch?v=v2jpnyKPH64

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.

Page 15: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Bağlantı Şeması

Page 16: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Servo Kütüphanesi (<Servo.h>) ve Potansiyometre ile Servo Açısının Kontrolü

File->Examples->Servo Yolundaki Tüm Örnekleri Tek Tek Çalıştırınız.

// Controlling a servo position using a potentiometer (variable resistor) // by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> #include <Servo.h> //include the libraryServo 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() { 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 }

Page 17: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

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.

Page 18: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

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. (ß -> 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.

Page 19: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Arduino ile DC Motor Kontrolü

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.

1N4007

Motor+Diyot yerine LED+Direnç bağlayarak bir sonraki slayttaki kodu tekrar çalıştırınız.

Page 20: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

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); }}

Page 21: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Şimdi de Motorun Bağlantı Uçlarını Değiştirin…

Page 22: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

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.

Page 23: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

H-Bridge (H-Köprüsü)

Page 24: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

L293D Dual H-Bridge Motor Driver

Page 25: BM-305 Mikrodenetleyiciler Güz 2015 (10. Sunu) (Yrd. Doç. Dr. Deniz Dal)

L293D Dual H-Bridge Motor Driver