## Introduction

An infrared obstacle avoidance sensor receives a signal when there is an object blocking its path.

In this guide, you will learn to connect an infrared obstacle avoidance sensor with the micro:bit, and get it to turn an LED off when an obstacle such as your hand or a piece of white paper is in its path.

Complete this guide to learn the basics and use it in your own projects. Some examples of what it can be used for include security alarm systems or an obstacle avoidance robot.

1. ## Step 1 The Module

• Let's take a closer look at the infrared obstacle avoidance sensor. It has three pins:

OUT: This is the signal output pin which will be connected to a GPIO pin on the micro:bit. The output signal will be '0' when there is an obstacle in its way, else it will be '1'.

GND: In electronics, we define a point in a circuit to be a kind of zero volts or 0V reference point, on which to base all other voltage measurements. This point is calledÂ  ground or GND.

3.3VÂ  : While 'VCC' stands for Voltage Common Collector. We'll connect the VCC pin to 3.3V on the micro:bit

• Voltage is the difference in potential between two points. As it is difficult to talk about voltage without a reference point, we need another point to compare it to.Â

9. ## Step 9 on start block

``````pins.setPull(DigitalPin.P0, PinPullMode.PullUp)
``````
10. ## Step 10 Add the variable

``````let avoidPin = 0
pins.setPull(DigitalPin.P0, PinPullMode.PullUp)
basic.forever(function () {
})
``````
• Replace the existing code with the following code to the Javascript interface

11. ## Step 11 Conditional statement

``````let avoidPin = 0
pins.setPull(DigitalPin.P0, PinPullMode.PullUp)
basic.forever(function () {
if (avoidPin == 1) {
pins.digitalWritePin(DigitalPin.P1, 1)
} else {
pins.digitalWritePin(DigitalPin.P1, 0)
}
})
``````
• We've added an 'if... else' conditional statement here. Copy and paste this code into the Javascript interface.

12. ## Step 12 Show number

``````let avoidPin = 0
pins.setPull(DigitalPin.P0, PinPullMode.PullUp)
basic.forever(function () {
if (avoidPin == 1) {
pins.digitalWritePin(DigitalPin.P1, 1)
} else {
pins.digitalWritePin(DigitalPin.P1, 0)
}
basic.showNumber(avoidPin)
})
``````
• After you have tested out the previous code, replace it with the following in the Javascript interface.

13. ## Step 13 Upload the code

• It's time to upload the code and test it out. Connect your micro:bit to the computer using a microUSB cable