Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Things you need: arduino board, PIR motion sensor module (HC-SR501)
- const int motionSensorPin = 2;
- const int outputPin = 13;
- void setup() {
- pinMode(outputPin, OUTPUT);
- pinMode(motionSensorPin, INPUT);
- Serial.begin(9600);
- }
- void loop() {
- int motionState = digitalRead(motionSensorPin);
- if (motionState == HIGH) {
- digitalWrite(outputPin, HIGH);
- Serial.println("Motion detected!");
- } else {
- digitalWrite(outputPin, LOW);
- Serial.println("No motion detected.");
- }
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement