Hi all!
I'm trying to build a lamp which would move(lighting shade part)
by servor when motion is detected. and also the lighting which would be
LED ring will run, deem in and out when motion is detected.
So it is basically, PIR sensor detects -> runs Servor and LED that deems in and out.
so far below is what I have, and it would be really nice if I could get some reference or
help on integrating LED ring parts(code) into this codes.
Great Thanks always. I'm really enjoying this arduino life:)
#include <Servo.h>
Servo myservo; //creates a servo object
//a maximum of eight servo objects can be created
int pos = 0; //variable to store servo position
//amount of time we give the sensor to calibrate(10-60 secs according to the datasheet)
int calibrationTime = 30;
int pirPin = 12; //digital pin connected to the PIR's output
int pirPos = 13; //connects to the PIR's 5V pin
void setup(){
myservo.attach(9); //attaches servo to pin 4
Serial.begin(9600); //begins serial communication
pinMode(pirPin, INPUT);
pinMode(pirPos, OUTPUT);
digitalWrite(pirPos, HIGH);
//give the sensor time to calibrate
Serial.println("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(calibrationTime - i);
Serial.print("-");
delay(1000);
}
Serial.println();
Serial.println("done");
while (digitalRead(pirPin) == HIGH) {
delay(500);
Serial.print(".");
}
Serial.print("SENSOR ACTIVE");
}
void loop(){
if(digitalRead(pirPin) == HIGH){ //if the PIR output is HIGH, turn servo
for(pos = 0; pos < 170; pos += 1) //goes from 0 to 180 degrees
{ //in steps of one degree
myservo.write(pos); //tells servo to go to position in variable "pos"
delay(50); //waits for the servo to reach the position
}
}
if(digitalRead(pirPin) == LOW){
for(pos = 170; pos >= 90; pos -= 1){
myservo.write(pos);
delay(50);
}
}
}