ngarzon005
Published © MIT

DistCap

A smart Cap that detects if you are near a person on less than 1.5 meters and if so it alerts you by a blinking a led and making a sound.

BeginnerShowcase (no instructions)2,472
DistCap

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
LED (generic)
LED (generic)
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Buzzer
Buzzer
×1
9V Battery Clip
9V Battery Clip
×1
9V battery (generic)
9V battery (generic)
×1

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver
Soldering Iron Tip, Screwdriver
Soldering Iron Tip, Screwdriver

Story

Read more

Schematics

Fritzing DistCap

Is an schematic about the connections of the DistCap.

Code

DistCap Code

C/C++
#define trigPin 2 // Set trig as pin 2
#define echoPin 3 // Set echo as pin 3

#define LED 4 // Set LED as pin 4

#define buzzer 5 // Set buzzer as pin 5

void setup()

{
  
Serial.begin (9600); //Serial Port begin

pinMode(trigPin, OUTPUT); // Set trigpin - pin 2 as an output

pinMode(echoPin, INPUT); // Set echopin - pin 3 as an output

pinMode (LED, OUTPUT); // Set LED - pin 4 as an output

pinMode(buzzer, OUTPUT); // Set buzzer - pin 5 as an output
}


void loop()

{

// Variable for defining duration and distance
int duration, distance; 

// The sensor is trigered by a HIGH pulse during 500 microseconds

digitalWrite(trigPin, HIGH); 

delayMicroseconds(500); 

digitalWrite(trigPin, LOW); 


// Convert the time into a distance

duration = pulseIn(echoPin, HIGH); 

distance = (duration/2) / 29.1; 

if (distance < 150) // If the distance is less than 1.5 meters the code down will execute

{

digitalWrite(LED, HIGH); // Turn on LED
tone(buzzer, 1000); // Start buzzer sound

}

else

{
  digitalWrite(LED, LOW); // Turn off LED
  noTone(buzzer);     // Stop buzzer sound
}
}

Credits

ngarzon005

ngarzon005

0 projects • 0 followers

Comments