Help with Code?

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?


Servo myservo;

int pos = 0;

void setup() {




void loop() {

int sensorValue = analogRead(A0);



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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s