Sie sind auf Seite 1von 5

Arduino Ultrasonic Proximity Sensor

6/29/15, 11:13 AM

Labs
free energy
Q&A
quizzes
Comments
Contact
Register
Login
Arduino
555
Alarms
Audio
DIY
Hobby
Lights
Power supply
Radio
Solar
Tested
Tools
Tutorials
Various
Search

Arduino Ultrasonic Proximity Sensor


This circuit was tested and worked properly!
Posted by T.K. Hareendran in Arduino, Tested with 2 comments
Tagged with: proximity sensors
Share

377

Tweet

This is an Arduino-based Proximity Sensor circuit wired using the popular HC-SR04 Ultrasonic ranging
module,used here for non-contact object detection purpose. The HC-SR04 module includes ultrasonic
transmitters, receiver and control circuit. You only need to supply a short pulse to the trigger input to start the
ranging, and then the module will send out burst of ultrasound at 40 kHz and raise its echo.
The set-up process is very simple, and best understood by referring the wiring diagram. If everything goes
http://www.electroschematics.com/10448/arduino-ultrasonic-proximity-sensor/

Page 1 of 5

Arduino Ultrasonic Proximity Sensor

6/29/15, 11:13 AM

right,you should see the burning eye of the red LED when there is no object in the safe-zone (within 5 cm
from the HC-SR04 module), and an ear-splitting beep from the piezo-buzzer otherwise.

Arduino Ultrasonic Sensor Wiring Diagram

Arduino Sketch
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.

/*
Project: Ultrasonic Proximity Sensor
Sensor: HC-SR04
Courtesy Note: Inspired by the Arduino Ping Sketch
Tested At: TechNode Protolabz / June 2014
*/
//Pins for HC-SR04
const int trigPin = 13;
//Pin which delivers time to receive echo using pulseIn()
int echoPin = 12;
int safeZone = 5;
// Pins for Indicators
int statusLed = 11;
int pzBzr = 10;
void setup() {
}
void loop()
{
//raw duration in milliseconds, cm is the
//converted amount into a distance
long duration, cm;
//initializing the pin states
pinMode(trigPin, OUTPUT);
pinMode(statusLed, OUTPUT);
pinMode(pzBzr, OUTPUT);
//sending the signal, starting with LOW for a clean signal
digitalWrite(trigPin, LOW);

http://www.electroschematics.com/10448/arduino-ultrasonic-proximity-sensor/

Page 2 of 5

Arduino Ultrasonic Proximity Sensor

28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.

6/29/15, 11:13 AM

delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
//setting up the input pin, and receiving the duration in uS
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
// convert the time into a distance
cm = microsecondsToCentimeters(duration);
//Checking if anything is within the safezone
// If not, keep status LED on
// Incase of a safezone violation, activate the piezo-buzzer
if (cm > safeZone)
{
digitalWrite(statusLed, HIGH);
digitalWrite(pzBzr, LOW);
}
else
{
digitalWrite(pzBzr, HIGH);
digitalWrite(statusLed, LOW);
}
delay(100);
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter
// The ping travels forth and back
// So to calculate the distance of the object we take half of the travel
return microseconds / 29 / 2;
}

Search
Share

377

Arduino Security
Alarm with Reed
Switch

Tweet

Arduino Self
Timer

Arduino Water
Level Indicator +
Controller

http://www.electroschematics.com/10448/arduino-ultrasonic-proximity-sensor/

Arduino
Christmas LED
Lights Bar
Page 3 of 5

Arduino Ultrasonic Proximity Sensor

6/29/15, 11:13 AM

2 Responses to "Arduino Ultrasonic Proximity Sensor"


1.

Eldho varghese says: on September 20, 2014 at 12:28 pm


reply
helloo,
thats a good project i think. can we increse the distance other than 5cm?? will that sensor sense more
than 5metre?? reply me sir. i need the information..

2.

Jim says: on September 23, 2014 at 8:10 pm


reply
Halloween is approaching.
I would love to see this expanded to include two sensors to run a servo with follow me eyes.
Kind of like what is discussed here.
http://www.instructables.com/id/Halloween-Props-That-Turn-to-Look-at-You-as-you-Wa/?ALLSTEPS

What do you think about this article? Leave a comment!


Name (required)
Mail (will not be published) (required)

You may add a picture too (related to electronics)

Choose File

no file selected

Submit Comment

Check this checkbox to get notifications of followup comments via e-mail. You can also subscribe
without commenting.
electroschematics partners
http://www.electroschematics.com/10448/arduino-ultrasonic-proximity-sensor/

Page 4 of 5

Arduino Ultrasonic Proximity Sensor

6/29/15, 11:13 AM

Login
Username

Password

Remember Me
Log In

Join all of us on our group

Recent Questions
I have an in-car camera that requires an electret exterior microphone.
Circuit Diagram to Drive 50 SMD LED in Parallel using 12V DC
220v DC to 220v AC Transformerless invertor circuit diagram needed....
recently added electronic circuits
IEEE 1394 Single And Dual Port FireWire Protective Circuits
Fox Deterrent Beacon Light
Light to Arduino Experiment
Rotary Encoder & Arduino
Optical Mouse Learn To Hack
Links - Policy - Disclaimer - Copyright 2008 - 2015

http://www.electroschematics.com/10448/arduino-ultrasonic-proximity-sensor/

Page 5 of 5

Das könnte Ihnen auch gefallen