fbpx
Micropython Lesson 12: Motion Sensor
Micropython Lesson 12

Motion Sensor

Use a motion sensor to detect motion

Components Required

Magicbit
Buy
PIR sensor
Buy

Introduction

A motion sensor (or motion detector) is an electronic device that is designed to detect and measure movement. Motion sensors are used primarily in the home and business security systems. PIR Sensor is short for Passive InfraRed sensor, which applies for projects that need to detect human or particle movement in a certain range, and it can be referred to as PIR (motion) sensor, or IR sensor.

Learning outcomes:

  • Using motion sensor
  • The theoretical background of using Infrared waves in motion sensor

Theory

When a human or animal body will get in the range of the sensor, it will detect a movement because the human or animal body emits heat energy in a form of infrared radiation. That is where the name of the sensor comes from, a Passive Infra-Red sensor. In addition, the term “passive” means that the sensor is not using any energy for detecting purposes; it just works by detecting the energy given off by the other objects.

Passive Infrared sensor working method
PIR Sensor – Howtomechatronics.com

Methodology

First, connect the motion sensor to your Magicbit and upload the following code to your Magicbit. In this demonstration, like other demonstrations, we use D32 as the data pin.

Code

 

from machine import Pin
import time

motion_sens = Pin(32, Pin.IN)

while True:
   print(motion_sens.value())
   time.sleep_ms(1000)

Explanation

When some human being is detected by the motion sensor, which is in the range of the sensor, the output of the serial monitor, will be displayed ‘1’. If not there will be displayed ‘0’.

Related Posts
Leave a Reply