New Arduino Sharp GP2D12 Infrared IR Range Sensor + Cable
Brand New and High Quality
Infrared rangefinder : 10cm (~4") to 80cm (~30")
Analog Interface
Lead free, ROHS compliant
1、Measuring range : 10 to 80 cm
2、The maximum allowable Angle : > 40 °
3、The power supply voltage : 4.5 to 5.5 V
4、The average power consumption : 35 mA
5、Peak power consumption : about 200 mA
6、The frequency of updates/cycle : 25 Hz/40 ms
7、Analog output noise : < 200 mV
Arduino take six channel 10 ADC with itself, the GP2D12 sensor can directly connect with Arduino analog interface, and get feedback value of this sensor.
According to the official manual, it is known that the output of the GP2D12 is 0.4 V ~ 2.4 V analog signals, corresponding 10 ~ 80 cmkjtance, output is inversely proportional to distance, and nonlinear .
Code:
char GP2D12;
char a,b;
void setup()
{
Serial.begin(9600); //
}
void loop()
{
int val;
GP2D12=read_gp2d12_range(0);
a=GP2D12/10;
b=GP2D12%10;
val=a*10+b;
if(val>10&&val<80)
{
Serial.print(a,DEC);//
Serial.print(b,DEC);//
Serial.println("cm");//
}
else Serial.println("over");//
delay(50);
}
float read_gp2d12_range(byte pin)
{
int tmp;
tmp = analogRead(pin);
if (tmp < 3)return -1;
return (6787.0 /((float)tmp - 3.0)) - 4.0;
}
Package included:
1X GP2D12 IR Range Sensor
1X Cable
We can also wholesale if you need a large quantity of item please contact us.