This example is for Wiring version 0027+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.
Reading a light sensor and set an LED intensity accordingly by BARRAGAN
Reads values from a photoresistor connected to the analog input pin 0. The value read from the sensor is proportional to the ambient light. The value is used to set the LED brightness to more ambient light less LED brightness.
Reads values from a photoresistor connected to the analog input pin 0. The value read from the sensor is proportional to the ambient light. The value is used to set the LED brightness to more ambient light less LED brightness.

int sensorValue; void setup() { pinMode(37, OUTPUT); } void loop() { sensorValue = analogRead(0); // read analog input pin 0 (value in the range 0-1023) // The luminosity of the LED will be proportional to te amount of light in the environment. // analogWrite(37, sensorValue); // write the value to PWM output pin 0 (value in the range 0-1023) // if you want the luminosity of the LED to be inversely proportional to the amount of // of light in the environment comment the previous line and use the line below instead: analogWrite(37, 1023-sensorValue); delay(100); // wait 100ms for next reading }