simple photo resistor controlled servo

SO , I’m working on this kinetic sculpture and to drive the clockwork based on the lighting i’m using arduino. I’m using a photo resistor and reading the ambient light value off of analog pin A0 and using a geared motor that is sold as a continuous rotation servo ( 0=anticlockwise rot, 90=stop, 180=clockwise rot). When I run the motor through inputs via processing (by uploading firmata on a mega board), things run smoothly. But when I try to upload the code onto the board itself so I can run it independent of my laptop, the motor doesn’t seem to respond. I opened the serial monitor and the resistance values seem to be coming in smoothly. Here is my code, can anyone figure out why this might be happening?
It should be straight forward and simple but I can’t see what’s going wrong, i checked the wiring, power supply, everything I could think of.

#include <Servo.h>

Servo servo;

void setup()
{
Serial.begin (9600);
servo.attach(8);
}

void loop()

{
float pres = analogRead(A0);
Serial.println(pres);
if (pres < 140)
{ servo.write(90);
}
else if (pres > 140 && pres < 300)
{ servo.write(180);
}
else if (pres > 300)
{ servo.write(0);
}
delay(2000);
}

I’m not sure if it will make any difference but this line

float pres = analogRead(A0);

should be

int pres = analogRead(A0);

because analogRead() returns an integer value.

Does the motor move if you add this line as the last thing in setup()

servo.write(110);

Please post the code that does work.

For the future please post your program using the code button </>.

…R

Yes! It works now, thank you very much.
Oh, okay, I will use the </> from now on! :slight_smile: