Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
43foldz
Published © GPL3+

Glasses That Detect Obstacles

Glasses that will beep or buzz when they detect an obstacle

BeginnerFull instructions provided631
Glasses That Detect Obstacles

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Buzzer, Piezo
Buzzer, Piezo
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor

Hand tools and fabrication machines

Tape, Electrical
Tape, Electrical

Story

Read more

Schematics

schematics

connect the wires to the corresponding pin

Code

code

C/C++
copy this code to your arduino
int distanceThreshold = 0;

int cm = 0;

int inches = 0;

long readUltrasonicDistance(int triggerPin, int echoPin)
{
  pinMode(triggerPin, OUTPUT);  // Clear the trigger
  digitalWrite(triggerPin, LOW);
  delayMicroseconds(2);
  // Sets the trigger pin to HIGH state for 10 microseconds
  digitalWrite(triggerPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(triggerPin, LOW);
  pinMode(echoPin, INPUT);
  // Reads the echo pin, and returns the sound wave travel time in microseconds
  return pulseIn(echoPin, HIGH);
}

void setup()
{
  Serial.begin(9600);

  pinMode(5, OUTPUT);
}

void loop()
{
  
  // measure the ping time in cm
  cm = 0.01723 * readUltrasonicDistance(7, 6);

  if (cm > 50) {
    digitalWrite(5, LOW);
  }
  if (cm < 50) {
    digitalWrite(5, HIGH);
  }
  delay(10); // Delay a little bit to improve simulation performance
}

code

C/C++
copy this code onto your arduino
int distanceThreshold = 0;

int cm = 0;

int inches = 0;

long readUltrasonicDistance(int triggerPin, int echoPin)
{
  pinMode(triggerPin, OUTPUT);  // Clear the trigger
  digitalWrite(triggerPin, LOW);
  delayMicroseconds(2);
  // Sets the trigger pin to HIGH state for 10 microseconds
  digitalWrite(triggerPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(triggerPin, LOW);
  pinMode(echoPin, INPUT);
  // Reads the echo pin, and returns the sound wave travel time in microseconds
  return pulseIn(echoPin, HIGH);
}

void setup()
{
  Serial.begin(9600);

  pinMode(5, OUTPUT);
}

void loop()
{
  
  // measure the ping time in cm
  cm = 0.01723 * readUltrasonicDistance(7, 6);

  if (cm > 50) {
    digitalWrite(5, LOW);
  }
  if (cm < 50) {
    digitalWrite(5, HIGH);
  }
  delay(10); // Delay a little bit to improve simulation performance
}

Credits

43foldz
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.