daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Feb 18th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. int led = 13;                
  4. int sensor = 2;              
  5. int state = LOW;            
  6. int val = 0;
  7. (value)                
  8.  
  9. void setup() {
  10.   pinMode(led, OUTPUT);      
  11.   pinMode(sensor, INPUT);    
  12.   Serial.begin(9600);        
  13. }
  14.  
  15. void loop(){
  16.   val = digitalRead(sensor);  
  17.   if (val == HIGH) {          
  18.     digitalWrite(led, HIGH);  
  19.     delay(100);                
  20.    
  21.     if (state == LOW) {
  22.       Serial.println("Motion detected!");
  23.       state = HIGH;      
  24.     }
  25.   }
  26.   else {
  27.       digitalWrite(led, LOW);
  28.       delay(200);            
  29.      
  30.       if (state == HIGH){
  31.         Serial.println("Motion stopped!");
  32.         state = LOW;      
  33.     }
  34.   }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top