How to Use a Motion Sensor with Raspberry Pi Pico

Basic Input / Output
(Image credit: Tom's Hardware)

The Raspberry Pi Pico has a number of GPIO pins which we can use as inputs or outputs by simply configuring the pins in our code. In this guide, we shall learn how to work with inputs, in this case a sensor, and outputs in the form of an LED. At the end of this guide we will have a simple motion detector in 16 lines of MicroPython. 

Before tackling this project, it would be beneficial to setup and test your Raspberry Pi Pico in our Raspberry Pi Pico Set Up Guide . We also use the circuit in that guide as the basis for this guide.

Latest Videos FromTom's Hardware
Les Pounder
Associate Editor

Les Pounder is an associate editor at Tom's Hardware. He is a creative technologist and for seven years has created projects to educate and inspire minds both young and old. He has worked with the Raspberry Pi Foundation to write and deliver their teacher training program "Picademy".

  • mideal
    Trying this code with the SR505 (the smaller version of the PIR sensor), omitting the LED connection and its code.
    I simply wanted to test the motion sensor (to control a servo afterwards).
    There is a motion detection every approx. 6 seconds - even when I put it into a black bag covered with a black cloth and no movement of nothing at all.
    Any idea?
    Reply
  • mideal
    NOW I found it. ... it's a standard delay time.....
    More investigation needed, or I need a SR501 like in your example.
    Reply