using LDR analog reading

I have been trying to get the reading of an analog read ldr to control a motor. Basically if the LDR reading is less than a pre set maximum light value(say 150) then I want to be able to set my motor to a certain speed.

So far i am able to read LDR values from an analog pin and am able to set the motor to varying speeds.

I thought by using a basic if(LDRvalue < light_max){
motor.writeMicroseconds(1000); } i would be able to solve the problem, but this doesnt seem to be working. I have even tried setting flags to see if the adruino even recognizes that the LDRvalue is falling below light max, but this has failed.

I really cant see what the problem is.. any advice?

rohankuriakose:
I have been trying to get the reading of an analog read ldr to control a motor. Basically if the LDR reading is less than a pre set maximum light value(say 150) then I want to be able to set my motor to a certain speed.

So far i am able to read LDR values from an analog pin and am able to set the motor to varying speeds.

I thought by using a basic if(LDRvalue < light_max){
motor.writeMicroseconds(1000); } i would be able to solve the problem, but this doesnt seem to be working. I have even tried setting flags to see if the adruino even recognizes that the LDRvalue is falling below light max, but this has failed.

I really cant see what the problem is.. any advice?

What is LDR reading? LDRvalue?

What Arduino are you using?

Post your code, put your code between the </> code tags. It is easier to read that way.

Chuck.

P.S. if I said 42 was the answer would it mean anything to you?

In a first step ignore the motor, and only light a LED to indicate light (LDR readings) below/above the threshold. Then add the motor, and watch whether it turns according to the state of the LED.