Elektroda.pl
Elektroda.pl
X
Please add exception to AdBlock for elektroda.pl.
If you watch the ads, you support portal and users.

Zdalnie sterowany samochodzik z Bluetooth i Arduino

ghost666 19 Sep 2015 19:03 25269 11
  • Zdalnie sterowany samochodzik z Bluetooth i Arduino
    Poniższy projekt opisuje, jak zbudować zdalnie sterowany samochodzik oparty o moduł Arduino. Kontrola jego ruchów odbywa się poprzez interfejs Bluetooth i prostą aplikację na telefon z systemem Android.

    Krok 1: elementy

    Zdalnie sterowany samochodzik z Bluetooth i Arduino Zdalnie sterowany samochodzik z Bluetooth i Arduino Zdalnie sterowany samochodzik z Bluetooth i Arduino Zdalnie sterowany samochodzik z Bluetooth i Arduino


    Do złożenia prezentowanego pojazdu potrzebne nam są:

    1. Moduł Arduino Uno, Micro, Mega, Duo lub Leonardo.
    2. Platforma mechaniczna - silniki wraz z podwoziem.
    3. Sterownik silników oparty np. o L298n.
    4. Moduł Bluetooth Hc-06.
    5. Bateria 9 V.
    6. Uchwyt baterii 9 V.
    7. Urządzenie z Androidem, np. telefon.

    Krok 2: programowanie

    Zdalnie sterowany samochodzik z Bluetooth i Arduino


    Poniżej znajduje się kod programu do modułu Arduino. Wystarczy skopiować go do Arduino IDE i wgrać do mikrokontrolera.

    Code: c
    Log in, to see the code


    Krok 3: Aplikacja na Androida

    Zdalnie sterowany samochodzik z Bluetooth i Arduino


    Wykorzystana aplikacja jest bardzo prosta, pozwala na wydawanie szeregu komend - UP, DOWN, RIGHT, LEFT, UPRIGHT itp - wyposażona jest także w slider i inne przydatne elementy, pozwalające na sterowanie przez nią rozmaitych pojazdów zdalnie sterowanych. Wymaga ona do zainstalowania Androida w wersji co najmniej 2.3.3 Pobrać ją można stąd:https://sites.google.com/site/bluetoothrccar/

    Krok 4: połączenie wszystkich elementów

    Zdalnie sterowany samochodzik z Bluetooth i Arduino


    Elementy samochodziku połączyć trzeba tak, jak pokazano na powyższym rysunku. Po połączeniu wszystkich elementów i wgraniu programu do Arduino oraz zainstalowaniu aplikacji wszystko jest już gotowe - można uruchamiać pojazd.

    Miłej zabawy!

    Żródło: http://www.instructables.com/id/Arduino-Bluetooth-RC-car-1/?ALLSTEPS

    Cool? Ranking DIY
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
    About Author
    ghost666
    Translator, editor
    Offline 
    Fizyk z wykształcenia. Po zrobieniu doktoratu i dwóch latach pracy na uczelni, przeszedł do sektora prywatnego, gdzie zajmuje się projektowaniem urządzeń elektronicznych i programowaniem. Od 2003 roku na forum Elektroda.pl, od 2008 roku członek zespołu redakcyjnego.
    ghost666 wrote 11695 posts with rating 9880, helped 157 times. Live in city Warszawa. Been with us since 2003 year.
  • #2
    treker
    Level 25  
    Zasilanie konstrukcji z silnikami baterią 9V, to chyba najgorsze możliwe rozwiązania. Nowa bateria będzie potrzebna co kilka minut... Do tego L298N z dużym spadkiem napięcia. Znacznie lepiej pasowałby tutaj taki mały moduł dedykowany do Arduino: https://www.pololu.com/product/2511
  • #3
    Therotos
    Level 10  
    Brakuje dwóch metod: Auto() oraz Manual().
  • #4
    ghost666
    Translator, editor
    Therotos wrote:
    Brakuje dwóch metod: Auto() oraz Manual().


    Istotnie. Nie bez powodu ich nie publikowałem:

    Code: c
    Log in, to see the code
  • #5
    Therotos
    Level 10  
    Ok, to wtedy usuń z kodu wywoływanie tych metod, bo potem wywala błąd w czasie kompilacji. Nie, żeby to było trudne do znalezienia, ale jeśli coś robimy to róbmy to porządnie.

    ghost666 wrote:
    Therotos wrote:
    Brakuje dwóch metod: Auto() oraz Manual().


    Istotnie. Nie bez powodu ich nie publikowałem:

    Code: c
    Log in, to see the code
  • #7
    csaa
    Level 1  
    Jakby co to oprogramowanie jest dostępne na Google Play :)
  • #8
    Dark PL
    Level 6  
    A czy zamiast modułu bluetooth HC-06 mogę podłączyć jakiś mocniejszy np: HM-10 ?
  • #9
    tomekrx18
    Level 8  
    Hej połączyłem się z autkiem ale nic sie nie dzieje po klikaniu na aplikacji ktoś wie w czym problem?
  • #10
    domeno1204
    Level 7  
    Wstawi ktoś poprawnie działający kod?
  • #11
    zlotyzabek
    Level 2  
    Cały kod z poprawkami :

    /Version 2.1 By Owen Sobel
    #define in1 5 //L298n Motor Driver pins.
    #define in2 6
    #define in3 10
    #define in4 11
    #define LED 13
    int command; //Int to store app command state.
    int Speed = 204; // 0 - 255.
    int Speedsec;
    int Turnradius = 0; //Set the radius of a turn, 0 - 255 Note:the robot will malfunction if this is higher than int Speed, if it is, pin13 will be HIGH. Useful for debugging.
    int button; // Store how many times a button has been pressed.
    void setup() {
    pinMode(in1, OUTPUT);
    pinMode(in2, OUTPUT);
    pinMode(in3, OUTPUT);
    pinMode(in4, OUTPUT);
    pinMode(LED, OUTPUT); //Set the LED pin.
    Serial.begin(9600); //Set the baud rate to your Bluetooth module.
    }

    void loop() {
    if (Turnradius > Speed) {
    Serial.write("Error : Code 01 ");
    digitalWrite(LED, HIGH);
    delay(1000);
    }
    else {
    digitalWrite(LED, LOW);
    }

    if (Speed > 255) {
    Serial.write("Error : Code 02 ");
    digitalWrite(LED, HIGH);
    delay(1000);
    }
    else {
    digitalWrite(LED, LOW);
    }
    Button();
    if (Serial.available() > 0) {
    command = Serial.read();
    Stop(); //Initialize with motors stoped.
    switch (command) {
    case 'F':
    forward();
    button = button + 1;
    break;
    case 'B':
    back();
    button = button + 1;
    break;
    case 'L':
    left();
    button = button + 1;
    break;
    case 'R':
    right();
    button = button + 1;
    break;
    case 'G':
    forwardleft();
    button = button + 1;
    break;
    case 'I':
    forwardright();
    button = button + 1;
    break;
    case 'H':
    backleft();
    button = button + 1;
    break;
    case 'J':
    backright();
    button = button + 1;
    break;
    case '0':
    Speed = 100;
    break;
    case '1':
    Speed = 140;
    break;
    case '2':
    Speed = 153;
    break;
    case '3':
    Speed = 165;
    break;
    case '4':
    Speed = 178;
    break;
    case '5':
    Speed = 191;
    break;
    case '6':
    Speed = 204;
    break;
    case '7':
    Speed = 216;
    break;
    case '8':
    Speed = 229;
    break;
    case '9':
    Speed = 242;
    break;
    case 'q':
    Speed = 255;
    break;
    case 'X':
    break;
    case 'x':

    break;
    }

    Speedsec = Turnradius;
    }
    }
    void Button () {
    Serial.print("button = ");
    Serial.print(button);
    Serial.println(" ");
    delay(300);
    }

    void forward() {
    analogWrite(in1, Speed);
    analogWrite(in3, Speed);
    }

    void back() {
    analogWrite(in2, Speed);
    analogWrite(in4, Speed);
    }

    void left() {
    analogWrite(in3, Speed);
    analogWrite(in2, Speed);
    }

    void right() {
    analogWrite(in4, Speed);
    analogWrite(in1, Speed);
    }
    void forwardleft() {
    analogWrite(in1, Speedsec);
    analogWrite(in3, Speed);
    }
    void forwardright() {
    analogWrite(in1, Speed);
    analogWrite(in3, Speedsec);
    }
    void backright() {
    analogWrite(in2, Speed);
    analogWrite(in4, Speedsec);
    }

    void backleft() {
    analogWrite(in2, Speedsec);
    analogWrite(in4, Speed);
    }

    void Stop() {
    analogWrite(in1, 0);
    analogWrite(in2, 0);
    analogWrite(in3, 0);
    analogWrite(in4, 0);
    }
  • #12
    Lactriksen
    Level 5  
    Nie chce mi się wgrać do arduino, pisze "Szkic używa 3134 bajtów (9%) pamięci programu. Maksimum to 32256 bajtów.
    Zmienne globalne używają 240 bajtów (11%) pamięci dynamicznej, pozostawiając 1808 bajtów dla zmiennych lokalnych. Maksimum to 2048 bajtów."
    A samochodzik jeździ dopóki nie odłączę go od komputera.

    zlotyzabek wrote:
    Cały kod z poprawkami :

    /Version 2.1 By Owen Sobel
    #define in1 5 //L298n Motor Driver pins.
    #define in2 6
    #define in3 10
    #define in4 11
    #define LED 13
    int command; //Int to store app command state.
    int Speed = 204; // 0 - 255.
    int Speedsec;
    int Turnradius = 0; //Set the radius of a turn, 0 - 255 Note:the robot will malfunction if this is higher than int Speed, if it is, pin13 will be HIGH. Useful for debugging.
    int button; // Store how many times a button has been pressed.
    void setup() {
    pinMode(in1, OUTPUT);
    pinMode(in2, OUTPUT);
    pinMode(in3, OUTPUT);
    pinMode(in4, OUTPUT);
    pinMode(LED, OUTPUT); //Set the LED pin.
    Serial.begin(9600); //Set the baud rate to your Bluetooth module.
    }

    void loop() {
    if (Turnradius > Speed) {
    Serial.write("Error : Code 01 ");
    digitalWrite(LED, HIGH);
    delay(1000);
    }
    else {
    digitalWrite(LED, LOW);
    }

    if (Speed > 255) {
    Serial.write("Error : Code 02 ");
    digitalWrite(LED, HIGH);
    delay(1000);
    }
    else {
    digitalWrite(LED, LOW);
    }
    Button();
    if (Serial.available() > 0) {
    command = Serial.read();
    Stop(); //Initialize with motors stoped.
    switch (command) {
    case 'F':
    forward();
    button = button + 1;
    break;
    case 'B':
    back();
    button = button + 1;
    break;
    case 'L':
    left();
    button = button + 1;
    break;
    case 'R':
    right();
    button = button + 1;
    break;
    case 'G':
    forwardleft();
    button = button + 1;
    break;
    case 'I':
    forwardright();
    button = button + 1;
    break;
    case 'H':
    backleft();
    button = button + 1;
    break;
    case 'J':
    backright();
    button = button + 1;
    break;
    case '0':
    Speed = 100;
    break;
    case '1':
    Speed = 140;
    break;
    case '2':
    Speed = 153;
    break;
    case '3':
    Speed = 165;
    break;
    case '4':
    Speed = 178;
    break;
    case '5':
    Speed = 191;
    break;
    case '6':
    Speed = 204;
    break;
    case '7':
    Speed = 216;
    break;
    case '8':
    Speed = 229;
    break;
    case '9':
    Speed = 242;
    break;
    case 'q':
    Speed = 255;
    break;
    case 'X':
    break;
    case 'x':

    break;
    }

    Speedsec = Turnradius;
    }
    }
    void Button () {
    Serial.print("button = ");
    Serial.print(button);
    Serial.println(" ");
    delay(300);
    }

    void forward() {
    analogWrite(in1, Speed);
    analogWrite(in3, Speed);
    }

    void back() {
    analogWrite(in2, Speed);
    analogWrite(in4, Speed);
    }

    void left() {
    analogWrite(in3, Speed);
    analogWrite(in2, Speed);
    }

    void right() {
    analogWrite(in4, Speed);
    analogWrite(in1, Speed);
    }
    void forwardleft() {
    analogWrite(in1, Speedsec);
    analogWrite(in3, Speed);
    }
    void forwardright() {
    analogWrite(in1, Speed);
    analogWrite(in3, Speedsec);
    }
    void backright() {
    analogWrite(in2, Speed);
    analogWrite(in4, Speedsec);
    }

    void backleft() {
    analogWrite(in2, Speedsec);
    analogWrite(in4, Speed);
    }

    void Stop() {
    analogWrite(in1, 0);
    analogWrite(in2, 0);
    analogWrite(in3, 0);
    analogWrite(in4, 0);
    }