PIR Sensor

From Sketching with Hardware at LMU Wiki
Revision as of 20:28, 29 August 2020 by Skwhadmin (talk | contribs) (Created page with "= Description = A PIR Sensor can detect motion, it is also called motion sensor. It detect moveing people or animals. PIR stands for passive infrared. It has 3 connectors: *...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Description

A PIR Sensor can detect motion, it is also called motion sensor. It detect moveing people or animals. PIR stands for passive infrared.

It has 3 connectors:

  • + connected to GND
  • - connected to 3.3V
  • Out - digital output is 1 if motion is detected

Pir3.PNG

How to connect it electrically

Joystick-electro.JPG


How to control it in MicroPython

Reading the value and printing it to the console

 1 #Example usage for ESP32
 2 from machine import Pin
 3 from time import sleep
 4 # digital input on pin 26
 5 pir = Pin(26, Pin.IN, Pin.PULL_UP) # enable internal pull-up resistor
 6 
 7 while True:
 8   pirVal = pir.value()
 9   print(pirVal)
10   sleep(1)

Related Tutorial Videos