Created
July 17, 2014 18:42
-
-
Save efatsi/2e8c3375ecd9d0190349 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int led = 9; | |
int relay = 2; | |
int sensor = A0; | |
int sensorValue; | |
boolean occupied = false; | |
void setup() { | |
pinMode(led, OUTPUT); | |
pinMode(relay, OUTPUT); | |
Serial.begin(9600); | |
digitalWrite(led, LOW); | |
digitalWrite(relay, LOW); | |
} | |
void loop() { | |
sensorValue = analogRead(sensor); | |
Serial.println(sensorValue); | |
if (sensorValue < 400) { | |
digitalWrite(led, HIGH); | |
digitalWrite(relay, HIGH); | |
if (!occupied) { | |
delay(3000); | |
occupied = true; | |
} | |
} | |
else { | |
digitalWrite(led, LOW); | |
digitalWrite(relay, LOW); | |
if (occupied) { | |
delay(3000); | |
occupied = false; | |
} | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment