#include <Servo.h> //includes servo library of instructions
Servo myservo; // create servo object to control a servo
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
myservo.write(0); // sets the servo position
delay(1000); // waits for the servo to get there
myservo.write(30); // sets the servo position
delay(1000); // waits for the servo to get there
myservo.write(90); // sets the servo position
delay(1000); // waits for the servo to get there
myservo.write(120); // sets the servo position
delay(1000); // waits for the servo to get there
myservo.write(160); // sets the servo position
delay(1000); // waits for the servo to get there
myservo.write(180); // sets the servo position
delay(1000); // waits for the servo to get there
}
Challenge: Create a system with the servo motor and the light sensor. Attach a small piece of cardboard to the moving portion of the servo so that it acts like an umbrella to create shade over the light sensor. Move the servo to new positions, each time it goes to a new position measure the light intensity. If it detects shadow stop the servo. If it detects light move the servo to the next position. Then it will keep moving to create shade where the light sensor is.