Een Mini PIR (passieve infraroodsensor) detecteert veranderingen in infrarode straling door beweging in de buurt. Voed hem via VCC (2,7V tot 12V) met GND aan massa, en gebruik de enkele OUT-signaallijn (ongeveer 3V) als digitale ingang op Arduino/ESP32.
| Pin | Signaal | Beschrijving |
|---|---|---|
VCC |
2.7V - 12V power | |
OUT |
3V signal | |
GND |
ground |
| Van | Naar | Draad |
|---|---|---|
board:5V |
x1:VCC |
red |
board:GND |
x1:GND |
black |
board:D2 |
x1:OUT |
green |
Dit voorbeeld is geschreven en compile-gecheckt voor de arduino-uno. Codey Online past het voor je aan naar elk ander ondersteund board.
const int pirPin = 2;
void setup() {
pinMode(pirPin, INPUT);
Serial.begin(9600);
while (!Serial) {
;
}
Serial.println("Mini PIR sensor example");
Serial.println("Warming up the PIR sensor for calibration...");
delay(30000);
Serial.println("Ready. Move in front of the sensor.");
}
void loop() {
int motionState = digitalRead(pirPin);
if (motionState == HIGH) {
Serial.println("Motion detected");
} else {
Serial.println("No motion");
}
delay(500);
}
Beschrijf wat je wilt bouwen. Codey Online schrijft de code, tekent het aansluitschema, compileert het en flasht je board rechtstreeks vanuit de browser.
Gratis starten