Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
F. Yao
Published © Apache-2.0

KEMET PIR Lock

KEMET PIR Lock

IntermediateWork in progressOver 1 day556
KEMET PIR Lock

Things used in this project

Story

Read more

Schematics

KEMET PIR Lock wire

KEMET PIR Lock wiring

Code

KEMET PIR Lock

C/C++
KEMET PIR Lock
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

// constants won't change. They're used here to set pin numbers:
const int PIR_kemet = 2;     // the number of the pushbutton pin
const int ledPin =  LED_BUILTIN;      // the number of the LED pin

// variables will change:
int PIR_State = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(PIR_kemet, INPUT);

  myservo.attach(9); 
  myservo.write(pos);  
  delay(15); 
}

void loop() {
  // read the state of the pushbutton value:
  PIR_State = digitalRead(PIR_kemet);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (PIR_State == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
    pos=120;
  } else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
    pos=60;
  }

  myservo.write(pos);  
  delay(60); 
}

Credits

F. Yao

F. Yao

18 projects • 13 followers
.

Comments