This circuit is part of a target game using a servo and a light sensor. Flashing the sensor with a flashlight or laser will triggers the target to fall.
--------------------------- Copy Code Below
#include <Servo.h>
int sensorPin = A0;
int sensorValue;
Servo myservo; //Create and instance of the Servo object
void setup()
{
myservo.attach(9); //Use pin 9 for servo control
}
void loop()
{
sensorValue = analogRead(sensorPin);
if (sensorValue < 500)
{
myservo.write(180); //instruct servo to turn 180 degrees
delay(15);
}
else
{
myservo.write(90);
delay(2000);
}
}
int sensorPin = A0;
int sensorValue;
Servo myservo; //Create and instance of the Servo object
void setup()
{
myservo.attach(9); //Use pin 9 for servo control
}
void loop()
{
sensorValue = analogRead(sensorPin);
if (sensorValue < 500)
{
myservo.write(180); //instruct servo to turn 180 degrees
delay(15);
}
else
{
myservo.write(90);
delay(2000);
}
}