This shows you the differences between two versions of the page.
|
pm:prj2021:avaduva:bluetoothwheelchair [2021/06/02 10:18] andrei.diaconu2311 |
pm:prj2021:avaduva:bluetoothwheelchair [2021/06/02 10:35] (current) andrei.diaconu2311 |
||
|---|---|---|---|
| Line 27: | Line 27: | ||
| -Folosesc functia de setup pentru a seta pinii de output | -Folosesc functia de setup pentru a seta pinii de output | ||
| -Folosesc o functie de loop in care preiau comenzile din bluetooth si verific ce comanda am, calculez distanta masurata de senzorul ultrasonic, aprind si sting becul si activez buzzer-ul la apasarea unui buton din telefon. | -Folosesc o functie de loop in care preiau comenzile din bluetooth si verific ce comanda am, calculez distanta masurata de senzorul ultrasonic, aprind si sting becul si activez buzzer-ul la apasarea unui buton din telefon. | ||
| + | ==== Rezultate Obtinute ==== | ||
| + | {{:pm:prj2021:avaduva:poza1.jpeg?200|}} | ||
| + | {{:pm:prj2021:avaduva:poza2.jpeg?200|}} | ||
| + | {{:pm:prj2021:avaduva:poza3.jpeg?200|}} | ||
| + | {{:pm:prj2021:avaduva:poza6.jpeg?200|}} | ||
| ==== DEMO ==== | ==== DEMO ==== | ||
| https://www.youtube.com/watch?v=5PakJnpXK68&ab_channel=AndreiDiaconu | https://www.youtube.com/watch?v=5PakJnpXK68&ab_channel=AndreiDiaconu | ||
| ==== COD ==== | ==== COD ==== | ||
| - | #include <SoftwareSerial.h> | + | #include <SoftwareSerial.h> |
| - | SoftwareSerial hc05(0, 1); | + | SoftwareSerial hc05(0, 1); |
| - | int motorLeft1 = 2; | + | int motorLeft1 = 2; |
| - | int motorLeft2 = 3; | + | int motorLeft2 = 3; |
| - | int motorRight1 = 4; | + | int motorRight1 = 4; |
| - | int motorRight2 = 5; | + | int motorRight2 = 5; |
| - | int trigPin = 9; // Trig Pin | + | int trigPin = 9; // Trig Pin |
| - | int echoPin = 8; // Echo Pin | + | int echoPin = 8; // Echo Pin |
| - | int distance; | + | int distance; |
| - | long duration; | + | long duration; |
| - | int light = 6; | + | int light = 6; |
| - | int led = 0; | + | int led = 0; |
| - | int buzzer = 7; | + | int buzzer = 7; |
| - | char cmd; | + | char cmd; |
| void setup() { | void setup() { | ||
| - | |||
| Serial.begin(9600); | Serial.begin(9600); | ||
| hc05.begin(9600); | hc05.begin(9600); | ||
| - | |||
| pinMode(motorLeft1, OUTPUT); | pinMode(motorLeft1, OUTPUT); | ||
| pinMode(motorLeft2, OUTPUT); | pinMode(motorLeft2, OUTPUT); | ||
| pinMode(motorRight1, OUTPUT); | pinMode(motorRight1, OUTPUT); | ||
| pinMode(motorRight2, OUTPUT); | pinMode(motorRight2, OUTPUT); | ||
| - | |||
| pinMode(trigPin, OUTPUT); | pinMode(trigPin, OUTPUT); | ||
| pinMode(echoPin, INPUT); | pinMode(echoPin, INPUT); | ||
| - | |||
| pinMode(10, OUTPUT); | pinMode(10, OUTPUT); | ||
| pinMode(11, OUTPUT); | pinMode(11, OUTPUT); | ||
| - | |||
| pinMode(light, OUTPUT); | pinMode(light, OUTPUT); | ||
| - | pinMode(buzzer, OUTPUT); | + | pinMode(buzzer, OUTPUT); |
| - | | + | |
| } | } | ||
| void loop() { | void loop() { | ||
| - | |||
| - | |||
| if (led == 0) { | if (led == 0) { | ||
| digitalWrite(light, HIGH); | digitalWrite(light, HIGH); | ||
| Line 81: | Line 78: | ||
| delay(1000); | delay(1000); | ||
| } | } | ||
| - | |||
| if(hc05.available() > 0){ | if(hc05.available() > 0){ | ||
| cmd = hc05.read(); | cmd = hc05.read(); | ||
| Line 89: | Line 85: | ||
| cmd = 'x'; | cmd = 'x'; | ||
| } | } | ||
| - | |||
| if(cmd == 'Y'){ | if(cmd == 'Y'){ | ||
| tone(buzzer, 1000); | tone(buzzer, 1000); | ||
| Line 95: | Line 90: | ||
| noTone(buzzer); | noTone(buzzer); | ||
| } | } | ||
| - | |||
| - | |||
| digitalWrite(trigPin, LOW); | digitalWrite(trigPin, LOW); | ||
| delayMicroseconds(2); | delayMicroseconds(2); | ||
| Line 110: | Line 103: | ||
| Serial.print("Distance: "); | Serial.print("Distance: "); | ||
| Serial.println(distance); | Serial.println(distance); | ||
| - | |||
| if (distance <= 20 ) { | if (distance <= 20 ) { | ||
| - | |||
| if (cmd == 'B') { | if (cmd == 'B') { | ||
| digitalWrite(motorLeft1, HIGH); | digitalWrite(motorLeft1, HIGH); | ||
| - | digitalWrite(motorLeft2, LOW); | + | digitalWrite(motorLeft2, LOW); |
| - | + | ||
| digitalWrite(motorRight1, LOW); | digitalWrite(motorRight1, LOW); | ||
| - | digitalWrite(motorRight2, HIGH); | + | digitalWrite(motorRight2, HIGH); |
| - | | + | |
| analogWrite(10, 200); //ENA pin | analogWrite(10, 200); //ENA pin | ||
| - | analogWrite(11, 200); //ENB pin | + | analogWrite(11, 200); //ENB pin |
| - | | + | |
| } | } | ||
| - | |||
| if (cmd == 'S') { | if (cmd == 'S') { | ||
| - | |||
| digitalWrite(motorLeft1, LOW); | digitalWrite(motorLeft1, LOW); | ||
| - | digitalWrite(motorLeft2, LOW); | + | digitalWrite(motorLeft2, LOW); |
| - | + | ||
| digitalWrite(motorRight1, LOW); | digitalWrite(motorRight1, LOW); | ||
| - | digitalWrite(motorRight2, LOW); | + | digitalWrite(motorRight2, LOW); |
| - | | + | |
| analogWrite(10, 0); //ENA pin | analogWrite(10, 0); //ENA pin | ||
| analogWrite(11, 0); //ENB pin | analogWrite(11, 0); //ENB pin | ||
| - | |||
| } | } | ||
| } | } | ||
| else{ | else{ | ||
| if (cmd == 'F') { | if (cmd == 'F') { | ||
| - | |||
| - | |||
| digitalWrite(motorLeft1, LOW); | digitalWrite(motorLeft1, LOW); | ||
| - | digitalWrite(motorLeft2, HIGH); | + | digitalWrite(motorLeft2, HIGH); |
| - | + | ||
| digitalWrite(motorRight1, HIGH); | digitalWrite(motorRight1, HIGH); | ||
| - | digitalWrite(motorRight2, LOW); | + | digitalWrite(motorRight2, LOW); |
| - | + | ||
| analogWrite(10, 200); //ENA pin | analogWrite(10, 200); //ENA pin | ||
| analogWrite(11, 200); //ENB pin | analogWrite(11, 200); //ENB pin | ||
| - | |||
| } | } | ||
| - | |||
| if (cmd == 'B') { | if (cmd == 'B') { | ||
| - | |||
| digitalWrite(motorLeft1, HIGH); | digitalWrite(motorLeft1, HIGH); | ||
| - | digitalWrite(motorLeft2, LOW); | + | digitalWrite(motorLeft2, LOW); |
| - | + | ||
| digitalWrite(motorRight1, LOW); | digitalWrite(motorRight1, LOW); | ||
| - | digitalWrite(motorRight2, HIGH); | + | digitalWrite(motorRight2, HIGH); |
| - | + | ||
| analogWrite(10, 200); //ENA pin | analogWrite(10, 200); //ENA pin | ||
| analogWrite(11, 200); //ENB pin | analogWrite(11, 200); //ENB pin | ||
| - | |||
| } | } | ||
| if (cmd == 'L') { | if (cmd == 'L') { | ||
| - | |||
| digitalWrite(motorLeft1, LOW); | digitalWrite(motorLeft1, LOW); | ||
| - | digitalWrite(motorLeft2, HIGH); | + | digitalWrite(motorLeft2, HIGH); |
| - | | + | |
| digitalWrite(motorRight1, LOW); | digitalWrite(motorRight1, LOW); | ||
| digitalWrite(motorRight2, LOW); | digitalWrite(motorRight2, LOW); | ||
| - | |||
| analogWrite(10, 200); //ENA pin | analogWrite(10, 200); //ENA pin | ||
| analogWrite(11, 200); //ENB pin | analogWrite(11, 200); //ENB pin | ||
| Line 181: | Line 151: | ||
| digitalWrite(motorLeft1, LOW); | digitalWrite(motorLeft1, LOW); | ||
| digitalWrite(motorLeft2, LOW); | digitalWrite(motorLeft2, LOW); | ||
| - | | ||
| digitalWrite(motorRight1, HIGH); | digitalWrite(motorRight1, HIGH); | ||
| digitalWrite(motorRight2, LOW); | digitalWrite(motorRight2, LOW); | ||
| - | |||
| analogWrite(10, 200); //ENA pin | analogWrite(10, 200); //ENA pin | ||
| analogWrite(11, 200); //ENB pin | analogWrite(11, 200); //ENB pin | ||
| - | |||
| } | } | ||
| if (cmd == 'S') { | if (cmd == 'S') { | ||
| - | |||
| digitalWrite(motorLeft1, LOW); | digitalWrite(motorLeft1, LOW); | ||
| digitalWrite(motorLeft2, LOW); | digitalWrite(motorLeft2, LOW); | ||
| - | | ||
| digitalWrite(motorRight1, LOW); | digitalWrite(motorRight1, LOW); | ||
| digitalWrite(motorRight2, LOW); | digitalWrite(motorRight2, LOW); | ||
| - | |||
| analogWrite(10, 0); //ENA pin | analogWrite(10, 0); //ENA pin | ||
| analogWrite(11, 0); //ENB pin | analogWrite(11, 0); //ENB pin | ||
| - | |||
| } | } | ||
| } | } | ||
| } | } | ||
| - | |||