Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Daniel Wakayamba
Created November 29, 2023

AquaGuide

Assistive swimming technology for the blind

24
AquaGuide

Things used in this project

Hardware components

Blues Swan
Blues Swan
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
Used instead of Waterproof Ultrasonic Sensors
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Buzzer
Buzzer
Used instead of the waterproof bone conduction bluetooth headphones
×2
Breadboard (generic)
Breadboard (generic)
×1
SparkFun Breadboard Power Supply 5V/3.3V
SparkFun Breadboard Power Supply 5V/3.3V
I used a USB cable to supply power from my Laptop port
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

AquaGuide

Arduino
int trig = 13;
int echol = A1;
int echor = A3;
int dtime = 10;
float distr=5, distl=5;
int timeout=10;

int lBuzzer = 10, rBuzzer = 11;

void setup() {
  pinMode(trig, OUTPUT);
  pinMode(echol, INPUT);
  pinMode(echor, INPUT);
  pinMode(trig, OUTPUT);

  pinMode(lBuzzer, OUTPUT);
  pinMode(rBuzzer, OUTPUT);

  Serial.begin(115200);
}

void loop(){ 
  delay(1000);
  pulse();
  float deviation[2];
  deviation[0] = get_deviation(0);
  deviation[1] = get_deviation(1);


  if(deviation[1] < 10){
    digitalWrite(lBuzzer, HIGH);
    digitalWrite(rBuzzer, HIGH);
  }else{
    digitalWrite(lBuzzer, LOW);
    digitalWrite(rBuzzer, LOW);
  }

  if(deviation[1] < 0 && abs(deviation[0]) > 5){
    digitalWrite(lBuzzer, HIGH);
    digitalWrite(rBuzzer, LOW);
  }else if(deviation[1] > 0 && abs(deviation[0]) > 5){
    digitalWrite(rBuzzer, HIGH);
    digitalWrite(lBuzzer, LOW);
  }

Serial.print("distl: "); Serial.print(distl);
Serial.print("\tdistr: "); Serial.println(distr);
Serial.print("deviation_degrees:"); Serial.print(deviation[1]);
Serial.print("\tdistance: "); Serial.println(deviation[0]);

 
}

void pulse(){
  timeout = 100000;  
  digitalWrite(trig, LOW);
  delay(dtime);
  digitalWrite(trig, HIGH);
  delay(dtime);
  digitalWrite(trig, LOW);
  distl = (pulseIn(echol, HIGH, timeout))*15/900.0;

  digitalWrite(trig, HIGH);
  delay(dtime);
  digitalWrite(trig, LOW);
  // convert echo time to centimetres
  distr = (pulseIn(echor, HIGH, timeout))*15/900.0;

}

float get_deviation(int i){
  float sep_distance = 8.5;
  float half_per = (sep_distance+distl+distr)*0.5;
  float area = sqrt(half_per*(half_per-distl)(half_per-distr)(half_per-sep_distance));//8.5 is the separation distance btwn the HC-SRO4s
  float theta_p = asin(area/(distl*sep_distance/2.0));
  float midline = sqrt(pow(distl,2)+pow((sep_distance/2.0),2)-distl*sep_distance*cos(theta_p));
  // convert radians to degrees
  float theta = 90-((asin((distl*sin(theta_p))/midline)))*180*7/22.0;


  if (i == 1){
    if (distl<distr){
      return -theta;
    }
    else{
      return theta;
    }
  }
  if (i == 0){
    return midline;
  }
}

Credits

Daniel Wakayamba
1 project • 1 follower
Thanks to Trevor Muhavi Mwanzi.

Comments