Analog Distance Sensor SN-GP2Y0A21

Distance sensors are widely used in applications that require distance measurement. It is also used in robotics application to detect and measure distance with wall or obstacles. So we are going to look on Analog Distance Sensor SN-GP2Y0A21. As it’s name sounds, it gives out analog readings with changes in distance.

Image
SN-GP2Y0A21

Some features of SN-GP2Y0A21:

– Analog output

– Detecting distance: 10cm to 80cm

– Operating supply voltage: +4.5V to +5.5V

Image
Pin connections for SN-GP2Y0A21
dist7
Schematic Diagram

To use the sensor, we need to look in details of the output. The output voltage is not linear to the distance. There is an analog output voltage vs distance plot in the datasheet.

Image
Analog Output Voltage vs Distance

An example code of using this sensor on Arduino:


#include <LiquidCrystal.h>
#define sensor A1
float volt;

LiquidCrystal lcd(5,6,7,8,9,10);

void setup()
{
 lcd.begin(16,2);
 pinMode(sensor,INPUT);
}

void loop()
{
 float reading=analogRead(sensor);
 volt=(reading/1023)*5;
 lcd.setCursor(0,0);
 lcd.print("ADC :");
 lcd.setCursor(9,0);
 lcd.print((int)reading);
 lcd.setCursor(0,1);
 lcd.print("Voltage:");
 lcd.setCursor(9,1);
 lcd.print(volt);
 lcd.setCursor(13,1);
 lcd.print("V");
 delay(500);
}

A view of the circuit:

Image

Image

Video on Analog Distance Sensor SN-GP2Y0A21:

 

If you have any questions, feel free to comment.

6 thoughts on “Analog Distance Sensor SN-GP2Y0A21

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s