# ServoMotor

my question:
if i set degree to every value from 0 until 125, it works fine
but it’s not working for 130-180 degrees
why?
it goes from zero to 130 and stops, no backward movement

pins of servomotor
5V plus
ground
and 3rd pin on nummer 52 (ATMEGA 2560)

``````#include <Servo.h>
#define DEGREE 0

Servo servoblau;

short x=10;
short degree = 125;

void setup()

{
servoblau.attach(52);                        // initialising pin 52

} // end setup

void loop()
{
short z=DEGREE;                            // set z to 0 degrees

for (char b=0; b<=degree; b++){      // for loop for increasing degrees stepwise
servoblau.write(z);                        // set servo to position z
delay(x);                                     // waiting
z++;                                           // increasing z position
} // end for

for (char b=0; b<=degree; b++){      // for loop for decreasing degrees stepwise
servoblau.write(z);                        // set servo to position z
delay(x);                                     // waiting
z--;                                           // decreasing z position

} //end for
}
``````

Tom.. :)

Or make them byte...

"char b" is a signed 8-bit value so it can't hold a value larger than 127. That explains why 125 works but 130 doesn't.

You could use "unsigned char b" to get values from 0 to 255.

If you are powering the servo from the arduino 5v, that can cause arduino resetting issues.

johnwasser:
“char b” is a signed 8-bit value so it can’t hold a value larger than 127. That explains why 125 works but 130 doesn’t.

You could use “unsigned char b” to get values from 0 to 255.

Sure, thank you very much, I should’ve known that…

zoomkat:
If you are powering the servo from the arduino 5v, that can cause arduino resetting issues.

why that?

Because a servo can demand quite some current and this can drop the voltage of the 5v line because the on-board regulator isn't that powerful.

i tried that with unsigned char
it worked

another question
is that impossible to go over 180 degrees cause of servomotor settings oder do i have to do something special in my program?

edit: i looked into the gearing mechanism
it’s impossible

Most servos can only turn 180 degrees at most, often less. There are some servos available that can turn through several rotations, usually used as sail winches on model yachts. Continuous rotation "servos" can rotate an infinite number of times in each direction but you have no control over position, only speed, because they have no feedback mechanism to determine the angle that they are at.

buell25:
is that impossible to go over 180 degrees cause of servomotor settings oder do i have to do something special in my program?

There is a physical limit to how far the servo can turn. If you use .writeMilliseconds() with values below 1000 and above 2000 you can figure out how far you can push that particular servo. To go beyond the default limits of 544 and 2400 you have to pass new limits to .attach(): Arduino - ServoAttach
If you have a potentiometer you can use this sketch to test the limits of your servo. Start with your potentiometer near the middle so you don’t harm the servo by driving it into the physical stop.

``````#include <Servo.h>
Servo myservo;
const int potPin = A0;
const int servoPin = 9;
void setup() {
myservo.attach(servoPin, 250, 2750);
Serial.begin(9600);
}
void loop() {
int microseconds = map(potVal, 0, 1023, 250, 2750);
myservo.writeMicroseconds(microseconds);
Serial.println(microseconds);
delay(500);
}
``````

ok thanks

another question i want to use a remote control and a servomotor i simply want to press a button on the remote control and the servo should make a movement

how do i realize that? i only have 5 Volts??!

Look into IR-libraries and you are good to go ;)

septillion:
Look into IR-libraries and you are good to go

i don’t know what you mean with IR libraries

if you mean #include <IRremote.h>
i have it already in my programm included

Look in Files/Example/IRremote in the IDE and you will find some examples of how to use the library.

UKHeliBob: Look in Files/Example/IRremote in the IDE and you will find some examples of how to use the library.

unfortunately there is nothing

i simply want to press a button on the remote control and the servo should make a movement

There are various remote control devices on ebay and elsewhere which could be used to act as a buttn connected to an arduino. Basic arduino servo button code below.

``````//zoomkat servo button test 7-30-2011
//Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
pinMode(button1, INPUT);
servo1.attach(7);
digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
if (press1 == LOW)
{
servo1.write(160);
}
else {
servo1.write(20);
}
}
``````

buell25: unfortunately there is nothing

What do you see if you scroll down ?

UKHeliBob:
What do you see if you scroll down ?

only Ethernet

Do you have IRremote.h on your PC and, if so, which exactly folder is it in ?

UKHeliBob: Do you have IRremote.h on your PC and, if so, which exactly folder is it in ?

I searched the whole folder for "IRemote.h" and "IRemote" but couldn´t find anything

I have only this

C:\Programme\arduino-nightly\libraries\RobotIRremote