Created
May 2, 2016 15:06
-
-
Save ViliusKraujutis/bba9e5f5830275be2bcdd43e4a0f05b9 to your computer and use it in GitHub Desktop.
Attached PIR sensor to Arduino, so it could adjust power 12V ~18W LED lamp sticker-strip under kitchen's cupboards. Just a simple, although interesting project combining electronics, automation and programming.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int relayPin = 3; | |
int pirPin = 2; | |
int ledPin = 13; // just a LED on Arduino board. Not that huge ~18W LED lamp. | |
long lastDetection = 0; // millis | |
long DELAY = 3 * 1000; // N seconds (also adjustable at PIR sensor too) | |
void setup() { | |
pinMode(relayPin, OUTPUT); | |
pinMode(pirPin, INPUT); | |
pinMode(ledPin, OUTPUT); | |
} | |
void loop() { | |
int pirValue = digitalRead(pirPin); | |
if (pirValue == HIGH) { | |
lastDetection = millis(); | |
Serial.println("Moved: " + lastDetection); | |
} | |
if (lastDetection + DELAY > millis()) { | |
digitalWrite(relayPin, LOW); // Switch relay, so it would turn on LED strip | |
digitalWrite(ledPin, HIGH); // Also turn on indicator LED added to Arduino board | |
} else { | |
digitalWrite(relayPin, HIGH); | |
digitalWrite(ledPin, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment