Skip to content

Instantly share code, notes, and snippets.

@helloCaller
Created January 27, 2016 16:52
Show Gist options
  • Save helloCaller/93a5862b170d0ba93f25 to your computer and use it in GitHub Desktop.
Save helloCaller/93a5862b170d0ba93f25 to your computer and use it in GitHub Desktop.
Arduino, change brightness with photoresistor
/*
Brighness Changer Part 2
Change Brightness of an LED with photoresistor
Adapted by Luke Garwood after example 5-4 from Getting Started With Arduino by Massimo Banzi and Michael Shiloh
*/
int LEDPIN = 9; //Setting up pin 9 to control the LED
int LightSensorValue = 0; //Setting up variable to hold values coming from light sensor
void setup() {
pinMode(LEDPIN, OUTPUT); //making pin 9 an output
}
void loop() {
LightSensorValue = analogRead(1); //reading analog values from sensor on pin A1
analogWrite(LEDPIN, LightSensorValue/1.5); // setting the brightness of LED in relation to the value of the sensor divided by 1.5
delay(10); // delay for best results
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment