// a sketch to read the light sensor directly wired into the arduino #include // include the library necessary to run the servo Servo myservo; // create a servo object int pos = 0; // initialise the position to zero int lightPin = A0; // set the analog input pin for the light sensor int lightLevel; // a variable to store the light level measurement #define lightCritical 1000 // a level that worked this evening. Will need later adjustment void setup() { myservo.attach(9); // set up communication with the servo on Pin 9 pinMode(13,OUTPUT); // set up the onboard LED to provide some visual feedback Serial.begin(9600); // set up a light level monitor to allow lightCritical to be tuned } void loop() { lightLevel = analogRead(lightPin); // read the light sensor Serial.println(lightLevel); // output to computer if (lightLevel > lightCritical) { digitalWrite(13,HIGH); // turn on LED myservo.write(90); // rotate servo 90 degrees delay(100); // wait for servo to reach max angle } else { digitalWrite(13,LOW); // turn off LED myservo.write(0); // rotate servo to zero delay(100); // wait for servo to reach zero } }