Why does he behaves like this?

Hello, i am new with Arduino (and coding in general…) and try to understand the code. For this purpose i printed an roboticarm (MK1 by Carlo Franciscone - EEZYrobots) and set up this with my Arduino. Take a look:
Roboarm - Eezybot MK1 with Arduino Uno - Album on Imgur I couldn’t bind the image into my post, sry.

Now, here is my Code:

#include <Servo.h> //Servo Biblio
#include <IRremote.h> //Setup IR + Biblio

Servo Servobase;
Servo Servoarml;
Servo Servoarmr;
Servo Servohand;

int angleBase = 86;
int angleArmr = 76;
int angleArml = 84;
int angleHand = 0;

#include <IRremote.h> //Setup IR + Biblio
int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
 Serial.begin(9600);

 Servobase.attach(9);
 Servoarml.attach(11);
 Servoarmr.attach(12);
 Servohand.attach(10);
 Servobase.write(angleBase);
 delay(500);
 Servoarml.write(angleArml);
 delay(500);
 Servoarmr.write(angleArmr);
 delay(500);
 Servohand.write(angleHand);
 delay(500);
 Serial.println("Servos active");

   // In case the interrupt driver crashes on setup, give a clue
  // to the user what's going on.
  Serial.println("Boot IRin");
  irrecv.enableIRIn(); // Start the receiver
  Serial.println("Enabled IRin");
}

void loop() {
   if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value

  if (results.value == 0)    {
      Servobase.write (angleBase+50);
      Serial.println("base cw");
      delay (20);
    }
  if (results.value == 800)    {
      Servobase.write (angleBase+50);
      Serial.println("base cw");
      delay (20);
    }
      if (results.value == 1)    {
      Servobase.write (angleBase-50);
      Serial.println("base ccw");
      delay (20);
    }
       if (results.value == 801)    {
      Servobase.write (angleBase-50);
      Serial.println("base ccw");
      delay (20);
    }
  }
  
}

Right now i just define 2 Buttons on my Remote App (Android RcCoid) and their repeat values (0 and 800; 1 and 801). But if i press the Buttons the Servo just does one turn for 50 degrees. A second press does not repeat the function… But a press of the other button lets him turn back and so on…

I can not film this right now because i use my phone as a remote, if i need to i will remap it to a tv remote to film it.

Is that understandable written…? Do you have the informations to tell me why he behaves like this?

Thank you

Quietsch

Connect it to a computer via USB while testing it and print some debugging information to the serial port so you can see what it's seeing - is it getting the second command? Is it just plain barfing at some point?

Does the software behave the same with the servos disconnected? If not, that implies that noise on the power rails from the motors is causing the microcontroller to hang or reset; use a separate power supply for the servos if this is the case (this is generally recommended)

Could it be that the interrupts required for servo and for IR are interfering with eachother?

Connected to the computer it shows me all the values i send...

The 4 Servos are connected to a DC Wall Adapter with 5V, while the Arduino runs from the USB port. The ground of both are connected...

The Servos got some noise if they are running they are a little jittering...

When i disconnect the servos and run it the Serial Monitor gives out this:

Serial Monitor: Servos active Boot IRin Enabled IRin 0 base cw 1 base ccw 3 2 7 6 4 5 0 base cw 0 base cw 0 base cw 0 base cw 0 base cw 0 base cw 800 800 800 800 800 800

That means when i keep pressing the button he just print out the value, but not the control statement ("base cw" / "base ccw")... All the buttons i created he receives all the values correct...

Quietsch: Connected to the computer it shows me all the values i send...

The 4 Servos are connected to a DC Wall Adapter with 5V, while the Arduino runs from the USB port. The ground of both are connected...

The Servos got some noise if they are running they are a little jittering...

So have you checked via print statements that the point where the servo position is set is really getting run, and that your code is setting it to the position you think you are?

jitter and electrical noise are not the same. Jitter is a correct signal, but inconsistent timing, as opposed to spikes that shouldn't be there at all (for example, the starting and stopping of inductive loads can put spikes onto the power supply rail, sometimes large enough to reset or crash other things powered from it - though it sounds like this isn't happening here, since you report that it doesn't stop printing debug output).

print statements

DrAzzy:
So have you checked via print statements that the point where the servo position is set is really getting run, and that your code is setting it to the position you think you are?

Could you give me an example how you mean that? I just got the “Serial.print” commands wich i checked…

DrAzzy:
jitter and electrical noise are not the same. Jitter is a correct signal, but inconsistent timing, as opposed to spikes that shouldn’t be there at all (for example, the starting and stopping of inductive loads can put spikes onto the power supply rail, sometimes large enough to reset or crash other things powered from it - though it sounds like this isn’t happening here, since you report that it doesn’t stop printing debug output).

Ok, i think i make a video to this, i can’t explain here what really happens…
Youtube Video Link
When i connect the Wall Adapter it doesn’t start, only after booting the Arduino, so it has to come from the signal…?!

I tried to do it now with this switch case function, it behaves the same way...

void loop() {
   if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
    switch (results.value) {
      case 0:
      Servobase.write (angleBase + 5);
      Serial.println("base cw");
      delay (20);
      break;
    }
    }
 }

Yeah - I mean using serial.print() - but print more information. Like, when you pass a value to servo.write, also print that same value to the serial port - that way you can see if the value you're sending it is what you think you're sending it. That way, you can more closely follow what it's doing. I often draw out the control flow of a problematic piece of code, and write out the steps it should be doing by hand.

When a widely used hardware library isn't working for you, your default assumption should be that you're telling the library to do the wrong thing, so sanity check the values you send it.

(I haven't read all of your code - but this is the sort of thing I'd do to track down where things are going off the rails).

You're a boss!!! While doing this i realized, that my code never changed the value of int angleBae... I just wrote angleBase+5 to the servo....

I made this line: angleBase = angleBase+5; and it is fixes :)

Thank you mate!!!