servo motor stop at some angles

Hi guys I got my servo motor to stop at some angles based on the detection of my light sensor, but the problem is that one it gets to the desired angle it doesn't stop completely instead it just slow down . I want it to fully stop once it gets to the desired angle any help please ! maybe a code or something to make the servo motor to stop ! or it will never stop since the motor is all the time connecting to the power pin in the arduino board ?

Thanks guys any help will be appreciated

How to use this forum

Your code, please?

Is this a normal servo or a continuous rotation servo ?

Hi Nick here is what I have

int anlogPin = 0 int analoValaue = 0 int servoPin = 2

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, 540, 680, 0, 179); // map the analog value (540-680) to the servo angle (0-179) servoMotor.write(analogValue);

am not sure what typs of motor all i know is that it's a servo motor

Where is the rest of your code ?

With the right code your servo will stop but only if the light does not change. Have you tried monitoring the value from the light sensor using Serial.print() ?

It looks like you have a normal servo, or at least the code is expecting one. Can it move through 360 degrees or does it stop at 180 if you turn it by hand ?

Thanks UKHeliBob It just rotates to 360 deg I dont really have the knowledge of coding but I want to learn it :(

Hi Nick here is what I have

int anlogPin = 0 int analoValaue = 0 int servoPin = 2

OK, now post your code, not what you think code should look like.

If the servo can turn through 360 degrees it is almost certainly designed for continuous rotation. Can you keep turning it past 360 degrees with no stop ? If you can then it is a continuous rotation servo and the value sent by servoMotor.write() sets the speed of the servo, not the angle to go to unlike a conventional servo.

UKHeliBob thanks for helping me ! once I cover the light sensor it stops at and once I move my hand away it keeps rotating 360 deg so yes its a continuous rotation :~ so your saying that I should get a conventional servomotor instead so in that case the servomotor would stop at the desired angle then it will loves once it detect different light intensity ? any clarification sir ?

A conventional servo would move to the position set by servoMotor.write() but it would still move if the light level changed. You would need to determine the range of values from the light sensor to use in the map() function so that the servo movement matches the light level.

If you want the servo to stay in one position when the light is above or below a certain value or in a certain range then you need to take a different approach.

so your saying that I should get a conventional servomotor instead so in that case the servomotor would stop at the desired angle then

As long as the desired angle is 0-180 degrees (sail winch servos can make several turns).

I really appreciate all the help guys i used analogValue = map(analogValue, 255, 680, 0, 179) ; 255 to 680 that's the light intensity detected by the sensor and 0 to 179 is the range of the angle servoMotor.write(analogValue);this one am nost sure what should i specify in it

but the servo motor i have which my friend used it for a small robot keeps rotating 360 deg even though the code says from 0 -180 deg , Im not sure if am using the wrong motor that for this code or something ?

Yes, use a conventional servo rather than a continuous rotation one which is what you have now.

UKHeliBob thanks for all the helps