कला
सुन्दरता र कल्याण
हस्तकला
संस्कृति र इतिहास
मनोरञ्जन
वातावरण
खाना र पेय
हरित भविष्य
रिभर्स इन्जिनियरिङ
विज्ञान
खेलकुद
प्रविधि
पहिर्न मिल्ने
Building an Infrared Distance Sensor
Ed

सिर्जनाकर्ता

Ed

13. जुलाई 2026FI

Building an Infrared Distance Sensor

Measure distance with light. A Sharp infrared sensor bounces a beam off an object and reports, as a voltage, the angle it returns at — closer objects give a higher reading. The Arduino turns that into an approximate distance and lights an LED when something comes near: a touchless switch, a hand-wave trigger, or a robot's eyes. Unlike the ultrasonic sensor, this uses infrared light, works at short range, and makes no sound.

मध्यम
1 hour

निर्देशनहरू

1

Wire the sensor and LED

The Sharp sensor has a 3-wire cable: VCC (red) to Arduino 5V, GND (black) to GND, and signal (white or yellow) to A0. On the breadboard, wire an LED from pin 7 through a 330 Ω resistor to GND (long leg to the pin).

Materials for this step:

Arduino Uno R3Arduino Uno R31 टुक्रा
Infrared Proximity Sensor - Sharp GP2Y0A21YKInfrared Proximity Sensor - Sharp GP2Y0A21YK1 टुक्रा
LED - Basic 5mmLED - Basic 5mm1 टुक्रा
Resistor 330 Ohm 1/6 Watt PTH - 20 packResistor 330 Ohm 1/6 Watt PTH - 20 pack1 प्याक
BreadboardBreadboard1 टुक्रा
Jumper Wires (Male-to-Male)Jumper Wires (Male-to-Male)1 प्याक
2

Connect and open the IDE

Plug the Arduino into your computer with the USB cable, open the Arduino IDE, and select Arduino Uno and its serial port.

Materials for this step:

USB-B CableUSB-B Cable1 टुक्रा

Tools needed:

Computer with Arduino IDEComputer with Arduino IDE
3

Upload the distance sketch

Paste this sketch and upload, then open the Serial Monitor. It reads the sensor, estimates the distance, and lights the LED when something is within 20 cm.

ir_distance_sensor.inoarduino
// Sharp GP2Y0A21YK infrared distance sensor (valid ~10-80 cm).
// The output is NON-LINEAR (roughly 1/distance); the formula below is a common
// approximation - calibrate against known distances if you need accuracy.
// Sensor signal on A0; indicator LED on pin 7.

const int IR_PIN = A0;
const int LED_PIN = 7;
const int NEAR_CM = 20;   // light the LED when something is closer than this

void setup() {
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int raw = analogRead(IR_PIN);
  float volts = raw * (5.0 / 1023.0);

  // approximate distance in cm for the GP2Y0A21 curve
  float distance = 27.86 * pow(volts, -1.15);

  Serial.print(distance);
  Serial.println(" cm");

  if (distance < NEAR_CM) {
    digitalWrite(LED_PIN, HIGH);   // object nearby
  } else {
    digitalWrite(LED_PIN, LOW);
  }
  delay(200);
}
4

Test and understand the curve

Open the Serial Monitor and move your hand between about 10 and 80 cm — the printed distance should track it, and the LED lights inside 20 cm. Two things to know: below ~10 cm the reading becomes ambiguous (the sensor's curve folds back), and the output is non-linear, so for real accuracy note the raw value at a few known distances and fit your own curve.

5

Put it to work

Use it as a touchless switch (wave to trigger), a shelf or drawer 'is-it-open' sensor, or an obstacle detector for a small robot. Change NEAR_CM to set the trigger distance, or swap in the short-range (4–30 cm) or long-range (20–150 cm) Sharp sensor for a different span.

सामग्री

7

आवश्यक उपकरणहरू

1
Estimated Total
$64.00

सम्बन्धित ब्लुप्रिन्ट

यी ब्लुप्रिन्टहरूले ज्ञान साझा गर्छन् — प्रविधि, सामग्री वा सिद्धान्त

CC0 सार्वजनिक डोमेन

यो ब्लुप्रिन्ट CC0 अन्तर्गत जारी गरिएको छ। तपाईं अनुमति नसोधी प्रतिलिपि, परिमार्जन, वितरण र प्रयोग गर्न सक्नुहुन्छ।

ब्लुप्रिन्ट मार्फत उत्पादनहरू किनेर सिर्जनाकर्तालाई सहयोग गर्नुहोस् सिर्जनाकर्ता कमिसन विक्रेताले तोकेको, वा यो ब्लुप्रिन्टको नयाँ संस्करण बनाउनुहोस् र आम्दानी बाँड्न आफ्नो ब्लुप्रिन्टमा जडानको रूपमा समावेश गर्नुहोस्।

छलफल

(0)

लग इन छलफलमा सामेल हुन

टिप्पणीहरू लोड गर्दै...