Servo Motor Code

Hi,

I am new to C++ language and I need someones advice, please and thank you.

• We require the code for Arduino to tell the Arduino to the PWN 180 Degrees (Clockwise) from set point and then back to its set point.
• Then PWN 180 Degrees (Counter Clockwise) from set point and then back to its set point.

What we are looking to do is loop the PWM through the relay’s on the output side of the Mitsubishi FX1S to run the Arduino signal through.

Thanks in advance.

Servos are usually driven with the Servo library, NOT PWM (and certainly not PWN).

The Servo library comes with examples that you are free to at least look at.

Your level-of-effort so far appears to be asking other people to do your work for you.

(deleted)

Gents,

See attachment code I have done so far.

I am doing a college project here and have had zero help from my lecture.

PaulS:
Servos are usually driven with the Servo library, NOT PWM (and certainly not PWN).

What he meant to write was that servos are controlled by PWM, but not directly from the PWM generated by analogWrite.
However, the Servo library will generate this slower, low duty cycle PWM for you.

• We require the code for Arduino to tell the Arduino to the PWN 180 Degrees (Clockwise) from set point and then back to its set point.
• Then PWN 180 Degrees (Counter Clockwise) from set point and then back to its set point.

Is your servo capable of moving through 360 degrees ?

Have you actually got a servo or is it a continuous rotation "not really a servo at all" electrically controlled motor ?

UKHeliBob:
Is your servo capable of moving through 360 degrees ?

Have you actually got a servo or is it a continuous rotation "not really a servo at all" electrically controlled motor ?

Yes, I have a servo, Parallax Inc Servo Motor, 4 → 6 V, 0 → 50 rpm.

TolpuddleSartre:
What he meant to write was that servos are controlled by PWM, but not directly from the PWM generated by analogWrite.
However, the Servo library will generate this slower, low duty cycle PWM for you.

No. I meant what I said. Servos are controlled by pulse position modulation, not pulse width modulation.

That's a continous rotation servo, no position control.

As a matter of interest how will the servo be powered ?

If I Google "Parallax Inc Servo Motor, 4 → 6 V, 0 → 50 rpm" I get this page which says R/C servo motor, continuous rotation. Continuous rotation "servos" have no positional feed back, they are no more than gear motors whose speed and direction (NOT position) is controlled by servo signals.

PaulS:
No. I meant what I said. Servos are controlled by pulse position modulation, not pulse width modulation.

If you really meant that, then you don't understand RC systems.

The position of the servo shaft is proportional to the width of the control pulse. This is the pulse that the Servo library generates.

PPM is used to multiplex the PWM pulses on the single channel between the transmitter and receiver in an RC system, but before the decoder.
The order of the individual channel pulses relative to the long sync low is what is referred to by the position in PPM.

The position of the servo shaft is proportional to the width of the control pulse.

No. It is controlled by the position of the start of the pulse (within a fixed time frame) and the position of the end of the pulse. That is far different from what the Arduino does for PWM.

It is controlled by the position of the start of the pulse (within a fixed time frame) and the position of the end of the pulse

That's a wordy definition of "width" :smiley:

TolpuddleSartre:
That's a wordy definition of "width" :smiley:

Maybe. But it is still far different from what PWM on the Arduino is. The PWM on the Arduino will not make a servo do anything useful.

PWM is PWM.
What is important to a servo is that it is low frequency, typically 50Hz, and low duty-cycle, typically 5-10%, and yes, this is not what analogWrite generates.
However, to deny that servos are controlled by PWM is simply wrong.

This guy does a pretty good job of explaining.