SIDST-GP2 is a distance sensor with analog output. You can use this module for measuring distance to objects located between 10 to 80cm.
For example, a robot could use SIDST-GP2 to detect obstacles or find objects.
Bill of materials:
This module doesn't require any kind of homemade electronic circuit. Just buy a GP2D-12 or GP2Y0A21YK and build a simple cable for connecting it to the Main Board.
Printable version: Single, Double, Quad
SIDST-GP2 will output a voltage level depending on the distance to the closest object put in front of it.
It can be powered from 4.5 to 5.5V, and can measure objects in the 10-80cm range.
The Main Board will receive a given voltage through pin #1 (the data pin). It should be converted using the microcontroller internal Analog-to-Digital Converter.
The distance to the object is inverse to the output voltage, for example:
All the information and possible output voltages can be found in its datasheet.
The following code can be compiled using SDCC.
/*================================================================== * Sample program for SIDST-GP2 using an MBP18 * * Plug SIDST-GP2 to RA0/AN0 (pin 17) and LTIND-A to RB4 (pin 10). * The LED will light up when there is an object closer than 25cm * * http://curuxa.org *=================================================================*/ #include <MBP18.h> #include <GP2.h> ConfigBits1(_CP_OFF & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_OFF & _PWRTE_ON & _WDT_OFF & _INTRC_IO); #define LED RB4 #define LedON 1 #define LedOFF 0 void main() { TRISB4=0; EnableAN0(); while(1) { //note: distance and ADC values are inversely correlated if(AdcMeasure() > GP2_25cm) LED=LedON; else LED=LedOFF; } }