How to use IR proximity sensors and Arduino Uno to detect objects? The core steps of using IR proximity sensors and Arduino Uno to detect objects are hardware connection, code writing, and logical judgment. The Arduino response is triggered by changes in sensor output level to achieve object detection function. Here are the specific implementation methods:
1. Hardware preparation and list of connected components IR proximity sensor module (including transmitter, receiver, signal processing circuit) Arduino Uno development board RED LED (for status indication) 220 ohm resistor (current limiting protection LED) USB cable, jumper several sensor characteristics detection distance: 2-30cm Output logic: output low level (0V) when an object appears, output high level (5V) when there is no object Working voltage: 3.3-5V (compatible with Arduino) Circuit connection IR sensor: VCC → Arduino 5VGND → Arduino GNDOUT → Arduino digital pin 8 (D8) LED indicator circuit: LED positive pole is connected to Arduino digital pin 13 (D13) through a 220 ohm resistor LED negative terminal connected to Arduino GND Figure 1: Schematic diagram of pin connection between IR sensor and Arduino
2. Code implementation and logic code function reading IR The sensor output level controls the LED to turn on and off according to the level status, and outputs the sensor status through the serial port (debugging). The complete code is int IRSensor=8; //IR sensor connected to D8int LED=13; //Connect the LED to D13void setup() {pinMode (IRSensor, INPUT);//Set the sensor pin to input pinMode (LED, OUTPUT); //Set the LED pin to output Serial. start (9600); //Initialize serial communication delay (500); Serial.println("Welcome to Microdigisoft"); }Void loop() {delay (1000);//1 second delay Serial. print ("IR Sensor value="); Serial.println(digitalRead(IRSensor)); //Print sensor status int statusSensor=digitalRead (IRSensor); If (statusSensor==1) {digitalWrite (LED, LOW);//LED off when there is no object} else {digitalWrite (LED, HIGH);//LED on when there is an object}} Code logic analysis initialization stage: Set the sensor pin to input mode, LED pin to output mode, and start serial communication. Main loop: Read the sensor output value (digitalRead (IRSensor)). If the output is high
(1), it means there is no object and the LED is off; If it is a low level (0), it indicates the presence of an object and the LED lights up. Printing sensor status through serial port for easy debugging.
III. Working Principle and Debugging Sensor Working Principle IR sensors determine the presence of objects by emitting infrared light and detecting the intensity of reflected light.
. When an object enters the detection range, the reflected light increases and the sensor outputs a low level; Conversely, output a high level. Debugging key distance adjustment: Ensure that the object is within the detection range of the sensor (2-30cm). Level verification: Observe whether the sensor output value meets expectations through the serial monitor (0 when there is an object, 1 when there is no object). LED status: Confirm that the LED on/off is consistent with the presence of the object. Figure 2: Schematic diagram of IR sensor and Arduino physical connection4. Extended application distance threshold adjustment: If more accurate distance detection is required, an adjustable distance IR sensor module can be selected, or analog reading can be achieved through PWM output

Current position >About Us