Hi, I'm an artist who is not too great at programming, I would really appreciate your advice.
I'm just trying to make a continuous rotation servo go when the light shines bright on a photocell, and turn off when the light is dim. I tried this program below which I googled:
What it does with a continuous rotation servo is make it go forward when the light is dim, and go backwards when the light is bright. I've been following lady adas tutorials on photosensors and have an idea of the range I'm wanting to target: it should be 700 to 1023 when the servo rotates. Anything dimmer than that it should just be off.
#include <Servo.h> // include the servo library
Servo servoMotor; // creates an instance of the servo object to control a servo
int analogPin = 0; // the analog pin that the sensor is on
int analogValue = 0; // the value returned from the analog sensor
int servoPin = 9; // Control pin for servo motor. As of Arduino 0017, can be any pin
void setup() {
servoMotor.attach(servoPin); // attaches the servo on pin 2 to the servo object
}
void loop()
{
analogValue = analogRead(analogPin); // read the analog input (value between 0 and 1023)
analogValue = map(analogValue, 0, 1023, 0, 179); // map the analog value (0 - 1023) to the angle of the servo (0 - 179)
servoMotor.write(analogValue); // write the new mapped analog value to set the position of the servo
delay(15); // waits for the servo to get there
}