Data saved to microSD card and charted in Excel
The Arduino code to monitor the PIR and fade in an LED if motion is detected.
int LED = 11;
int sensor = 7;
int n = 0;
int light = 0;
void setup()
{
pinMode(LED, OUTPUT);
pinMode(sensor, INPUT);
digitalWrite(LED, LOW);
delay(1000);
}
void loop()
{
int sens = digitalRead(sensor);
if(sens == LOW)
{
for(n=0; n<255; n++)
{
analogWrite(LED, n);
delay(10);
}
light = 1;
}
if (light == 1)
{
if (sens == HIGH)
{
for(n=255; n>-1; n--)
{
analogWrite(LED, n);
delay(10);
}
light = 0;
}
}
}
|
No comments:
Post a Comment