Differences

This shows you the differences between two versions of the page.

Link to this comparison view

pm:prj2021:avaduva:bluetoothwheelchair [2021/06/02 10:16]
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 ====
 +https://​www.youtube.com/​watch?​v=5PakJnpXK68&​ab_channel=AndreiDiaconu
 +==== COD ====
 + #​include <​SoftwareSerial.h>​
 + ​SoftwareSerial hc05(0, 1);
  
 + int motorLeft1 = 2;
 + int motorLeft2 = 3;
 + int motorRight1 = 4;
 + int motorRight2 = 5;
 +
 + int trigPin = 9;       // Trig Pin
 + int echoPin = 8;       // Echo Pin
 + int distance;
 + long duration;
 + int light = 6;
 + int led = 0;
 + int buzzer = 7;
 + char cmd;
 +
 +void setup() {
 +  Serial.begin(9600);​
 +  hc05.begin(9600);​
 +  pinMode(motorLeft1,​ OUTPUT);
 +  pinMode(motorLeft2,​ OUTPUT);
 +  pinMode(motorRight1,​ OUTPUT);
 +  pinMode(motorRight2,​ OUTPUT);
 +  pinMode(trigPin,​ OUTPUT);
 +  pinMode(echoPin,​ INPUT);
 +  pinMode(10, OUTPUT); ​
 +  pinMode(11, OUTPUT);
 +  pinMode(light,​ OUTPUT);
 +  pinMode(buzzer,​ OUTPUT); ​
 +}
 +
 +void loop() {
 +  if (led == 0) {
 +    digitalWrite(light,​ HIGH);
 +    led = 1;
 +    delay(1000);​
 +  }
 +  else if (led == 1) {
 +    digitalWrite(light,​ LOW);
 +    led = 0;
 +    delay(1000);​
 +  }
 +  if(hc05.available() > 0){
 +    cmd = hc05.read();​
 +    Serial.write(Serial.read());​
 +  }
 +  else {
 +    cmd = '​x';​
 +  }
 +    if(cmd == '​Y'​){
 +        tone(buzzer,​ 1000);
 +        delay(1000);​
 +        noTone(buzzer);​
 +   }
 +  digitalWrite(trigPin,​ LOW);
 +  delayMicroseconds(2);​
 +  // Sets the trigPin on HIGH state for 10 micro seconds
 +  digitalWrite(trigPin,​ HIGH);
 +  delayMicroseconds(10);​
 +  digitalWrite(trigPin,​ LOW);
 +  // Reads the echoPin, returns the sound wave travel time in microseconds
 +  duration = pulseIn(echoPin,​ HIGH);
 +  // Calculating the distance
 +  distance = duration * 0.034 / 2;
 +  // Prints the distance on the Serial Monitor
 +  Serial.print("​Distance:​ ");
 +  Serial.println(distance);​
 +  if (distance <= 20 ) {
 +      if (cmd == '​B'​) {
 +        digitalWrite(motorLeft1,​ HIGH);
 +        digitalWrite(motorLeft2,​ LOW);      ​
 +        digitalWrite(motorRight1,​ LOW);
 +        digitalWrite(motorRight2,​ HIGH); ​      
 +        analogWrite(10,​ 200); //ENA pin
 +        analogWrite(11,​ 200); //ENB pin  ​
 +      }
 +        if (cmd == '​S'​) {
 +          digitalWrite(motorLeft1,​ LOW);
 +          digitalWrite(motorLeft2,​ LOW);        ​
 +          digitalWrite(motorRight1,​ LOW);
 +          digitalWrite(motorRight2,​ LOW);     
 +          analogWrite(10,​ 0); //ENA pin
 +          analogWrite(11,​ 0); //ENB pin
 +    }
 +  }
 +  else{
 +  if (cmd == '​F'​) {
 +    digitalWrite(motorLeft1,​ LOW);
 +    digitalWrite(motorLeft2,​ HIGH);  ​
 +    digitalWrite(motorRight1,​ HIGH);
 +    digitalWrite(motorRight2,​ LOW);    ​
 +    analogWrite(10,​ 200); //ENA pin
 +    analogWrite(11,​ 200); //ENB pin
 +  }
 +  if (cmd == '​B'​) {
 +    digitalWrite(motorLeft1,​ HIGH);
 +    digitalWrite(motorLeft2,​ LOW);  ​
 +    digitalWrite(motorRight1,​ LOW);
 +    digitalWrite(motorRight2,​ HIGH); ​   ​
 +    analogWrite(10,​ 200); //ENA pin
 +    analogWrite(11,​ 200); //ENB pin
 +  }
 +
 +  if (cmd == '​L'​) {
 +    digitalWrite(motorLeft1,​ LOW);
 +    digitalWrite(motorLeft2,​ HIGH); ​
 +    digitalWrite(motorRight1,​ LOW);
 +    digitalWrite(motorRight2,​ LOW);
 +    analogWrite(10,​ 200); //ENA pin
 +    analogWrite(11,​ 200); //ENB pin
 +  }
 +  if (cmd == '​R'​) {
 +
 +    digitalWrite(motorLeft1,​ LOW);
 +    digitalWrite(motorLeft2,​ LOW);
 +    digitalWrite(motorRight1,​ HIGH);
 +    digitalWrite(motorRight2,​ LOW);
 +    analogWrite(10,​ 200); //ENA pin
 +    analogWrite(11,​ 200); //ENB pin
 +  }
 +
 +  if (cmd == '​S'​) {
 +    digitalWrite(motorLeft1,​ LOW);
 +    digitalWrite(motorLeft2,​ LOW);
 +    digitalWrite(motorRight1,​ LOW);
 +    digitalWrite(motorRight2,​ LOW);
 +    analogWrite(10,​ 0); //ENA pin
 +    analogWrite(11,​ 0); //ENB pin
 +  }
 +  }
 +}
  
  
pm/prj2021/avaduva/bluetoothwheelchair.1622618174.txt.gz · Last modified: 2021/06/02 10:16 by andrei.diaconu2311
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0