Photoresistor project

`int sensorValue = 0;

void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);

pinMode(9, OUTPUT);
}

void loop()
{
// read the value from the sensor
sensorValue = analogRead(A0);
// print the sensor reading so you know its range
Serial.println(sensorValue);
// map the sensor reading to a range for the LED
analogWrite(9, map(sensorValue, 0, 1023, 255, 0));
delay(100); // Wait for 100 millisecond(s)
}

1 Like