Moduł czujnika ruchu PIR na podczerwień HC-SR501 do Arduino i
| Pin | Sygnał | Opis |
|---|---|---|
VCC |
power | Power input for the PIR module, typically 5V DC to the onboard regulator. |
OUT |
digital | Digital motion output; goes high when PIR motion is detected. |
GND |
ground | Ground reference for power and the OUT signal. |
| Z | Do | Przewód |
|---|---|---|
board:5V |
x1:VCC |
red |
board:GND |
x1:GND |
black |
board:D2 |
x1:OUT |
green |
Ten przykład został napisany i sprawdzony kompilacją dla arduino-uno. Codey Online dostosuje go do każdej innej obsługiwanej płytki.
// HC-SR501 PIR Motion Sensor
// Reads the PIR motion output and prints when motion is detected.
const int pirPin = 2;
void setup() {
pinMode(pirPin, INPUT);
Serial.begin(9600);
while (!Serial) {
;
}
Serial.println("HC-SR501 PIR motion sensor ready");
}
void loop() {
int motionState = digitalRead(pirPin);
if (motionState == HIGH) {
Serial.println("Motion detected!");
} else {
Serial.println("No motion");
}
delay(500);
}
Opisz, co chcesz zbudować. Codey Online napisze kod, narysuje schemat połączeń, skompiluje projekt i wgra go na płytkę bezpośrednio z przeglądarki.
Zacznij za darmo