In this guide, we will be showing you how to use an IR sensor with your Raspberry Pi Pico using MicroPython. We will also be providing you with a code example to help you get started. We will also learn how to interface an IR sensor with Raspberry Pi Pico
- Raspberry Pi Pico W
- IR Infrared Obstacle Avoidance Sensor
- Light-Emitting Diode (LED)
- Jumper Wire
IR Infrared Obstacle Avoidance Sensor
IR sensor is used to detect the presence of an object by emitting and detecting infrared radiation.is a very popular sensor which is used in many applications like remote control, proximity sensor, line following robots security systems, etc. The working of an IR sensor is very simple. It consists of an IR transmitter and an IR receiver.
The IR transmitter emits infrared radiation which is detected by the IR receiver. When an object is placed in front of the IR sensor, the infrared radiation is reflected back to the receiver. This change in the intensity of the received infrared radiation is used to determine the presence of an object.
Raspberry Pi Pico
Raspberry Pi Pico is a new microcontroller board from the makers of the popular Raspberry Pi single-board computer. Pico is the company’s first microcontroller board developed specifically for use with the MicroPython programming language.
MicroPython is a lean and efficient implementation of the Python 3 programming language that is optimized for microcontrollers.
Raspberry Pi Pico Pinout
How to use IR Sensor With Raspberry Pi Pico
First, we need to connect the IR sensor to the Raspberry Pi Pico as shown in the above circuit diagram. After connecting the IR sensor to the Raspberry Pi Pico, we need to write a program to read the output of the IR sensor.
The following code can be used to read the output of the IR sensor and the LED.
reed = machine.Pin(16, machine.Pin.IN)
led = machine.Pin(17, machine.Pin.OUT)
if reed.value() == 0:
print("IR Sensor Detected!")
In ending, it is possible to use an IR sensor with Raspberry Pi Pico using Micropython. By following the instructions in this article, you can successfully set up your IR sensor and use it to detect objects.