Bestilt før kl. 14.00 på hverdage = afsendt samme dag 30 dages fortrydelsesret 1 års garanti
← Terug til oversigten

Ved afspilning indlæses videoen fra YouTube.

Tilslutningsdiagram og kodeeksempel

Sådan tilslutter du PIR Sensor HC-SR501 Bevægelsessensor til en Arduino UNO eller ESP32, med en eksempelsketch, du kan uploade med det samme.

HC-SR501 bevægelsesdetektion med Arduino Uno

Dette projekt registrerer menneskelig bevægelse ved hjælp af HC-SR501 PIR-sensoren. Når der registreres bevægelse, går sensorens output pin til HIGH, hvilket tænder den onboard LED og udskriver en advarsel til Serial Monitor. Åbn Serial Monitor ved 115200 baud for at se bevægelsesstatus i realtid.

Tilslutningsdiagram: PIR Sensor HC-SR501 Bevægelsessensor på en Arduino UNO
Tilslutningsdiagram · Klik for at forstørre
Tilslutningstabel: PIR Sensor HC-SR501 Bevægelsessensor på en Arduino UNO
Tilslutningstabel · Klik for at forstørre
HC_SR501_Motion_Detection_with_Arduino_U.ino · kompileret og testet
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : HC-SR501 Motion Detection with Arduino Uno
 *  Board     : Arduino UNO (arduino:avr:uno)
 *  Parts     : HC-SR501 PIR Motion Sensor
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

// HC-SR501 PIR Motion Sensor Demo

const int PIR_PIN = 2;
const int LED_PIN = 13;

int lastState = LOW;

void setup() {
  pinMode(PIR_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  
  Serial.begin(115200);
  Serial.println(F("HC-SR501 PIR Motion Sensor Initialized"));
  Serial.println(F("Warming up sensor (approx. 30-60 seconds)..."));
}

void loop() {
  int motionState = digitalRead(PIR_PIN);

  if (motionState != lastState) {
    if (motionState == HIGH) {
      digitalWrite(LED_PIN, HIGH);
      Serial.println(F("Motion detected!"));
    } else {
      digitalWrite(LED_PIN, LOW);
      Serial.println(F("Motion ended."));
    }
    lastState = motionState;
  }

  delay(100);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

Bevægelsesdetektion med HC-SR501 og ESP32

Dette projekt registrerer bevægelse ved hjælp af en HC-SR501 PIR-sensor. Sensoren forsynes fra 5V VIN-pin, og en spændingsdeler med 1kΩ/2kΩ modstande forbinder sikkert sensorens udgang med ESP32'ens 3.3V-indgang. Når der registreres bevægelse, lyser onboard LED, og der sendes en besked til Serial Monitor.

Tilslutningsdiagram: PIR Sensor HC-SR501 Bevægelsessensor på en ESP32 DevKit V1
Tilslutningsdiagram · Klik for at forstørre
Tilslutningstabel: PIR Sensor HC-SR501 Bevægelsessensor på en ESP32 DevKit V1
Tilslutningstabel · Klik for at forstørre
Motion_Detection_with_HC_SR501_and_ESP32.ino · kompileret og testet
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : Motion Detection with HC-SR501 and ESP32
 *  Board     : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
 *  Parts     : HC-SR501 PIR Motion Sensor
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

// HC-SR501 PIR Motion Sensor Demo
const int PIR_PIN = 13;      // Connected to HC-SR501 OUT via divider
const int LED_PIN = 2;       // Onboard LED

int lastState = LOW;

void setup() {
  Serial.begin(115200);
  pinMode(PIR_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  
  Serial.println("HC-SR501 Sensor warming up (approx. 30-60s)...");
  delay(2000);
  Serial.println("Ready to detect motion.");
}

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

  if (motion != lastState) {
    if (motion == HIGH) {
      digitalWrite(LED_PIN, HIGH);
      Serial.println("Motion detected!");
    } else {
      digitalWrite(LED_PIN, LOW);
      Serial.println("Motion ended.");
    }
    lastState = motion;
  }

  delay(50);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

Set for nylig

Servo MG995 360 grader

Servo MG995 360 grader

€ 9,35
MAX6675 Modul + K Type Termokobler Sensor

MAX6675 Modul + K Type Termokobler Sensor

€ 5,70