/************************************
name:Photoresistor
function: if you shine the photoresistor with a certain light intensity, you will see several LEDs light up.
If you increase the light intensity, you will see more LEDs light up.
When you place it in dark environment, all the LEDs will go out.
*********************************************/
//Email: [email protected]
//Website: www.sunfounder.com
const int photocellPin = A0; //photoresistor attach to A0
int sensorValue = 0; // value read from the sensor
int ledLevel = 0; // sensor value converted into LED 'bars'
const int motorIn1 = 9;
const int motorIn2 = 10;
void setup()
{
Serial.begin(9600);
pinMode(motorIn1,OUTPUT);
pinMode(motorIn2,OUTPUT);
}
void loop()
{
sensorValue = analogRead(photocellPin);
ledLevel = map(sensorValue, 0, 1023, 0, 250);
analogWrite(motorIn2,ledLevel);
}