Difference between revisions of "SF-SR02 Ultrasonic Module"

From Wiki
Jump to: navigation, search
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
=='''Introduction'''==
 
=='''Introduction'''==
This module contains an ultrasonic sensor to detect the distance to an obstacle in front. It is usually used on robots to avoid obstacles. With the two holes, it can be installed easily on the robot. The sensor detects obstacles 2cm-700cm away, though it keeps stable signal output within 5m and the signals become weaker and weaker when it gets farther away from the obstacle beyond 5m.  
+
[[File:SF SR02.png]] <br>
There is power indicator light added onside to indicate power on/off. The 3-pin design makes it unique among most of the ultrasonic module in the market: the same pin to trigger and receive signals. The 3-pin anti-reverse cable included make the wiring tighter and more convenient. Also the beautiful cartoon design and the red PCB add to its fascination
+
This module contains an ultrasonic sensor to detect the distance to an obstacle in front. It is usually used on robots to avoid obstacles. With the two holes, it can be installed easily on the robot. The sensor detects obstacles 2cm-700cm away, though it keeps stable signal output within 5m and the signals become weaker and weaker when it gets farther away from the obstacle beyond 5m. <br>
 +
There is power indicator light added onside to indicate power on/off. The 3-pin design makes it unique among most of the ultrasonic module in the market: the same pin to trigger and receive signals. The 3-pin anti-reverse cable included make the wiring tighter and more convenient. Also the beautiful cartoon design and the red PCB add to its fascination.<br>
 +
<font color="red">Note: Pin NSE is to burn firmware to the ship when it's manufactured and does not need to use later. If you hear some slight noise during the application, it's fine. </font>
  
[[File:Ultrasonic .jpg]] <br>
 
 
=='''Feature'''==
 
=='''Feature'''==
1) An ultrasonic module with a detecton range of 2cm-700cm; signals detected are stable within 5m, grow weaker beyond 5m and at last disappear
+
1) An ultrasonic module with a detecton range of 2cm-700cm; signals detected are stable within 5m, grow weaker beyond 5m and at last disappear<br>
2) With a power indicator LED so you can tell whether it is powered
+
2) With a power indicator LED so you can tell whether it is powered<br>
3) Auxiliary 3-pin anti-reverse cable, thus making the wiring tighter and convenient
+
3) Auxiliary 3-pin anti-reverse cable, thus making the wiring tighter and convenient<br>
4) Operating voltage: 5V; working current: 16mA
+
4) Operating voltage: 5V; working current: 16mA<br>
5) A cartoon shape with red PCB design, making it adorable and cute
+
5) A cartoon shape with red PCB design, making it adorable and cute<br>
  
  
 
=='''Pin Function'''==
 
=='''Pin Function'''==
 +
'''GND''': ground of the power<br>
 +
'''5V''': 5V Supply<br>
 
'''SIG''': Trigger Pulse Input and Echo Pulse Output<br>
 
'''SIG''': Trigger Pulse Input and Echo Pulse Output<br>
'''GND''': Ground<br>
+
'''NSE''': No need to use; only used to burn the firmware to the chip when the module is manufactured.<br>
'''VCC''': 5V Supply<br>
+
 
 
=='''Features'''==
 
=='''Features'''==
 
{| border="1" class="wikitable"
 
{| border="1" class="wikitable"
Line 43: Line 46:
 
|}
 
|}
  
=='''Pricinple'''==
 
The Timing diagram is shown below. You only need to supply a short 10uS pulse to the trigger input to start the ranging, and then the module will send out an 8 cycle burst of ultrasound at 40 kHz and raise its echo. The Echo is a distance object that is pulse width and the range in proportion .You can calculate the range through the time interval between sending trigger signal and receiving echo signal. Formula: uS / 58 = centimeters or uS / 148 =inch; or: the range = high level time * velocity (340M/S) / 2; we suggest to use over 60ms measurement cycle, in order to prevent trigger signal to the echo signal.
 
[[File:Cha.png]]
 
 
=='''Test Code'''==
 
