Skip to content

Instantly share code, notes, and snippets.

@j6k4m8
Last active March 21, 2016 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j6k4m8/5700158bc23949cb3b5e to your computer and use it in GitHub Desktop.
Save j6k4m8/5700158bc23949cb3b5e to your computer and use it in GitHub Desktop.
LED Photoresistor Arduino Read
/* CHEMICAL CAR: ARDUINO SKETCH
* You shouldn't have to change anything below the define lines.
* Contact Jordan (jm@jhu.edu) 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