Hi, I'm using an Arduino uno with a servo motor and phototransistor. Essentially, when the room goes dark, I want the servo motor to rotate 180 degrees. Using some of the example codes, I formed my own code. For some reason this doesn't work. Any suggestions?
#include<Servo.h>
Servo myservo;
int pos = 0;
void setup() {
myservo.attach(0);
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
delay(1);
if (sensorValue < 450){
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
}
Touch here for the full post on the Arduino Apprentices tumblr