This shows you the differences between two versions of the page.
pm:prj2021:abirlica:joystick_car [2021/06/03 19:48] bogdan_andrei.zat |
pm:prj2021:abirlica:joystick_car [2021/06/04 18:07] (current) bogdan_andrei.zat |
||
---|---|---|---|
Line 19: | Line 19: | ||
*2 baterii 9V | *2 baterii 9V | ||
*4 roti | *4 roti | ||
- | *modul bluetooth HC-05 | + | *2 module bluetooth HC-05 |
===== Schema bloc ===== | ===== Schema bloc ===== | ||
Line 41: | Line 41: | ||
* Librarii folosite: SoftwareSerial.h | * Librarii folosite: SoftwareSerial.h | ||
</note> | </note> | ||
+ | |||
+ | {{ :pm:prj2021:abirlica:diagrama_zat_bogdan_andrei.png?500 |}} | ||
=== Configurare module bluetooth === | === Configurare module bluetooth === | ||
- | Pentru realizarea conexiunii intre telecomanda si masinuta am configurat dele 2 module bluetooth astfel: unul master, iar celalalt slave. Pentru a realiza aceasta configuratie a fost nevoie sa intru in modul de comanda AT pentru cele doua module HC-05 folosind urmatorul cod: | + | Pentru realizarea conexiunii intre telecomanda si masinuta am configurat cele 2 module bluetooth astfel: unul master, iar celalalt slave. Pentru a realiza aceasta configuratie a fost nevoie sa intru in modul de comanda AT pentru cele doua module HC-05 folosind urmatorul cod: |
+ | <code> | ||
#include <SoftwareSerial.h> | #include <SoftwareSerial.h> | ||
Line 63: | Line 66: | ||
MyBlue.write(Serial.read()); | MyBlue.write(Serial.read()); | ||
} | } | ||
+ | </code> | ||
Cu ajutorul librariei SoftwareSerial am reusit sa accesez modul de comanda pentru modulele bluetooth fara a fi nevoie sa folosesc pinii Rx si Tx de pe placuta arduino(era nevoie de un divizor de tensiune, si nu am avut rezistentele necesare). | Cu ajutorul librariei SoftwareSerial am reusit sa accesez modul de comanda pentru modulele bluetooth fara a fi nevoie sa folosesc pinii Rx si Tx de pe placuta arduino(era nevoie de un divizor de tensiune, si nu am avut rezistentele necesare). | ||
Line 76: | Line 79: | ||
*Cod sursa masinuta: | *Cod sursa masinuta: | ||
+ | |||
+ | <code> | ||
+ | #include <SoftwareSerial.h> | ||
+ | |||
+ | SoftwareSerial MyBlue(10, 11); | ||
+ | int xPosition; | ||
+ | int yPosition; | ||
+ | int x; | ||
+ | int y; | ||
+ | int motorSpeedA1; | ||
+ | int motorSpeedA2; | ||
+ | int motorSpeedB1; | ||
+ | int motorSpeedB2; | ||
+ | |||
+ | #define enA 5 //dreapta jos | ||
+ | #define in1 6 | ||
+ | #define in2 7 | ||
+ | #define in3 4 | ||
+ | #define in4 2 | ||
+ | #define enB 3 //stanga jos | ||
+ | #define enA_2 A1 //stanga sus | ||
+ | #define in1_2 12 | ||
+ | #define in2_2 13 | ||
+ | #define enB_2 A0 //dreapta sus | ||
+ | #define in3_2 9 | ||
+ | #define in4_2 8 | ||
+ | |||
+ | void setup() { | ||
+ | // put your setup code here, to run once: | ||
+ | pinMode(enA, OUTPUT); | ||
+ | pinMode(enB, OUTPUT); | ||
+ | pinMode(in1, OUTPUT); | ||
+ | pinMode(in2, OUTPUT); | ||
+ | pinMode(in3, OUTPUT); | ||
+ | pinMode(in4, OUTPUT); | ||
+ | pinMode(enA_2, OUTPUT); | ||
+ | pinMode(enB_2, OUTPUT); | ||
+ | pinMode(in1_2, OUTPUT); | ||
+ | pinMode(in2_2, OUTPUT); | ||
+ | pinMode(in3_2, OUTPUT); | ||
+ | pinMode(in4_2, OUTPUT); | ||
+ | |||
+ | MyBlue.begin(9600); | ||
+ | state = 1; | ||
+ | } | ||
+ | |||
+ | void move_forward() { | ||
+ | digitalWrite(in1,LOW); | ||
+ | digitalWrite(in2, HIGH); | ||
+ | digitalWrite(in4,HIGH); | ||
+ | digitalWrite(in3, LOW); | ||
+ | digitalWrite(in1_2,HIGH); | ||
+ | digitalWrite(in2_2, LOW); | ||
+ | digitalWrite(in4_2,HIGH); | ||
+ | digitalWrite(in3_2, LOW); | ||
+ | } | ||
+ | |||
+ | void move_backward() { | ||
+ | digitalWrite(in1,HIGH); | ||
+ | digitalWrite(in2, LOW); | ||
+ | digitalWrite(in4,LOW); | ||
+ | digitalWrite(in3, HIGH); | ||
+ | digitalWrite(in1_2,LOW); | ||
+ | digitalWrite(in2_2, HIGH); | ||
+ | digitalWrite(in4_2,LOW); | ||
+ | digitalWrite(in3_2, HIGH); | ||
+ | } | ||
+ | |||
+ | void stop_car() { | ||
+ | digitalWrite(in1,LOW); | ||
+ | digitalWrite(in2, LOW); | ||
+ | digitalWrite(in3,LOW); | ||
+ | digitalWrite(in4, LOW); | ||
+ | digitalWrite(in1_2,LOW); | ||
+ | digitalWrite(in2_2, LOW); | ||
+ | digitalWrite(in3_2,LOW); | ||
+ | digitalWrite(in4_2, LOW); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | // put your main code here, to run repeatedly: | ||
+ | |||
+ | x = 510/4; | ||
+ | y = 510/4; | ||
+ | |||
+ | while (MyBlue.available() >= 2) { | ||
+ | y = MyBlue.read(); | ||
+ | x = MyBlue.read(); | ||
+ | } | ||
+ | | ||
+ | xPosition = x*4; | ||
+ | yPosition = y*4; | ||
+ | | ||
+ | if (yPosition < 470) { | ||
+ | | ||
+ | move_forward(); | ||
+ | motorSpeedA1 = map(yPosition, 470, 0, 0, 255); | ||
+ | motorSpeedB2 = map(yPosition, 470, 0, 0, 255); | ||
+ | motorSpeedA2 = map(yPosition, 470, 0, 0, 255); | ||
+ | motorSpeedB2 = map(yPosition, 470, 0, 0, 255); | ||
+ | | ||
+ | delay(10); | ||
+ | } else if (yPosition > 550) { | ||
+ | | ||
+ | move_backward(); | ||
+ | motorSpeedA1 = map(yPosition, 550, 1023, 0, 255); | ||
+ | motorSpeedB1 = map(yPosition, 550, 1023, 0, 255); | ||
+ | motorSpeedA2 = map(yPosition, 550, 1023, 0, 255); | ||
+ | motorSpeedB2 = map(yPosition, 550, 1023, 0, 255); | ||
+ | | ||
+ | delay(10); | ||
+ | } else { | ||
+ | motorSpeedA1 = 0; | ||
+ | motorSpeedA2 = 0; | ||
+ | motorSpeedB1 = 0; | ||
+ | motorSpeedB2 = 0; | ||
+ | stop_car(); | ||
+ | } | ||
+ | |||
+ | //vireaza la dreapta | ||
+ | if (xPosition < 470) { | ||
+ | int mapX = map(xPosition, 470, 0, 0, 255); | ||
+ | motorSpeedA1 = motorSpeedA1 + mapX; | ||
+ | motorSpeedB1 = motorSpeedB1 - mapX; | ||
+ | motorSpeedA2 = motorSpeedA2 + mapX; | ||
+ | motorSpeedB2 = motorSpeedB2 - mapX; | ||
+ | |||
+ | if (motorSpeedA1 < 0) { | ||
+ | motorSpeedA1 = 0; | ||
+ | } | ||
+ | if (motorSpeedB1 > 255) { | ||
+ | motorSpeedB1 = 255; | ||
+ | } | ||
+ | if (motorSpeedA2 < 0) { | ||
+ | motorSpeedA2 = 0; | ||
+ | } | ||
+ | if (motorSpeedB2 > 255) { | ||
+ | motorSpeedB2 = 255; | ||
+ | } | ||
+ | //vireaza la stanga | ||
+ | } else if (xPosition > 550) { | ||
+ | int mapX = map(xPosition, 550, 1023, 0, 255); | ||
+ | motorSpeedA1 = motorSpeedA1 - mapX; //stanga | ||
+ | motorSpeedB1 = motorSpeedB1 + mapX; //drepta | ||
+ | motorSpeedA2 = motorSpeedA2 - mapX; //stanga | ||
+ | motorSpeedB2 = motorSpeedB2 + mapX; //dreapta | ||
+ | |||
+ | if (motorSpeedA1 > 255) { | ||
+ | motorSpeedA1 = 255; | ||
+ | } | ||
+ | if (motorSpeedB1 < 0) { | ||
+ | motorSpeedB1 = 0; | ||
+ | } | ||
+ | if (motorSpeedA2 > 255) { | ||
+ | motorSpeedA2 = 255; | ||
+ | } | ||
+ | if (motorSpeedB2 < 0) { | ||
+ | motorSpeedB2 = 0; | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | |||
+ | analogWrite(enA, motorSpeedB1); | ||
+ | analogWrite(enB, motorSpeedA1); | ||
+ | analogWrite(enA_2, motorSpeedA2); | ||
+ | analogWrite(enB_2, motorSpeedB2); | ||
+ | } | ||
+ | </code> | ||
+ | |||
*Cod sursa telecomanda: | *Cod sursa telecomanda: | ||
- | ===== O poza cu statusul curent ^_^ ===== | + | <code> |
+ | |||
+ | #include <SoftwareSerial.h> | ||
+ | |||
+ | SoftwareSerial MyBlue(10, 11); | ||
+ | |||
+ | int VRx = A1; | ||
+ | int VRy = A0; | ||
+ | int SW = 2; | ||
+ | |||
+ | int xPosition = 0; | ||
+ | int yPosition = 0; | ||
+ | int SW_state = 0; | ||
+ | int mapX = 0; | ||
+ | int mapY = 0; | ||
+ | |||
+ | void setup() { | ||
+ | |||
+ | pinMode(VRx, INPUT); | ||
+ | pinMode(VRy, INPUT); | ||
+ | pinMode(SW, INPUT_PULLUP); | ||
+ | |||
+ | MyBlue.begin(9600); | ||
+ | |||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | xPosition = analogRead(VRx); | ||
+ | yPosition = analogRead(VRy); | ||
+ | SW_state = digitalRead(SW); | ||
+ | |||
+ | MyBlue.write(xPosition/4); | ||
+ | MyBlue.write(yPosition/4); | ||
+ | } | ||
+ | |||
+ | </code> | ||
+ | |||
+ | ===== Concluzii ===== | ||
+ | |||
+ | Ideea de a face un proiect fizic cu arduino mi s-a parut una foare interesanta inca de cand am aflat prima data. Mi-a placut foarte mult sa lucrez la masinuta mea cu telecomanda si cred ca motivul principat este ca pana acum n-am mai avut un proiect fizic de realizat, ceva din care sa avem un produs finit, nu doar virtual. Poate ca asta a fost singura materie din facultate la care voi face asa ceva, ceea ce m-a facut sa fiu foarte entuziasmat in realizarea proiectului. Pot spune ca am invatat foarte multe in tot timpul in care am lucrat la proiect, iar cea mai mare provocare consider ca a fost sa configurez modulele bluetooth si sa reusesc sa transmit datele cum trebuie de la telecomanda la masinuta. A fost nevoie de multe cautari pana am reusit intr-un final. | ||
+ | |||
+ | ===== Galerie foto ^_^ ===== | ||
{{ :pm:prj2021:abirlica:poza_masinuta_zat_bogdan_andrei.jpeg?500 |}} | {{ :pm:prj2021:abirlica:poza_masinuta_zat_bogdan_andrei.jpeg?500 |}} | ||
+ | |||
+ | {{ :pm:prj2021:abirlica:masinuta1_zat_bogdan.jpeg?300 |}} | ||
+ | |||
+ | {{ :pm:prj2021:abirlica:masinuta2_zat_bogdan.jpeg?300 |}} | ||
+ | |||
+ | {{ :pm:prj2021:abirlica:masinuta3_zat_bogdan.jpeg?300 |}} | ||
+ | |||
+ | {{ :pm:prj2021:abirlica:masinuta4_zat_bogdan.jpeg?500 |}} | ||
+ | |||
+ | {{ :pm:prj2021:abirlica:masinuta_poza_smechera.jpeg?700 |}} | ||
+ | |||
+ | ===== Video ===== | ||
+ | |||
+ | Link catre video: https://www.youtube.com/watch?v=5S7FXWg-9R0 | ||
+ | |||
+ | <html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | ||
+ |