|
| 1 | +:imagesdir: img/ |
| 2 | + |
| 3 | +ifndef::rootpath[] |
| 4 | +:rootpath: ../../ |
| 5 | +endif::rootpath[] |
| 6 | + |
| 7 | +ifdef::rootpath[] |
| 8 | +:imagesdir: {rootpath}{imagesdir} |
| 9 | +endif::rootpath[] |
| 10 | + |
| 11 | +==== IR Obstacle Avoidance Sensor |
| 12 | +[.text-right] |
| 13 | +https://github.com/oss-slu/Pi4Micronaut/edit/develop/pi4micronaut-utils/src/docs/asciidoc/components/inputComponents/irObstacleAvoidanceSensor.adoc[Improve this doc] |
| 14 | + |
| 15 | +===== Overview |
| 16 | +This section provides details for the IR Obstacle Avoidance Sensor, including its components, assembly instructions, and functionality. |
| 17 | + |
| 18 | +The IR (Infrared) Obstacle Avoidance Module is a proximity sensor that detects objects and obstacles within a short distance (2-30cm) using infrared reflection. It is commonly used in robotics for collision avoidance, object detection, and boundary sensing. The module features adjustable sensitivity via a potentiometer, digital output for easy integration, fast response time, low power consumption, and operates on 3.3V to 5V power supplies. |
| 19 | + |
| 20 | +===== Components |
| 21 | +* 1 x Raspberry Pi 4 |
| 22 | +* 1 x IR Obstacle Avoidance Module |
| 23 | +* 5 x Male-to-Male Jumper Wires |
| 24 | +* 1 x Breadboard |
| 25 | +* Power supply for Raspberry Pi |
| 26 | + |
| 27 | +===== Assembly Instructions |
| 28 | +* Place the IR Obstacle Avoidance Module onto the breadboard. |
| 29 | +* Connect the **VCC** pin of the IR module to **3.3V** on the Raspberry Pi. |
| 30 | +* Connect the **GND** pin of the IR module to **Ground** on the Raspberry Pi. |
| 31 | +* Connect the **OUT** (or **DO**) pin of the IR module to **GPIO 17** on the Raspberry Pi. |
| 32 | +* Use the remaining two jumper wires to secure the module to the breadboard, following the provided circuit diagram. |
| 33 | +* Verify connections to ensure no loose wires or short circuits. |
| 34 | +* Adjust the potentiometer to set detection sensitivity: |
| 35 | + - Turn **clockwise** to increase sensitivity. |
| 36 | + - Turn **counter-clockwise** to decrease sensitivity. |
| 37 | + |
| 38 | +> **Tip**: Use 3.3V for compatibility with Raspberry Pi GPIO. Ensure the module's IR LEDs face forward. |
| 39 | + |
| 40 | +===== Circuit Diagram |
| 41 | +image::irObstacleAvoidance-CD.png[] |
| 42 | + |
| 43 | +===== Schematic Diagram |
| 44 | +image::irObstacleAvoidance-SD.png[] |
| 45 | + |
| 46 | +===== Functionality |
| 47 | +The IR Obstacle Avoidance Module uses active infrared light reflection to detect obstacles. It emits infrared light via an onboard LED, which reflects off nearby objects and is detected by the IR receiver. The onboard comparator circuit processes the signal and outputs a digital signal (LOW when an obstacle is detected, HIGH when the path is clear). The detection range (2-30cm) is adjustable via the potentiometer, making it suitable for real-time robotics applications. |
| 48 | + |
| 49 | +===== Testing |
| 50 | +Use the following commands to test the component: |
| 51 | + |
| 52 | +[source, bash] |
| 53 | +---- |
| 54 | +$curl http://localhost:8080/ir-obstacle/status |
| 55 | +---- |
| 56 | +* `/status` - Returns `true` if an obstacle is detected, `false` if the path is clear. |
| 57 | + |
| 58 | +[source, bash] |
| 59 | +---- |
| 60 | +$curl http://localhost:8080/ir-obstacle/state |
| 61 | +---- |
| 62 | +* `/state` - Returns the raw digital state (`HIGH` or `LOW`). |
| 63 | + |
| 64 | +[source, bash] |
| 65 | +---- |
| 66 | +$curl http://localhost:8080/ir-obstacle/message |
| 67 | +---- |
| 68 | +* `/message` - Returns a human-readable status (`"Obstacle detected"` or `"No obstacle"`). |
| 69 | + |
| 70 | +[source, bash] |
| 71 | +---- |
| 72 | +$curl http://localhost:8080/ir-obstacle/wait/{timeoutMillis} |
| 73 | +---- |
| 74 | +* `/wait/{timeoutMillis}` - Waits for obstacle detection within the specified timeout (in milliseconds) and returns `true` if detected, `false` otherwise. |
| 75 | + |
| 76 | +[source, bash] |
| 77 | +---- |
| 78 | +$curl http://localhost:8080/ir-obstacle/init |
| 79 | +---- |
| 80 | +* `/init` - Initializes the sensor and adds an event listener to print `"Obstacle Detected"` or `"No Obstacle"` to the console when the sensor state changes. |
| 81 | + |
| 82 | +===== Troubleshooting |
| 83 | +**Sensor Always Reports Obstacle Detected**: |
| 84 | +* Adjust potentiometer counter-clockwise to decrease sensitivity. |
| 85 | +* Ensure the module is not facing a reflective surface. |
| 86 | +* Verify VCC is connected to 3.3V. |
| 87 | +* Test with a white object to confirm detection. |
| 88 | +* Check GPIO state with `gpio readall`. |
| 89 | + |
| 90 | +**Sensor Never Detects Obstacles**: |
| 91 | +* Adjust potentiometer clockwise to increase sensitivity. |
| 92 | +* Verify OUT pin is connected to GPIO 17. |
| 93 | +* Confirm `application.yml` has the correct GPIO address. |
| 94 | +* Test with a reflective object (e.g., white or shiny surface). |
| 95 | +* Measure OUT pin voltage with a multimeter (should switch between 0V and 3.3V). |
| 96 | + |
| 97 | +**Inconsistent Detection**: |
| 98 | +* Increase debounce time in `application.yml` to 20000 (20ms). |
| 99 | +* Secure all jumper wires. |
| 100 | +* Shield from sunlight or other IR sources. |
| 101 | +* Mount the module rigidly to prevent vibration. |
| 102 | +* Add a 100µF capacitor across VCC and GND near the module. |
| 103 | + |
| 104 | +**Module Won't Power On**: |
| 105 | +* Verify 3.3V at VCC with a multimeter. |
| 106 | +* Check GND connections. |
| 107 | +* Ensure `application.yml` is correctly configured. |
| 108 | +* Test GPIO manually with `gpio mode 17 in` and `gpio read 17`. |
| 109 | + |
| 110 | +**Application Crashes**: |
| 111 | +* Verify `application.yml` syntax and `ir-obstacle-input` key. |
| 112 | +* Ensure `@Named("ir-obstacle-input")` matches the configuration. |
| 113 | +* Rebuild with `./gradlew clean build`. |
| 114 | +* Check logs for configuration errors. |
| 115 | + |
| 116 | +===== YAML Configuration |
| 117 | +The IR Obstacle Avoidance Sensor configuration as it appears in the YAML file: |
| 118 | + |
| 119 | +[source, yaml] |
| 120 | +---- |
| 121 | +pi4j: |
| 122 | + digital-input: |
| 123 | + ir-obstacle-input: |
| 124 | + name: IR Obstacle Avoidance Sensor |
| 125 | + address: 17 |
| 126 | + pull: PULL_UP |
| 127 | + debounce: 10000 |
| 128 | + provider: pigpio-digital-input |
| 129 | +---- |
| 130 | + |
| 131 | +===== Constructor and Methods |
| 132 | +To see the constructor and methods of the `IRObstacleAvoidance` class, refer to the JavaDoc: link:https://oss-slu.github.io/Pi4Micronaut/javadoc/com/opensourcewithslu/inputdevices/IRObstacleAvoidance.html[IRObstacleAvoidance JavaDoc] |
| 133 | + |
| 134 | +===== Example Controller |
| 135 | +This controller demonstrates the usage of the IR Obstacle Avoidance Sensor: |
| 136 | + |
| 137 | +[source, java] |
| 138 | +---- |
| 139 | +include::../../../../../../components/src/main/java/com/opensourcewithslu/components/controllers/IRObstacleAvoidanceController.java[tag=ex] |
| 140 | +---- |
0 commit comments