Sie sind auf Seite 1von 9

Sharp IR distance sensor tutorial for

Arduino

Mansi Advani

PHYS 295 3 U WR Independent Research

Wilbur Wright College


Overview
GP2Y0A02YK0F is a sensor unit that measures distance (20-150cm), and is composed of an
integrated combination of IRED (infrared emitting diode), PSD (position sensitive detector) and
signal processing circuit. The temperature of the environment, the operating duration and the
various reflectivities of the object do not easily influence the distance detection because it adopts
the triangulation method.

Other features make this sensor very seamless, such as,

IR distance sensors are convenient for measuring distances without really touching a
surface.
It is an analog output type sensor, measuring distance from 20-150cm, which makes it
appropriate for broad applications.
The sensor outputs the voltage in correspondence to the detection distance, which makes
it usable as a proximity sensor.
Reads sensor readings and the index in about 7 minutes or less.
Connects easily with regular windows or OS device, does not need any special
supporting monitors or screens, or power cables.

What is IR?

In the electromagnetic spectrum, IR(Infrared) radiation is found between the visible and
microwave regions. The infrared waves typically have wavelengths between 700nm and
1000000nm (0.75 and 1000m) and lie on the low energy side of the spectrum. IR waves are not
visible to the human eye. It is important to know that Humans at normal body temperature
radiate chiefly at wavelengths around 10 m (micrometers).
The wavelength region ranging from 0.75 to 3m is known as the near infrared region. The
region between 3 and 6m is known as the mid-infrared and the infrared radiation which has a
wavelength greater higher than 6m is known as far infrared.

I will discuss this module more in detail with the widely known Arduino Uno Rev. 3 and
how to set it up and benefit from it.

I havent come across any such negative sides of this sensor, in fact to my research it is
pretty fast with the data.

Connecting to the Arduino board

The IR distance sensor can be connected in two different ways: either directly or through a
breadboard. Here, I have used a USB cable that connects to the laptop or any such screen, and 3
female jumper wires, without the use of breadboard, which is very easy to connect it with.

Apparatus

Microcontroller: Arduino UNO, Rev. 3

Sensor: SHARP 2Y0A02 F 68 IR distance sensor (proximity sensor)

Appropriate USB cable

3 female jumper wires.


The SHARP 2Y0A02 IR distance sensor

The sensor is composed of several wires, each with unique uses. Some cane be used with
resistor to test the blink program after uploading it, but here, since we dont really need to do any
uploads, we go with the code, that reads IR distance. I will briefly explain the functions for each:

Power Pins

The SHARP 2Y0A02 can be powered from 4.5- 5.5V. The consumption current for the sensor is
Typ. 33 mA.

5V is the input to the voltage.


GND is the signal and power ground pin, which connects to the microcontroller ground
pin
Ao is the output from the onboard regulator.
Arduino Wiring

The three wires protruding from the sensor has +5V, Gnd (Ground) and signal. These are
mostly color coded with red as +V, black as ground, and white or yellow as the signal. If the
infrared distance sensor does not come with any wires, there will be a need to find the
appropriate connector, or solder wires directly to the leads (ensure the solder and pins do not
contact one another) so you can attach wires.

Connect the red wire to +5V on the Arduino


Connect the black wire to Gnd on the Arduino
The yellow wire is connected to an analog pin on the Arduino (in this case we chose A0)

Moreover, if the breadboard is not used, the jumper wires are most handy and work
fine with the set up. The connection of pins remains the same.
Download the Sharp 2Y0A02 Arduino library:

http://playground.arduino.cc//Main/SharpIR

Plugging in:
As soon as the set-up is plugged in to the laptop via USB, on the Arduino ON and L light
up, and after the code is verified and uploaded, a small orange light lits up just beside the TX,
which depicts that the code is being processed.

Example Code

Open the Arduino app, and type in the code that is to be checked.

Here, I used a small example code, later click verify, and then open up the serial console to see
the result. It is seen that various light levels and the distance range in form of some numbers line
up.

Here, the code uses loop.

Void setup simply means that the sketch started

Serial.begin(9600) sets the data rate in bits per second, for transmission of serial data. For
communicating with the computer, a few rates are used of which, 9600 is one of them.

Serial.println() is a function used here to display information to the computers monitor from the
Serial library.
Here, I have the IR distance sensor hooked up on the Arduino, and since I want to see the value
that the sensor is recording, I use Serial.print() function to send the data to the computer monitor
via the USB cable.

Semicolons and curly brackets, tab play a unique role here. They are very important symbols that
define where the program ends, or whether it is the end of one string or not.

This code is now ready to be verified and run.

Finally, time for results!!

At 20cm At 30cm

As observed in the left screenshot of serial console, the values are taken at 20cm, the
beginning range for this sensor. Which lie in the range of 490-520 units. Whereas the screenshot
on the right, measures at 30cm range from 370-400 units.

USES

Touch-less switch (Control of illumination, Sanitary equipment, etc)


Sensor for energy saving (ATM, Copier, Laptop computer, vending machine, LCD
monitor)
Amusement equipment (Robot, Arcade game machine)
To connect it with a sound creating device, to prevent the entrance of certain animals like
Kioti at certain distance.

Das könnte Ihnen auch gefallen