=='''Test Code'''==
 +
{| border="1" class="wikitable"
 +
|SF-SR02
 +
|Uno
 +
|-
 +
|GND
 +
|GND
 +
|-
 +
|5V
 +
|5V
 +
|-
 +
|SIG
 +
|A0
 +
|-
 +
|NSE
 +
|NOT Connected
 +
|}
 
<pre>
 
<pre>
 +
/******************************************
 +
* Name:SF-SR02 Ultrasonic Module
 +
* Function:Detection the distance
 +
For any technical questions, visit http://www.sunfounder.com/forum
 +
**********************************************/
 +
//Email: service@sunfounder.com
 +
//Website: www.sunfounder.com
 +
 
#include <Wire.h>
 
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
 
  
#define Echo 11 //Echo connnect to pin11
+
#define SIG A0 //SIG attach to A0 of control board
#define Trig 12 //Trig connect to pin12
+
unsigned long rxTime;
unsigned long rxTime; //define a variable
+
float distance;
float distance;  
+
 
LiquidCrystal_I2C lcd(0x27,16,2);
+
 
void setup()  
 
void setup()  
 
{
 
{
 
   // put your setup code here, to run once:
 
   // put your setup code here, to run once:
   Serial.begin(115200); //set the baud rate of serial monitor
+
   Serial.begin(115200);
  pinMode(Echo,INPUT);
+
  pinMode(Trig,OUTPUT);
+
  lcd.init();                      // initialize the lcd
+
 
+
  // Print a message to the LCD.
+
  lcd.backlight(); //turn o the backlight
+
  lcd.setCursor(0, 0); //set the cursor on 0 row,0 col
+
  lcd.print("Ping:"); //print the "Ping: "on the LCD
+
 
}
 
}
  
void loop()
+
void loop() {
{
+
   //set SIG as OUTPUT,start to output trigger signal to the module to start the ranging
   // Generates a pulse
+
  pinMode(SIG, OUTPUT);
   digitalWrite(Trig, HIGH);
+
  //Genarate a pulse 20uS pulse
   delayMicroseconds(10);
+
   digitalWrite(SIG, HIGH);
   digitalWrite(Trig, LOW);
+
   delayMicroseconds(20);
   rxTime = pulseIn(Echo, HIGH); //read the Receive time
+
   digitalWrite(SIG, LOW);
 +
  //set SIG as INPUT,start to read value from the module
 +
  pinMode(SIG, INPUT);
 +
   rxTime = pulseIn(SIG, HIGH);//waits for the pin SIG to go HIGH, starts timing, then waits for the pin to go LOW and stops timing
 
   //  Serial.print("rxTime:");
 
   //  Serial.print("rxTime:");
 
   //  Serial.println(rxTime);
 
   //  Serial.println(rxTime);
   distance = (float)rxTime * 34 / 2000.0; //Converted into a distance ,cm
+
   distance = (float)rxTime * 34 / 2000.0; //convert the time to distance
   if(distance < 800 ) //filter interference signal
+
  //leave the distance between 2cm-800cm
 +
   if(distance < 2)
 +
  {
 +
    distance=0;
 +
  }
 +
  if(distance > 800)
 
   {
 
   {
     Serial.print("distance:");
+
     distance=0;
    Serial.print(distance); //print it the distance in serial monitor
+
    Serial.println("CM");
+
    lcd.setCursor(6, 0);
+
    lcd.print(distance);//print it in LCD1602
+
    lcd.print("CM");
+
    delay(100);
+
 
   }
 
   }
 +
  Serial.print("distance: "); //print distance:
 +
  Serial.print(distance); //print the distance
 +
  Serial.println("CM"); //and the unit
 +
  delay(10);
 
}
 
}
 
</pre>
 
</pre>
[[File:Fdfd.jpg]]
 
  
 
=='''Resource'''==
 
