logo elektroda
logo elektroda
X
logo elektroda
Adblock/uBlockOrigin/AdGuard mogą powodować znikanie niektórych postów z powodu nowej reguły.

Zdalnie sterowany samochodzik z Bluetooth i Arduino

ghost666 19 Wrz 2015 19:03 26157 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.

    Kod: C / C++
    Zaloguj się, aby zobaczyć kod


    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

    Fajne? Ranking DIY
    O autorze
    ghost666
    Tłumacz Redaktor
    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.
    https://twitter.com/Moonstreet_Labs
    ghost666 napisał 11960 postów o ocenie 10197, pomógł 157 razy. Mieszka w mieście Warszawa. Jest z nami od 2003 roku.
  • #2 15007233
    treker
    Poziom 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 15010290
    Therotos
    Poziom 10  
    Brakuje dwóch metod: Auto() oraz Manual().
  • #4 15010297
    ghost666
    Tłumacz Redaktor
    Therotos napisał:
    Brakuje dwóch metod: Auto() oraz Manual().


    Istotnie. Nie bez powodu ich nie publikowałem:

    Kod: C / C++
    Zaloguj się, aby zobaczyć kod
  • #5 15010343
    Therotos
    Poziom 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 napisał:
    Therotos napisał:
    Brakuje dwóch metod: Auto() oraz Manual().


    Istotnie. Nie bez powodu ich nie publikowałem:

    Kod: C / C++
    Zaloguj się, aby zobaczyć kod
  • #7 16072356
    csaa
    Poziom 1  
    Jakby co to oprogramowanie jest dostępne na Google Play :)
  • #8 16668097
    Dark PL
    Poziom 6  
    A czy zamiast modułu bluetooth HC-06 mogę podłączyć jakiś mocniejszy np: HM-10 ?
  • #9 16874220
    tomekrx18
    Poziom 8  
    Hej połączyłem się z autkiem ale nic sie nie dzieje po klikaniu na aplikacji ktoś wie w czym problem?
  • #10 17225182
    domeno1204
    Poziom 7  
    Wstawi ktoś poprawnie działający kod?
  • #11 18539491
    zlotyzabek
    Poziom 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 19003582
    Lactriksen
    Poziom 6  
    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 napisał:
    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);
    }
REKLAMA