Jennifer Chen
Created December 2, 2015 © GPL3+

Distance Measuring Sensor

Using SHARP 2Y0A21 Infrared Proximity Sensor

BeginnerShowcase (no instructions)167,584
Distance Measuring Sensor

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Proximity Sensor
Proximity Sensor
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Connecting Proximity Sensor to Arduino

Analog Sensor Schematic

Schematic uses a light sensor, can also be replaced with a proximity sensor

Code

Arduino Code for Proximity Sensor

Arduino
This code works with any analog sensor!
//collects data from an analog sensor

int sensorpin = 0;                 // analog pin used to connect the sharp sensor
int val = 0;                 // variable to store the values from sensor(initially zero)

void setup()
{
  Serial.begin(9600);               // starts the serial monitor
}
 
void loop()
{
  val = analogRead(sensorpin);       // reads the value of the sharp sensor
  Serial.println(val);            // prints the value of the sensor to the serial monitor
  delay(400);                    // wait for this much time before printing next value
}

Credits

Jennifer Chen

Jennifer Chen

13 projects • 12 followers

Comments