.. note:: Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts. **Why Join?** - **Expert Support**: Solve post-sale issues and technical challenges with help from our community and team. - **Learn & Share**: Exchange tips and tutorials to enhance your skills. - **Exclusive Previews**: Get early access to new product announcements and sneak peeks. - **Special Discounts**: Enjoy exclusive discounts on our newest products. - **Festive Promotions and Giveaways**: Take part in giveaways and holiday promotions. πŸ‘‰ Ready to explore and create with us? Click [|link_sf_facebook|] and join today! .. _ar_avoid: 2.30 IR Obstacle Avoidance Sensor =================================== Overview ---------------- In this lesson, you will learn how to use IR Obstacle Avoidance Sensor. This module is commonly installed on the car and robot to judge the existence of the obstacles ahead. Also it is widely used in hand held device, water faucet and so on. Components Required ------------------------ .. image:: img/Part_two_30.png * :ref:`cpn_mega2560` * :ref:`cpn_wires` * :ref:`cpn_avoid` Fritzing Circuit ------------------------- We can directly connect the pins of IR Obstacle Sensor Module with the pins of Mega 2560 Board. The digital pin 2 is used to read the signal of IR Obstacle Avoidance Sensor Module. We get the VCC of IR Sensor Module connected to 5V, GND to GND, OUT to digital pin 2. .. image:: img/image231.png :align: center Schematic Diagram ------------------------ .. image:: img/image232.png :align: center Code ----------- .. note:: * You can open the file ``2.30_irSensorModule.ino`` under the path of ``sunfounder_vincent_kit_for_arduino\code\2.30_irSensorModule`` directly. * Or copy this code into Arduino IDE. .. raw:: html Uploaded the codes to the Mega2560 board, you can see the readings of pins on the serial monitor. When IR Obstacle Avoidance Sensor Module detects there is something covering ahead, there appears γ€Œ0」on the serial monitor; otherwise,γ€Œ1」is displayed. Refer to:ref:`ar_digital_read` to check the detail code explanation. Phenomenon Picture ----------------------- .. image:: img/image233.jpeg :align: center