Arduino Library For Ultrasonic Ranging Module HC-SR04 - ITead Studio

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

13/10/12

Arduino Library For Ultrasonic Ranging Module HC-SR04 | ITead Studio

ITead Studio
Make innovation easier Feed Rss Blog Archive iStore iMall Distributors iForum About us

April 24th, 2010

Arduino Library For Ultrasonic Ranging Module HC-SR04


Application Note, by ITead.

We have already sold many HC-SR04 modules , though its easy use and we has published a demo ,still some user mail us for a specialized code of his own use even just change the different Arduino pins for module. So we decide to release a Arduino Library for those beginning user . You just need to add the library into your Arduino , and call for a function , you can get the distance. Download the Library , unzip the release package to arduino-0018/libraries/ folder. Open the Arduino IDE , you can include the library by Sketch-Import library-Ultrasonic . And you can find the example sketch in File-Examples-Ultrasonic-UltrasonicDemo . Here we give out a brief introduction of this ultrasonic ranging library. It includes 3 function for user : 1. Ultrasonic(int TP, int EP) This is a initial function for ultrasonic ranging module, choose the pins for module Trig and Echo pin. example: Ultrasonic(13,12); then you define the digital pin 13 of Arduino for the Trig pin of HC-SR04. And the pin 12 for Echo pin. 2. long Timing() Trigger the ultrasonic ranging module work and return the duration that Echo pin keep high level. example: long time; Ultrasonic hcsr; time = hcsr.Timing(); Then you start the HC-SR04 for ranging and you get the time the Echo pin keep high, you can change the time corresponds to the distance : Distance = ((Duration of high level)*(Sonic :340m/s))/2 3. long Ranging(int sys) (sys : CM / INC) If you dont want to change the time into distance yourself , this function will help you get the distance immediate. And the function has a parameter sys, you can use CM or ICN , than you get the distance show as centimeter or inch. This function will call the Timing() and you dont need to use the Timing() before it. example: long distance; Ultrasonic hcsr; distance = hcsr.Ranging(CM); OK, now you get the distance in centimeter . Its very easy , right ? Download the library for HC-SR04 ultrasonic ranging module here : Ultrasonic ranging library (1.4 KiB, 11,233 hits) Adicionar ao Reddit
iteadstudio.com/application-note/arduino-library-for-ultrasonic-ranging-module-hc-sr04/ 1/4

13/10/12

Arduino Library For Ultrasonic Ranging Module HC-SR04 | ITead Studio

You may also be interested in these posts: 1. 2. 3. 4. 5. Cheap-cheap Ultrasonic Ranging Module:HC-SR04 Arduino Ultrasonic Ranging With HC-SR04 Serial Ultrasonic Module JSME007TX ITDB02 Arduino Library V1.3 ITDB02 TFT LCD Library For Arduino

Tags: Arduino, Library, ranging Back Top 2.4G Wireless Module : nRF24L01 Module Breakout board for SMD ICs

Responses to Arduino Library For Ultrasonic Ranging Module HC-SR04


Comments (7) Trackbacks (10) Leave a comment Trackback 1. I was womdering if you had that library for the HC-SR04 in a different archive format (ex..zip) or in a text format. I purchased a unit and would really love to move forward with this model and if useful possibly purchase more. Thank You Sincerely, Shawn McNown at May 28, 2011 5:20 AM Reply 2. I get a message that the RAR is damaged. Greg M. Johnson at June 5, 2011 2:11 AM Reply 3. This is great and thank you a lot for sharing. Ultrasonic sensors are very useful but take a lot or lines, and this sensor is one of the cheapiest. Your library will be very useful. Personally i am trying to use it with a hacked robo sapien:-) Best regards and thanks from France ! @hugobiwan @hugobiwan at June 20, 2011 5:57 AM Reply 4. The new Arduino 1.0 does not compile the Ultrasonic library because ultrasonic.h has #include WProgram.h and the WProgram.h is removed from version 1.0 - see the forum http://arduino.cc/forum/index.php/topic,81078.msg613177.html#msg613177 T Greenbaum at December 12, 2011 12:25 PM Reply 5. Greenbaum, change the WProgram.h reference to Arduino.h and everything should run fine. Luiz Gustavo at December 31, 2011 8:51 PM Reply 6. Its INC for inches, not ICN as shown above. James at May 9, 2012 2:54 AM Reply 7. here is update link for library codes http://ultrasonic-ranging-module-hc-sr04-updates.googlecode.com/files/Ultrasonic.rar
iteadstudio.com/application-note/arduino-library-for-ultrasonic-ranging-module-hc-sr04/ 2/4

13/10/12

Arduino Library For Ultrasonic Ranging Module HC-SR04 | ITead Studio

raz at May 27, 2012 11:09 AM Reply 1. Sensore di distanza ad ultrasuoni con Arduino Giuseppe Fatiguso's Blog (,June 7, 2011) [...] Quello che rende semplice questo sketch di esempio, che esiste una libreria software per questo sensore per arduino, scaricabile a questa pagina. [...] 2. La domotique chez Benchi - Arduino et la mesure de distance par ultrason hc-sr04 (,August 14, 2011) [...] http://iteadstudio.com/application-note/arduino-library-for-ultrasonic-ranging-module-hc-sr04/ Partager: [...] 3. Eletrnica digital com Arduino: sensor ultrasnico + servo motor = olhos | Djames Suhanko Linux e Programao (,August 19, 2011) [...] bastante popular em Arduino tanto que possui at uma biblioteca, que pode ser baixada nesse link. Baixe o arquivo e extraia-o em arduino-0022/libraries/. Ser criado um diretrio chamado [...] 4. Domotique - Connaitre le niveau d'une cuve de rcupration d'eau | Blog de C-quad (,August 23, 2011) [...] cout est plutt faible 10$ et un librairie pour Arduino est [...] 5. HC-SR04 Um sensor de Ultra Som barato Kemper.com.br Robtica com Carter Social (,August 31, 2011) [...] O site contendo a documentao original em ingls pode ser encontrado neste link. [...] 6. Arduino Arts Archive Tutorials with Arduino: Range Sensor with LCD and 7 segment led #display #arduino (,September 10, 2011) [...] You can download the library here. [...] 7. Tutorials with Arduino: Range Sensor with LCD and 7 segment led #display #arduino / Cooking Hacks Blog (,September 11, 2011) [...] You can download the library here. [...] 8. My First Arduino Robot Bobs Mods (,December 5, 2011) [...] This was very helpful for setting up my ultrasonic sensors, also this. [...] 9. Finding distance/range using arduino Mambohead (,December 27, 2011) [...] went and got the library here. #include Ultrasonic.h Ultrasonic ultrasonic( 12, 13 [...] 10. Counting Human Activity with an Arduino, Part 1 DBP Harrison (,July 10, 2012) [...] 3 and works a little differently, with a pin for triggering and another for receiving an echo. An Arduino library is available so there is no reason to shy away from using them, especially when they can be [...]

Leave a Reply
Name(required) Mail (will not be published)(required)
iteadstudio.com/application-note/arduino-library-for-ultrasonic-ranging-module-hc-sr04/ 3/4

13/10/12

Arduino Library For Ultrasonic Ranging Module HC-SR04 | ITead Studio

Website

Submit Comments

Back Top 2006-2010 ITead Studio


SEO Powered by Platinum SEO from Techblissonline

iteadstudio.com/application-note/arduino-library-for-ultrasonic-ranging-module-hc-sr04/

4/4

You might also like