Skip to content

Instantly share code, notes, and snippets.

@elktros
Last active October 11, 2018 10:34
Show Gist options
  • Save elktros/bc02bbe50732191438ebad55c88f792a to your computer and use it in GitHub Desktop.
Save elktros/bc02bbe50732191438ebad55c88f792a to your computer and use it in GitHub Desktop.
Arduino Code for Automatic Room Lights using Arduino and PIR Sensor Project.
int in1 = 9;
int sensor = 8;
int led = 13;
unsigned long t=0;
void setup()
{
Serial.begin(9600);
pinMode(in1, OUTPUT);
pinMode(sensor, INPUT);
pinMode(led, OUTPUT);
digitalWrite(in1,HIGH);
digitalWrite(led,LOW);
while(millis()<13000)
{
digitalWrite(led,HIGH);
delay(50);
digitalWrite(led,LOW);
delay(50);
}
digitalWrite(led,LOW);
}
void loop()
{
digitalWrite(in1,HIGH);
digitalWrite(led,LOW);
if(digitalRead(sensor)==HIGH)
{
t=millis();
while(millis()<(t+5000))
{
digitalWrite(in1,LOW);
digitalWrite(led,HIGH);
if((millis()>(t+2300))&&(digitalRead(sensor)==HIGH))
{
t=millis();
}
}
}
}
@sushamakhatavkar
Copy link

is this code 100% correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment