Skip to content

Instantly share code, notes, and snippets.

@JHeld07
Created January 12, 2016 15:02
Show Gist options
  • Save JHeld07/a9fd9c1f99f2d346346c to your computer and use it in GitHub Desktop.
Save JHeld07/a9fd9c1f99f2d346346c to your computer and use it in GitHub Desktop.
Light Sensor
int State=0;
void setup() {
pinMode(5,OUTPUT); // Set Digital pin 5 to output
}
void loop() {
int sensorValue = analogRead(A0); // Read analog value off of photoresistor
float voltage = sensorValue * (5.0 / 1023.0); // Calculate voltage with a resolution of 1023
if(voltage<3){ //not recording
if (State==0){
digitalWrite(5,HIGH); // Toggle record state
delay(50);
digitalWrite(5,LOW);
State=1;
}
}
if (voltage>3){ // recording
if (State==1){
digitalWrite(5,HIGH); // Toggle record state
delay(50);
digitalWrite(5,LOW);
State=0;
}
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment