Last active
March 21, 2016 20:47
-
-
Save j6k4m8/5700158bc23949cb3b5e to your computer and use it in GitHub Desktop.
LED Photoresistor Arduino Read
This file contains 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
/* CHEMICAL CAR: ARDUINO SKETCH | |
* You shouldn't have to change anything below the define lines. | |
* Contact Jordan ([email protected]) with questions. | |
*/ | |
#define MOTOR 7 | |
#define SENSOR A0 | |
#define LED13 13 | |
#define DELAY 5000 | |
// Don't change code below this line! | |
int BASELINE = 0; | |
void setup() { | |
delay(5000); | |
pinMode(MOTOR, OUTPUT); | |
pinMode(LED13, OUTPUT); | |
digitalWrite(MOTOR, HIGH); | |
BASELINE = analogRead(SENSOR); | |
Serial.begin(9600); | |
} | |
void loop() { | |
int r = analogRead(SENSOR); | |
if (r > (BASELINE + 50)) { | |
digitalWrite(MOTOR, LOW); | |
Serial.println(r); | |
digitalWrite(LED13, HIGH); | |
} else { | |
digitalWrite(LED13, LOW); | |
digitalWrite(MOTOR, HIGH); | |
Serial.println(r); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment