output a value to position servo

Hey guys

I am attempting to solve a programming qn: It says to: 'output a value( calling the variable of the value, 'servoPosition') to a position servo connected to the digital pin 11 of the arduino'

I have 3 doubts:

  1. confused as to what the phrase 'output a value to a position servo' means. What value is this referring to?

  2. what is the function needed to be used? I am thinking servo.write(), but when i used this function, i see nothing in the serial monitor, so im guessing there is no 'output'?

  3. is a 'position servo' the same thing as a 'servo'? meaning motor?

Thanks a bunch.

You need to post your program.

servo1.write() will send data to the servo to cause it to move to the required position. It does not send data to the Serial Monitor. You use Serial.print() for that.

...R

Thanks for the reply! :-)

ohh i see... so to 'output a value to the position servo' doesn't mean output the value to the serial monitor, but it just means provide some data to the servo, to make it move to a certain position? Is that right?

Probably. That would certainly be it if the question said "output a value to position a servo...". Are you sure you copied it correctly ?

Steve

hmmm the question actually says 'to a position servo'.. maybe its a typo in the qn itself, and its supposed to be 'position a servo', i think? Then it makes sense. Thank you!

Just wondering, what does the 'value' refer to? Which value are we trying to output to the servo? Does it refer to the angle?

If you choose to use servo.write() then yes it will be the angle. If you choose to use servo.writeMicroseconds() then it will be a number of microseconds.

preethi16: ohh i see... so to 'output a value to the position servo' doesn't mean output the value to the serial monitor, but it just means provide some data to the servo, to make it move to a certain position? Is that right?

may be

preethi16: 3. is a 'position servo' the same thing as a 'servo'? meaning motor?

i understand what is that you are asking

This is the code ive got. However, after compiling it and uploading it, the servo does not even move. What is wrong with this code?

#include <Servo.h>
Servo servo1; // servo control object

int servoPosition = 90;

void setup()
{

servo1.attach(11); //Connect the servo to pin 11
//with a minimum pulse width of
//900 and a maximum pulse width of
//2100.

}

void loop()
{

/* To control a servo, give it the angle you’d like it
to turn to. Servos cannot turn a full 360 degrees, but
can tell it to move anywhere between 0 and 180 degrees. */

// Change position at full speed:

/* Assign variable ‘servoPosition’ value of the angle which
provides data/command to servo, to be oriented in a certain
way */

servo1.write(servoPosition); // Tell servo to go to 90 degrees

delay(1000); // Pause to get it time to move
}

Thanks for the clarification.

Well if the servo is already centred it won't move. Try setting servoPosition to 0 or 180 and see what happens. Or even better move it to 90 first, delay, then move it to another position.

Of course that's all assuming the servo is correctly connected. What servo is it and how connected ? It's generally a bad idea to take servo power directly from the Arduino though you can get away with it for single small servo.

Steve

..or try the sweep example in the IDE.

But whatever, always remember to use code tags when posting code.

just set it to 0 and it works! Thanks heaps!

But just wondering, now that ive answered the qn which says to give output to the servo to position it(which i think my code did?), by turning it by 90 degrees, then how do i make it stop?

Because the qn just says to give A value to position the servo (in my case, the value of the angle was 90 degrees). But then, the servo continues to make this vibrating sound, meaning it is continuing the loop. So, how to make this whole thing stop after it rotates by 90 degrees?

Just want to make sure ive actually answered the question correctly.

Thanks again.

Just want to make sure ive actually answered the question correctly.

Why not ask your instructor/supervisor/professor?

Oh i dont have 1, this was just from a friend and we were all stuck in this qn. Just wondering how to stop the loop because now that ive already got the rotation working, and since it just rotates once, doesnt make sense to continue in the loop, does it? Just wanted to know if this can be stopped.

If you don't want it to repeat, put the code in setup()

Oh ok... So no need to include the void loop in the code at all? So it just needs to have a void setup?

You've got five minutes between posting - why don't you try it before posting?