E-Book Arduino - WordPress.com

Transkript

E-Book Arduino - WordPress.com
ARDUİNO PROJESİ
Arduino Kullanarak
Android Bluetooth Uygulama ile
RC Araba Kontrolü
Aminou Zakara Tahirou
PROJEYİ YAPMAK İÇİN GEREKEN MALZEMELER
1. Arduino (Herhangi bir arduino olabilir)
2. Motor Sürücüsü (L293D)
3. Arduino Bluetooth
4. Arduino Kabloları (Erkek-Erkek)
5. Arduino Mini BreadBoard
6. 9V Batarya
7.Arduino Batarya Kablosu
8. RC Araba (Eskisi de olabilir)
1. Arduino
Bu projede Arduino UNO kullanıldı.
Projeyi başlamadan önce kullanılacak arduino türü ve arduinonun
port türü çok önemlidir.
Arduinoyu bilgisayara takıldığında hiç bir şey yapmadan:
Araçlar kısmından Kart kısmına girip kullanılacak arduino
türü işaretlenmelidir.
Araçlar kısmından yine Port kısmında arduinonun port türü
işaretlenmelidir.
2.Motor Sürücüsü (L293D)
Motor Sürücüsü arabanın motorlarının hareket etirmesini sağlar.
Bu projede motor sürücüsünde iki tane motor bağlanılacaktır.
Birincisi arabanın ön tekerler için bir ve ikincisi arka tekerler için
kullanılacaktır.
Motor sürücüsüsünde de arduino bataryadan bağımsız kendi bataryası ile çalışılmaktadır.
Motor sürücüsü arduino üzerinde yerleştirilcektir.
3. Arduino Bluetooth
Bu bluetooth kullanarak android uygulama ile bağlanıp arabamızın
uzaktan kontro ettirilmeyi sağlar.
Bluetooth’un TX kablosu Arduinonun RX a bağlanmalıdır.
Bluetooth’un RX kablosu Arduinounun TX a bağlanmalıdır.
Bluetooth’un GND ---> Arduino GND
Bluetooth’un +5V ---> Arduino +5V
Not: Bluetooth TX ---> Arduino RX
Bluetooth RX ---> Arduino TX
4. Arduino Kabloları (Erkek-Erkek)
Kablolar projemizin süresinde birbirlerine bağlanmak gereken yerlere birbirlerine bağlanmamızı sağlar.
En az 4 dört tane kablo kullnılacaktır.
5. Arduino Mini BreadBoard
Bu projede mini breadboard sadece bluetooth içn kullanılacaktır.
6. 9V Batarya
Batarya projemiz bittikten sonre, arduino bilgisayardan bağımsız
olarak kullanmamızı sağlar.
7. Arduino Batarya Kablosu
Adısı gibi batarya kablosu, bataryayı takarak kullanılmaktadır.
8. RC Araba (Eskisi de olabilir)
Arabanın eskisi de olabilir, yeter ki motorları sağlam olsunlar.
Uzaktan kumandalı arabayı kullanılacaktır.
Arabın motorları, ışıkları, pillerin koyulacak yeri kullanılacaktır.
Sadece arabaının kabloları tabanı kullanılmayacaktır.
Kütüphane Ekleme
Arduino programın ayarlarında Taslak --->Library ekle kısmında bunu(Adafruit Motor Shield) ekli olup olmadığını kontrol edilmelidir.
Eğer ekli ise kodlar kısmına geçebiliriz.
Değilse onun internetten indirilecek, masa üstünde atılacak, dosya adının
yerine “AFMotor” yazarak değiştirilecek.
Dosyayı alıp arduino bilgisayarin (C:) yerel dik e girip arduinonun kütüphanesine girerek yapıştırılacak.
Sonra Arduino programı kapatıp açılmalıdır.
Tekrar Taslak --->Library(kütüphane) ekle kısmında “Adafruit Motor
Shield” ekli olacaktır.
Sonrada kodları yazılabilecektir.
Projenin Kodları
//-------------------------------------------------------------------------------------------------------------------------------------//Basic Remote Control Car - Bill Tarpy - North East CoderDojo
17/01/2015
//Feel free to use this software as a basis for your own.
#include <SoftwareSerial.h> //the library for seial communication
#include <AFMotor.h> // the library for the Adafruit L293 Arduino Motor
Shield
int incomingByte = 0; // for incoming serial data
int speed_min = 135; //the minimum “speed” the motors will turn - take it
lower and motors don’t turn
int speed_max = 255; //the maximum “speed” the motors will turn – you
can’t put in higher
int speed_left = speed_max; // set both motors to maximum speed
int speed_right = speed_max;
//as we added a Motor Shield Library we can just use the following code to
define our M1 and M2 motors and their PWM frequency
//the library takes care of all the complexity of the physical interface the
Arduino uses to talk to the shield and the motor
AF_DCMotor motor_left(1, MOTOR12_1KHZ); // create motor #1, 1KHz
pwm
AF_DCMotor motor_right(4, MOTOR12_1KHZ); // create motor #2,
1KHz pwm
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps - this is the speed the
serial interface will work at
Serial.println(“Motor test!”);// display message for test purposes when connected to a serial monitor
}
void loop() {
//this is our repeating loop - that will go round and round until we switch
the Arduino off
motor_left.setSpeed(speed_left); // minimum speed 135 max speed 255
motor_right.setSpeed(speed_right); // minimum speed 135 max speed
255
//first check if there is anything on the serial interface
//we are using the Arduino’s default serial interface (pins 0 and 1)so no
need to define these
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
}
// if there is something on the serial interface it is read and assigned to
incomingByte
// we then use a SWITCH (case) statement which, depending on incomingByte, does different things
// it runs the left and right motors to produce movement Forward, Backward, Left, Right or Stop
//that’s all there is to it!
switch(incomingByte)
{
case ‘S’:
// stop all motors
{ motor_left.run(RELEASE); // stopped
motor_right.run(RELEASE); // stopped
Serial.println(“Stop\n”); //display message for test purposes when connected to a serial monitor
incomingByte=’*’;}
break;
case ‘F’:
// turn it on going forward
{ motor_left.run(FORWARD);
Serial.println(“Forward\n”);//display message for test purposes when
connected to a serial monitor
incomingByte=’*’;}
break;
case ‘B’:
// turn it on going backward
{ motor_left.run(BACKWARD);
Serial.println(“Backward\n”);//display message for test purposes when
connected to a serial monitor
incomingByte=’*’;}
break;
case ‘R’:
// turn right
{
motor_right.run(FORWARD);
Serial.println(“Rotate Right\n”);//display message for test purposes
incomingByte=’*’;}
break;
case ‘L’:
// turn left
{
motor_right.run(BACKWARD);
Serial.println(“Rotate Left\n”);//display message for test purposes
incomingByte=’*’;}
break;
case ‘1’:
// Put what you like in here - for example - change the motor speeds
{ speed_left = speed_min; // set both motors to minimum speed
speed_right = speed_min;
Serial.println(“Speed 1\n”);//display message for test purposes
incomingByte=’*’;}
break;
case ‘2’:
// Put what you like in here - for example - turn on some LED lights
on the car
{
Serial.println(“Lights on\n”);//display message for test purposes
//why not use the motor sheild’s spre motors - M3 and M4 - to turn
lights on and off
//you would need to define M3/4 in your program setup, and a few
extra veriables to hold values
//then FORWARD and BACKWARD would send a voltage one way
then the other through the M3 and M4 terminals as you require
}
incomingByte=’*’;}
break;
}
//----------------------------------------------------------------------------------------------------------------------
Projenin Şeması
REFERANS:
http://wirebeings.com/Android-RC-CAR.html
https://learn.adafruit.com/adafruit-motor-shield/library-install
HAZIRLAYANLAR:
Aminou Zakara Tahirou
E-mail: [email protected]
g-mail: [email protected]

Benzer belgeler

E-book - WordPress.com

E-book - WordPress.com int incomingByte = 0; // for incoming serial data int speed_min = 135; //the minimum “speed” the motors will turn - take it lower and motors don’t turn int speed_max = 255; //the maximum “speed” th...

Detaylı