(SKU:RB-02S041)Sharp GP2D12 IR Distance Sensor(10cm-80cm)

From ALSRobot-Wki
Jump to: navigation, search
RB-02S041.jpg

Contents

overview

GP2D12 IR sensor is a cost-effective, most commonly used infrared distance Sensor by Japan Sharp company, it can be used to measure the distance of the object, realize wheeled robot detect function. It is not only small volume, low power consumption, cheap but also good ranging effect, suitable to the robot enthusiasts.

Technical parameters and performance

  1. Measurement range: 10 to 80cm
  2. Supply voltage: 4.5 to 5.5V
  3. Average consumption: 35mA
  4. Peak consumption: 200mA
  5. Uprate rate: 25Hz/40ms
  6. Analog output noise: <200mV
  7. Relationship between measure distance and analog output
  8. Voltage: 2.4V-0.4V corresponding 10cm-80cm
  9. Weight:4g

using method

Pin definition

  • Vo: output pin
  • GND: power supply
  • Vcc: power supply positive

Product size chart

RB-02S0411.jpg

Analog signal and measuring range

RB-02S0412.jpg

Signal output

RB-02S0413.jpg

Application Routine

The distance sensor is fixed to the steering gear, you can use hot melt adhesive or adhesive tape. And then use a 1uF electrolytic capacitor and a 22uF electrolytic capacitor in parallel with the 5V regulator chip L4940V5. Insert the signal line of the infrared distance sensor into analog pin 0. 4 LED resistors are inserted into 3, 5, 6, 11 pins by 1K. Finally, the actuator signal line is connected to the 9 pin.

Connection diagram

RB-02S0414.jpg

Sample code

#include <Servo.h>

 const int SERVO  =9;   
 const int IR     =0;   
 const int LED1   =3;   
 const int LED2   =5;  
 const int LED3   =6;   
 const int LED4   =11; 

Servo myServo;    
int dist1 = 0;     
int dist2 = 0;     
int dist3 = 0;     
int dist4 = 0;     

void setup()
{
    myServo.attach(SERVO); 
    pinMode(LED1, OUTPUT);
    pinMode(LED2, OUTPUT); 
    pinMode(LED3, OUTPUT); 
    pinMode(LED4, OUTPUT); 
}

void loop()
{
    
    dist1 = readDistance(15);     
    analogWrite(LED1, dist1);     
    delay(300);                   
 
    dist2 = readDistance(65);     
    analogWrite(LED2, dist2);     
    delay(300);                   
 
    dist3 = readDistance(115);    
    analogWrite(LED3, dist3);    
    delay(300);                   
 
    dist4 = readDistance(165);   
    analogWrite(LED4, dist4);    
    delay(300);                   
}

int readDistance(int pos)
{
    myServo.write(pos);               
    delay(600);                       
    int dist = analogRead(IR);         
    dist = map(dist, 50, 500, 0, 255); 
    dist = constrain(dist, 0, 255);    
    return dist;                      
}

Program effect

When the steering gear is rotated to a given position, the distance is measured and converted to a LED brightness value, changing the LED brightness value, and turning it to the next position, and then continue, so that the.

Product recommendation

Buy address:Sharp GP2D12 IR Distance Sensor(10cm-80cm)

Personal tools
Namespaces

Variants
Actions
Navigation
Tools