Maggie George
Created December 7, 2015

Distance Measuring Sensor assignment

creating simple distance measuring sensor using a 2YA21 Sharp Infrared Proximity Sensor and Arduino.

Full instructions provided4,683
Distance Measuring Sensor assignment

Things used in this project

Hardware components

SparkFun 2YA21 Sharp Infrared Proximity Sensor
×1
Arduino UNO
Arduino UNO
×1

Story

Read more

Schematics

Distance Measuring IR Sensor Schematic

used to operate distance measuring IR sensor using arduino.

Code

Distance Measuring IR Sensor Code

C/C++
Used to request values of object distance from an IR Distance Measuring 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(100);                    // wait for this much time before printing next value
}

Credits

Maggie George

Maggie George

9 projects • 5 followers

Comments