=='''Resource'''==
[http://www.sunfounder.com/wiki/index.php?title=File:Ultrasonic.zip Ultrasonic Test Code][[File:ZIP.jpg]]<br>
+
[http://wiki.sunfounder.cc/images/7/7c/SF_SR02.zip SF_SR02 Test Code][[File:ZIP.jpg]]<br>
[http://www.sunfounder.com/wiki/index.php?title=File:MAX232_DataSheet.pdf MAX232_DataSheet][[File:PDF.jpg]]<br>
+
[http://wiki.sunfounder.cc/images/f/f1/MAX232_DataSheet.pdf MAX232_DataSheet][[File:PDF.jpg]]<br>
[http://www.sunfounder.com/wiki/index.php?title=File:SGM324YS14.pdf SGM324YS14 datasheet][[File:PDF.jpg]]
+
[http://wiki.sunfounder.cc/images/b/ba/SGM324YS14.pdf SGM324YS14 datasheet][[File:PDF.jpg]]

Latest revision as of 08:31, 15 March 2017

Introduction

SF SR02.png
This module contains an ultrasonic sensor to detect the distance to an obstacle in front. It is usually used on robots to avoid obstacles. With the two holes, it can be installed easily on the robot. The sensor detects obstacles 2cm-700cm away, though it keeps stable signal output within 5m and the signals become weaker and weaker when it gets farther away from the obstacle beyond 5m.
There is power indicator light added onside to indicate power on/off. The 3-pin design makes it unique among most of the ultrasonic module in the market: the same pin to trigger and receive signals. The 3-pin anti-reverse cable included make the wiring tighter and more convenient. Also the beautiful cartoon design and the red PCB add to its fascination.
Note: Pin NSE is to burn firmware to the ship when it's manufactured and does not need to use later. If you hear some slight noise during the application, it's fine.

Feature

1) An ultrasonic module with a detecton range of 2cm-700cm; signals detected are stable within 5m, grow weaker beyond 5m and at last disappear
2) With a power indicator LED so you can tell whether it is powered
3) Auxiliary 3-pin anti-reverse cable, thus making the wiring tighter and convenient
4) Operating voltage: 5V; working current: 16mA
5) A cartoon shape with red PCB design, making it adorable and cute


Pin Function

GND: ground of the power
5V: 5V Supply
SIG: Trigger Pulse Input and Echo Pulse Output
NSE: No need to use; only used to burn the firmware to the chip when the module is manufactured.

Features

Working Voltage DC5V
Working Current 16mA
Working Frequency 40Hz
Max Range 700cm, Ensured stable signal within 5m, gradually faded signal outside 5m till disappearing at 7m position.
Min Range 2cm
Trigger Input Signal 10uS TTL pulse
Echo Output Signal Input TTL lever signal and the range in proportion
Dimension 46x20.5x15 mm

Test Code

SF-SR02 Uno
GND GND
5V 5V
SIG A0
NSE NOT Connected
/******************************************
 * Name:SF-SR02 Ultrasonic Module
 * Function:Detection the distance
For any technical questions, visit http://www.sunfounder.com/forum
 **********************************************/
//Email: service@sunfounder.com
//Website: www.sunfounder.com

#include <Wire.h>

#define SIG A0 //SIG attach to A0 of control board
unsigned long rxTime;
float distance;

void setup() 
{
  // put your setup code here, to run once:
  Serial.begin(115200);
}

void loop() {
  //set SIG as OUTPUT,start to output trigger signal to the module to start the ranging
  pinMode(SIG, OUTPUT);
  //Genarate a pulse 20uS pulse
  digitalWrite(SIG, HIGH);
  delayMicroseconds(20);
  digitalWrite(SIG, LOW);
  //set SIG as INPUT,start to read value from the module
  pinMode(SIG, INPUT);
  rxTime = pulseIn(SIG, HIGH);//waits for the pin SIG to go HIGH, starts timing, then waits for the pin to go LOW and stops timing
  //  Serial.print("rxTime:");
  //  Serial.println(rxTime);
  distance = (float)rxTime * 34 / 2000.0; //convert the time to distance
  //leave the distance between 2cm-800cm
  if(distance < 2)
  {
    distance=0;
  }
  if(distance > 800)
  {
    distance=0;
  }
  Serial.print("distance: "); //print distance: 
  Serial.print(distance); //print the distance
  Serial.println("CM"); //and the unit
  delay(10);
}

Resource

SF_SR02 Test CodeZIP.jpg
MAX232_DataSheetPDF.jpg
SGM324YS14 datasheetPDF.jpg