Codey OnlineBiblioteca de componentes Arduino y ESP32 › PIR Sensor HC-SR501
PIR Sensor HC-SR501
Sensores

PIR Sensor HC-SR501

El sensor PIR HC-SR501 detecta cambios en la radiación infrarroja (IR) causados por el movimiento, normalmente de personas o animales. Proporciona una señal de salida digital (OUT) apta para lectura directa por microcontroladores como Arduino o ESP32, usando los pines estándar de alimentación y tierra (VCC y GND).

Ancho: 33.1 mm

Pinout — PIR Sensor HC-SR501

Pin Señal Descripción
GND GND Ground
OUT digital out
VCC VCC Power positive

Esquema de cableado de ejemplo — PIR Sensor HC-SR501

Desde Hasta Cable
board:5V x1:VCC red
board:GND x1:GND black
board:D2 x1:OUT green

Código Arduino de ejemplo — PIR Sensor HC-SR501

Este ejemplo se escribió y verificó por compilación para arduino-uno. Codey Online lo adapta a cualquier otra placa compatible.

// PIR Sensor HC-SR501 - canonical beginner example
// Reads the sensor output on D2 and prints motion status to Serial Monitor.

const int pirPin = 2;

void setup() {
  pinMode(pirPin, INPUT);
  Serial.begin(9600);
  while (!Serial) {
    ;
  }
  Serial.println("PIR sensor warming up... give it about 30-60 seconds.");
}

void loop() {
  int motion = digitalRead(pirPin);

  if (motion == HIGH) {
    Serial.println("Motion detected!");
  } else {
    Serial.println("No motion.");
  }

  delay(500);
}

Componentes relacionados

18650 Battery Shield with USB-C Charger and 5V Boost Converter

18650 Battery Shield with USB-C Charger and 5V Boost Converter

2.4 inch OLED Display I2C 3.3V

2.4 inch OLED Display I2C 3.3V

3.5 inch TFT LCD Shield

3.5 inch TFT LCD Shield

50kg Load Cell Weight Sensor

50kg Load Cell Weight Sensor

Crea tu proyecto de Arduino o ESP32 con IA

Describe lo que quieres construir. Codey Online escribe el codigo, dibuja el esquema de conexiones, lo compila y graba tu placa directamente desde el navegador.

Empieza gratis