HC-SR04 Ultrasonic Sensor Distance Measuring Module: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
(17 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
[[Image:DSC00731-Small.jpg|300px|thumb|right|HC-SR04 array with NewPing library]] |
|||
[[Image:HC-SR04+Nano.jpg|300px|thumb|right|HC-SR04 Ultrasonic Sensor on Arduino Nano breadboard]] |
|||
[http://www.dealextreme.com/p/133696 HC-SR04 Ultrasonic Sensor Distance Measuring Module] |
[http://www.dealextreme.com/p/133696 HC-SR04 Ultrasonic Sensor Distance Measuring Module] |
||
<pre> |
|||
* Model: HC-SR04 |
|||
* Working voltage : 5V(DC) |
|||
- Color: Blue + Silver |
|||
* Static current: Less than 2mA. |
|||
- Working voltage : 5V(DC) |
|||
* Output signal: Electric frequency signal, high level 5V, low level 0V. |
|||
- Static current: Less than 2mA. |
|||
* Sensor angle: Not more than 15 degrees. |
|||
- Output signal: Electric frequency signal, high level 5V, low level 0V. |
|||
* Detection distance: 2cm~450cm. |
|||
- Sensor angle: Not more than 15 degrees. |
|||
* High precision: Up to 3mm |
|||
- Detection distance: 2cm~450cm. |
|||
* Mode of connection: VCC / trig(T) / echo(R) / GND |
|||
- High precision: Up to 3mm |
|||
* Module Working Principle: |
|||
- Mode of connection: VCC / trig(T) / echo(R) / GND |
|||
** Adopt IO trigger through supplying at least 10us sequence of high level signal |
|||
- Module Working Principle: |
|||
** The module automatically send eight 40khz square wave and automatically detect whether receive the returning pulse signal |
|||
- Adopt IO trigger through supplying at least 10us sequence of high level signal |
|||
** If there is signals returning, through outputting high level and the time of high level continuing is the time of that from the ultrasonic transmitting to receiving |
|||
- The module automatically send eight 40khz square wave and automatically detect whether receive the returning pulse signal |
|||
- If there is signals returning, through outputting high level and the time of high level continuing is the time of that from the ultrasonic transmitting to receiving |
|||
</pre> |
|||
A lire |
A lire |
||
* http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1272177425 |
* http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1272177425 |
||
* http://iteadstudio.com/application-note/arduino-library-for-ultrasonic-ranging-module-hc-sr04/ |
* http://iteadstudio.com/application-note/arduino-library-for-ultrasonic-ranging-module-hc-sr04/ |
||
Supports imprimés 3D |
|||
* http://www.thingiverse.com/search?q=ultrasonic&sa= |
|||
* http://www.thingiverse.com/thing:35398 |
|||
* http://www.thingiverse.com/thing:45831 |
|||
* http://www.thingiverse.com/thing:102800 |
|||
==Projets== |
|||
* [[Fusion multi-capteurs pour table tactile]] 2013 |
|||
* [[RobAIR 2013 Configuration 2]] |
|||
==Arduino== |
==Arduino== |
||
* [http://code.google.com/p/arduino-new-ping/ Library New Ping] for HC-SR04 Ultrasonic Sensor. |
|||
[[Image:Arduino+HCSR04.jpg|thumb|200px|right|HCSR-04 with Arduino Nano]] |
|||
** [http://code.google.com/p/arduino-new-ping/downloads/list Download Library] |
|||
** [http://code.google.com/p/arduino-new-ping/wiki/15_Sensors_Example Example] with multiple ultrasonic sensors. |
|||
===Simple Example=== |
|||
[http://code.google.com/p/arduino-new-ping/wiki/Simple_NewPing_Example Simple Example] with '''schematic'''. |
|||
<pre> |
<pre> |
||
// load the library for HC-SR04 http://iteadstudio.com/application-note/arduino-library-for-ultrasonic-ranging-module-hc-sr04/ |
// load the library for HC-SR04 http://iteadstudio.com/application-note/arduino-library-for-ultrasonic-ranging-module-hc-sr04/ |
||
Line 54: | Line 73: | ||
} |
} |
||
</pre> |
</pre> |
||
===With 3 Ultrasonic + Servo=== |
|||
[[Image:UltrasonicScanner1.jpg|200px|thumb|right|Three HC-SR04 Ultrasonic Sensors]] |
|||
[[Image:UltrasonicScanner2.jpg|200px|thumb|right|Three HC-SR04 Ultrasonic Sensors]] |
|||
[[Image:UltrasonicScanner.jpg|200px|thumb|right|Three HC-SR04 Ultrasonic Sensors on a tilt bracket]] |
|||
<pre> |
|||
/* |
|||
* UltraSonic Scanner |
|||
* |
|||
* output values from a ultrasonic sensors array in a NMEA 0183 sentence (ie formatted message) |
|||
* |
|||
* $USDIS,LEFT_DISTANCE_IN_CM,CENTER_DISTANCE_IN_CM,RIGHT_DISTANCE_IN_CM,SERVOPOS*CHECKSUM[CR][LF] |
|||
* |
|||
* TODO Calcutate checksum (always 00) |
|||
*/ |
|||
#include "Ultrasonic.h" |
|||
#include <Servo.h> |
|||
Servo myservo; // create servo object to control a servo |
|||
// a maximum of eight servo objects can be created |
|||
Ultrasonic ultrasonicCenter(12,13); |
|||
Ultrasonic ultrasonicRight(10,11); |
|||
Ultrasonic ultrasonicLeft(6,7); |
|||
int servoPos = 90; // variable to store the servo position |
|||
int servoIncr = 10; // variable to store the servo increment |
|||
const int MINSERVOPOS=55; |
|||
const int MAXSERVOPOS=125; |
|||
void setup() { |
|||
Serial.begin(4800); |
|||
myservo.attach(3); // attaches the servo on pin 9 to the servo object |
|||
} |
|||
void loop() { |
|||
Serial.print("$USDIS,"); |
|||
Serial.print(ultrasonicLeft.Ranging(CM)); |
|||
Serial.print(","); |
|||
Serial.print(ultrasonicCenter.Ranging(CM)); |
|||
Serial.print(","); |
|||
Serial.print(ultrasonicRight.Ranging(CM)); |
|||
Serial.print(","); |
|||
Serial.print(servoPos); |
|||
Serial.print("*"); |
|||
Serial.print("00"); |
|||
Serial.print("\r\n"); |
|||
myservo.write(servoPos); // tell servo to go to position in variable 'pos' |
|||
servoPos=servoPos+servoIncr; |
|||
if(servoPos<MINSERVOPOS || servoPos>MAXSERVOPOS) servoIncr=-servoIncr; |
|||
delay(100); |
|||
} |
|||
byte calcChecksumBuf(byte checksum, byte buf[], int i, int len){ |
|||
for(;i<len; i++){ |
|||
checksum=calcChecksum(checksum,buf[i]); |
|||
} |
|||
return checksum; |
|||
} |
|||
byte calcChecksum(byte checksum, byte c){ |
|||
if ( c == '$' ) return 0; |
|||
if ( c != '\r' && c != '\n' && c != '*' ) { |
|||
checksum ^= c; |
|||
} |
|||
return checksum; |
|||
} |
|||
</pre> |
|||
==New Ping== |
|||
<pre> |
|||
From http://code.google.com/p/arduino-new-ping/wiki/15_Sensors_Example |
|||
... TODO ... |
|||
</pre> |
|||
==[[MSP430]]== |
|||
Voir le programme pour l'[[US-100 Ultrasonic Distance Sensor Module]] |
Latest revision as of 09:06, 28 April 2015
HC-SR04 Ultrasonic Sensor Distance Measuring Module
- Model: HC-SR04
- Working voltage : 5V(DC)
- Static current: Less than 2mA.
- Output signal: Electric frequency signal, high level 5V, low level 0V.
- Sensor angle: Not more than 15 degrees.
- Detection distance: 2cm~450cm.
- High precision: Up to 3mm
- Mode of connection: VCC / trig(T) / echo(R) / GND
- Module Working Principle:
- Adopt IO trigger through supplying at least 10us sequence of high level signal
- The module automatically send eight 40khz square wave and automatically detect whether receive the returning pulse signal
- If there is signals returning, through outputting high level and the time of high level continuing is the time of that from the ultrasonic transmitting to receiving
A lire
- http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1272177425
- http://iteadstudio.com/application-note/arduino-library-for-ultrasonic-ranging-module-hc-sr04/
Supports imprimés 3D
- http://www.thingiverse.com/search?q=ultrasonic&sa=
- http://www.thingiverse.com/thing:35398
- http://www.thingiverse.com/thing:45831
- http://www.thingiverse.com/thing:102800
Projets
Arduino
- Library New Ping for HC-SR04 Ultrasonic Sensor.
- Download Library
- Example with multiple ultrasonic sensors.
Simple Example
Simple Example with schematic.
// load the library for HC-SR04 http://iteadstudio.com/application-note/arduino-library-for-ultrasonic-ranging-module-hc-sr04/ // Remark: change the “WProgram.h” reference to “Arduino.h” in files "Ultrasonic.h" and "Ultrasonic.cpp" and everything will be fine #include "Ultrasonic.h" // Sensor VCC pin connected to Arduino pin 5V // Sensor GND pin connected to Arduino pin GND // Sensor TRIG pin connected to Arduino pin 12 // sensor ECHO pin connected to Arduino pin 13 Ultrasonic ultrasonic(12,13); void setup() { Serial.begin(9600); } void loop() { Serial.print(ultrasonic.Ranging(CM)); Serial.println(" cm"); delay(100); Serial.print(ultrasonic.Timing()); // Distance = ((Duration of high level)*(Sonic :340m/s))/2 Serial.println(" ms"); delay(100); }
With 3 Ultrasonic + Servo
/* * UltraSonic Scanner * * output values from a ultrasonic sensors array in a NMEA 0183 sentence (ie formatted message) * * $USDIS,LEFT_DISTANCE_IN_CM,CENTER_DISTANCE_IN_CM,RIGHT_DISTANCE_IN_CM,SERVOPOS*CHECKSUM[CR][LF] * * TODO Calcutate checksum (always 00) */ #include "Ultrasonic.h" #include <Servo.h> Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created Ultrasonic ultrasonicCenter(12,13); Ultrasonic ultrasonicRight(10,11); Ultrasonic ultrasonicLeft(6,7); int servoPos = 90; // variable to store the servo position int servoIncr = 10; // variable to store the servo increment const int MINSERVOPOS=55; const int MAXSERVOPOS=125; void setup() { Serial.begin(4800); myservo.attach(3); // attaches the servo on pin 9 to the servo object } void loop() { Serial.print("$USDIS,"); Serial.print(ultrasonicLeft.Ranging(CM)); Serial.print(","); Serial.print(ultrasonicCenter.Ranging(CM)); Serial.print(","); Serial.print(ultrasonicRight.Ranging(CM)); Serial.print(","); Serial.print(servoPos); Serial.print("*"); Serial.print("00"); Serial.print("\r\n"); myservo.write(servoPos); // tell servo to go to position in variable 'pos' servoPos=servoPos+servoIncr; if(servoPos<MINSERVOPOS || servoPos>MAXSERVOPOS) servoIncr=-servoIncr; delay(100); } byte calcChecksumBuf(byte checksum, byte buf[], int i, int len){ for(;i<len; i++){ checksum=calcChecksum(checksum,buf[i]); } return checksum; } byte calcChecksum(byte checksum, byte c){ if ( c == '$' ) return 0; if ( c != '\r' && c != '\n' && c != '*' ) { checksum ^= c; } return checksum; }
New Ping
From http://code.google.com/p/arduino-new-ping/wiki/15_Sensors_Example ... TODO ...
MSP430
Voir le programme pour l'US-100 Ultrasonic Distance Sensor Module