The HC-SR04 Ultrasonic Ranging Sensor is a non contact distance measuring module device commonly use in Robotic Obstacle Avoidance. The HC SR04 has a high ranging accuracy. The measurement range can go up to 5 meter, which would be helpful for your project.
Characteristics
- Power supply: 5v DC
- Effectual angle: < 15°
- Ranging distance: 2cm-500 cm
- Resolution: 1 cm
- Ultrasonic Frequency: 40k Hz
A short pulse is transmitter at the time of zero, reflected by an object back to the trigger. The sensor receives the signal and converts it to an electrical signal. The next pulse can be transmitted when the echo is fade. This period of time is called cycle period. Recommended period of cycle should < 50ms if a ten μs pulse is sent to the signal pi. The Ultrasonic Ranging Sensor module will output 8-40kHz signal detect the echo back. Measuring distance is proportional to the echo pulse width and calculated by the formula. if no obstacle the detection output pin will give a 38ms high level signal.
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 28 29 30 31 32 |
/* .:osyhyyso+/. .odmy+-` `-+y+` `:+ooooooooo` .:+oossooo/-` .ssssssssssso: :///////////- `smm+` `/ho` +mmmyssssssso /dmmdysssshmmmd`ymmmssssssymmmd` `////////////` -dmy` .yh. +mmh` -mmm/ ymmd.mmms ommm- ------------` `dmy /yyyyy/ :syyyyys:hh` `mmm/ smmh .mmm/ommm/.....-+mmms -ooooooooooo+ omm. /ymmmd` /hmmmmmmmo oh+ .mmmo........``dmmh:.....:hmmd.mmmmmmmmmmmmdo- ```````````` hmh .mmmm/+mmmmdhmmmm+.oho /dmmmmmmmmmm. :ymmmmmmmmmdy+`ommm/````:dmmh- /sssssssssss+ smd` hmmmsshhhhhdmmmmhh.yho ` `......... ``.... .-..`` ```.-.. `` `` ```` -mmo`/:::` -:::: +hh. :ssyo:-ssyo:-ssyo: /o .oh s+: s/o+ d:`hoy /o:`+++o y/d+h. /mm+ `ohh: +//o o//o +//o -. `+ -:s./+/`//o- o +/: :`-+/`:++: o`s.o- -dmh. `/hhy- -`:.. .``` ```` .```` ` ``` ``--.` ` /hmh+-`````.-+shdy/ `oooos+sso/.o:oo+:/sss+s o/s+ss///:o/ ./shdmmddddyo/. `- ```` */ #include "Ultrasonic.h" \\ Inport the ultrasonic.h fuction from Arduino library Ultrasonic ultrasonic(12,13); void setup() { Serial.begin(9600); } void loop() { Serial.println(ultrasonic.Ranging(CM)); delay(100); } |