im trying to merge two codes

hello, I'm trying to merge two codes together for my project I normally can do this with no problem but I cant figure out a way to do it and I was wondering if you guys can help. both codes work by themselves. I'm trying to control a servo with a ir and two dc motors with ir I'm thinking it has something to do with the bool. the first code is for dc motors second code is for servo and the third code is me trying to merge them together please help! ive been stuck on this for days and cant go forward with my project till this is done.

here is the dc motor code...

#include <IRremote.h>


int RECV_PIN = 4;

IRrecv irrecv(RECV_PIN);

decode_results results;

int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface 
int speedpinA=9;//enable motor A
int pinI3=12;//define I3 interface 
int pinI4=13;//define I4 interface 
int speedpinB=10;//enable motor B
int spead =65;//define the spead of motor


void setup()

{

irrecv.enableIRIn();
 pinMode(pinI1,OUTPUT);// UP DOWN MOTOR
 pinMode(pinI2,OUTPUT);
 pinMode(speedpinA,OUTPUT);
 pinMode(pinI3,OUTPUT);// FORWARD BACKWARD MOTOR
 pinMode(pinI4,OUTPUT);
 pinMode(speedpinB,OUTPUT);

}

void loop() {

if (irrecv.decode(&results)) {



irrecv.resume();

if (results.value == 0x827D40BF){ //  forward 

                                  //SPEED
    analogWrite(speedpinB,spead);
    digitalWrite(pinI4,HIGH);//turn FORWARD, BACKWARD MOTOR 
    digitalWrite(pinI3,LOW);
    

}else if(results.value == 0x827DC03F){ //  UP 

    analogWrite(speedpinA,spead);//SPEED
    digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
    digitalWrite(pinI1,HIGH);

}

else if(results.value == 0x827D807F){ //  DOWN

analogWrite(speedpinA,spead);//SPEED

    digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
    digitalWrite(pinI1,LOW);

}
else if(results.value == 0x827D10EF){ //  backward 

analogWrite(speedpinB,spead);//SPEED
    
    digitalWrite(pinI4,LOW);
    digitalWrite(pinI3,HIGH);


}
else if(results.value == 0x827DA05F){ // type your remote stop robot control button hex value in underlined area.
digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this should be done to avid damaging the motor. 
    digitalWrite(speedpinB,LOW);
}
}

}

and here is the servo code...

#include <IRremote.h>      //must copy IRremote library to arduino libraries
#include <Servo.h>
#define plus 0x827D20DF   //clockwise rotation button
#define minus 0x827D609F  //counter clockwise rotation button

int RECV_PIN = 4;       //IR receiver pin
Servo servo;
int val;                //rotation angle
bool cwRotation, ccwRotation;  //the states of rotation

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
 Serial.begin(9600);
 irrecv.enableIRIn(); // Start the receiver
 servo.attach(5);     //servo pin
}

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

   if (results.value == plus)
   {
     cwRotation = !cwRotation;      //toggle the rotation value
     ccwRotation = false;         //no rotation in this direction
   }

   if (results.value == minus)
   {
     ccwRotation = !ccwRotation;   //toggle the rotation value
     cwRotation = false;            //no rotation in this direction
   }
 }
 if (cwRotation && (val != 175))  {
   val++;                         //for colockwise button
 }
 if (ccwRotation && (val != 0))  {
   val--;                         //for counter colockwise button
 }
 servo.write(val);
 delay(200);          //General speed
}

and this is me trying to merge the two codes together it does verify that their are no errors...

#include <IRremote.h>
#include <Servo.h>
#define plus 0x827D20DF   //clockwise rotation button
#define minus 0x827D609F  //counter clockwise rotation button

int RECV_PIN = 4;
Servo servo;
int val;                //rotation angle
bool cwRotation, ccwRotation;  //the states of rotation
IRrecv irrecv(RECV_PIN);

decode_results results;

int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface 
int speedpinA=9;//enable motor A
int pinI3=12;//define I3 interface 
int pinI4=13;//define I4 interface 
int speedpinB=10;//enable motor B
int spead =65;//define the spead of motor


void setup()

{
 Serial.begin(9600);
 irrecv.enableIRIn();
 pinMode(pinI1,OUTPUT);// UP DOWN MOTOR
 pinMode(pinI2,OUTPUT);
 pinMode(speedpinA,OUTPUT);
 pinMode(pinI3,OUTPUT);// FORWARD BACKWARD MOTOR
 pinMode(pinI4,OUTPUT);
 pinMode(speedpinB,OUTPUT);
 servo.attach(5);     //servo pin

}

void loop() {

if (irrecv.decode(&results)) {



irrecv.resume();

if (results.value == 0x827D40BF){ //  forward 

                                  //SPEED
    analogWrite(speedpinB,spead);
    digitalWrite(pinI4,HIGH);//turn FORWARD, BACKWARD MOTOR 
    digitalWrite(pinI3,LOW);
    

}else if(results.value == 0x827DC03F){ //  UP 

    analogWrite(speedpinA,spead);//SPEED
    digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
    digitalWrite(pinI1,HIGH);

}

else if(results.value == 0x827D807F){ //  DOWN

analogWrite(speedpinA,spead);//SPEED

    digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
    digitalWrite(pinI1,LOW);

}
else if(results.value == 0x827D10EF){ //  backward 

analogWrite(speedpinB,spead);//SPEED
    
    digitalWrite(pinI4,LOW);
    digitalWrite(pinI3,HIGH);


}
else if(results.value == 0x827DA05F){ // type your remote stop robot control button hex value in underlined area.
digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this should be done to avid damaging the motor. 
    digitalWrite(speedpinB,LOW);
}
{
  if (irrecv.decode(&results)) {
   Serial.println(results.value, HEX);
   irrecv.resume(); // Receive the next value

   if (results.value == plus)
   {
     cwRotation = !cwRotation;      //toggle the rotation value
     ccwRotation = false;         //no rotation in this direction
   }

   if (results.value == minus)
   {
     ccwRotation = !ccwRotation;   //toggle the rotation value
     cwRotation = false;            //no rotation in this direction
   }
 }
 if (cwRotation && (val != 175))  {
   val++;                         //for colockwise button
 }
 if (ccwRotation && (val != 0))  {
   val--;                         //for counter colockwise button
 }
 servo.write(val);
 delay(200);          //General speed
}}}

After 25 posts on these forums, you should be well aware that your code must be posted in between [code]code tags[/code]
(I see that you've been told this at least twice in the past. Perhaps it's time to take notice and do it? And please also format the code correctly, using Ctrl-T)

I'm sry I was unaware of this and wouldnt of done it if I've known I apologize.

Tmz1313:
I'm sry I was unaware of this and wouldnt of done it if I've known I apologize.

That's not true. As I said, you were told the same thing in two of your previous threads.
In this reply:- need to drive two dc motors at two diffrent speeds so far only one speed - #2 by JimboZA - Motors, Mechanics, Power and CNC - Arduino Forum
And in this reply:- how to control two dc motors with diffrent speeds - #4 by groundFungus - Programming Questions - Arduino Forum

Anyway, it's not too late to edit your post and add code tags.
At the bottom of the post, hover your mouse over "More", then click on "Modify".
Then, when the edit window opens, select all of your code then press the </> button. That will enclose your code in code tags.

once again... I didn't know or I wouldnt have done it I'm not trying to break the rules. I simply did not see those replies. have you noticed I didn't reply back? its because I got no notification of a message and I couldn't find my post in the forum. For some reason I don't get messages in my inbox I have to go to the forum page, find my post then I can see if anyone replied. but anyways I know now and wont do it again... if you can help that would be greatly appreciated. I have fixed my post the right way :slight_smile:

and now I found out how to get alerts!!! so once again I apologize. I will have this problem no more

Thanks for fixing it.
You know you can click on the ["Receive Emails and Alerts"] button, then select "Receive Emails and Alerts" to ensure that you get notifications?

Also, you can set your preferences in:- >Profile >Forum Settings, then >Settings >Notifications >Notification Preferences
(This doesn't seem to be working right at the moment, for me at least.)


You've shown your merged code and said it compiles but doesn't work, but don't give any more details.
We need some clues to go on.
Please describe exactly what you want to happen, in detail, then describe what is actually happening (or not happening).

Edit: I just saw your latest post, but left this reply as-is anyway. :slight_smile:

I want to Beable to press a button on my ir remote to move the servo and dc motors. And have a dedicated button for each motor and servo. What happens when I merge the codes is basically nothing... A little jerking and buzzing sound from the servo. No sounds or movements from the dc motors. I have a feeling it's because how much the two codes are different. And how they act out the code ( sry can't think of the lingo that needs to be used lol.) both codes run perfect by themselves motors and servo works exactly how I want them to work

I'm trying to decipher your code and read your mind regarding what you want.

Your latest post just confuses things even more - you say you want "a dedicated button for each motor and servo", yet your code has no button input pins, and you said nothing whatsoever about how you intend to have the buttons control the DC motors and servo.

I don't know what sort of motor driver you're using, and the names "pinI1" etc aren't particularly descriptive, so I'll just assume that your DC motor control logic is correct. (You said it was previously working.

Do you really want this to 'toggle' each time "PLUS" is received from the IR remote, or do you just simply want to set the CW rotation flag and clear the CCW rotation flag? :-

if (results.value == plus)
{
    cwRotation = !cwRotation;      //toggle the rotation value
    ccwRotation = false;         //no rotation in this direction
}

Here:-

if (cwRotation && (val != 175))
{
    val++;                         //for colockwise button
}

Do you actually mean to increment val while it is less than 175?

Looking at it all, too, I'd personally use 'switch/case' rather than the 'if/else' statements'.

Edit: It's a little confusing, but do you want the servo to only move while the "PLUS" or "MINUS" buttons on the IR remote are pressed? (CW when "PLUS", CCW when "MINUS")
And no servo movement when the button is not pressed?

When I say buttons I mean buttons on the remote not like a push button. I mean one button on the ir remote for the servo to turn clockwise one button to turn counterclockwise and same with the dc motors. And you have to forgive me I didn't write neither of these codes and haven't added the "//" to describe what is doing what... That's another thing I need to work on lol. I'm useing a seeed motor shield and pinI1 and pinI2 I think are used for direction of motor? Once again this isn't my code and I myself am kinda confused how this shield works and how the interface works with it but yes I can run the code by itself and use my ir remote to control what way the motors are going so I doubt that is the problem. And I want to set the Cw rotation flag and clear the Ccw rotation flag. And also I want to increment value while it is less than 175. Tell you the truth I am just as confused as you are I'm pretty new to all this and some of the code is kinda of confusing. I just know the two codes work independently but won't work when I merge them together. And also I'm on my phone so it's even harder for me to figure how to use this forum. Please bare with me. I will have to look into how to use the switch/case function. I'm unfamiliar with that.

Tmz1313:
When I say buttons I mean buttons on the remote not like a push button. I mean one button on the ir remote for the servo to turn clockwise one button to turn counterclockwise and same with the dc motors. And you have to forgive me I didn't write neither of these codes and haven't added the "//" to describe what is doing what... That's another thing I need to work on lol. I'm useing a seeed motor shield and pinI1 and pinI2 I think are used for direction of motor? Once again this isn't my code and I myself am kinda confused how this shield works and how the interface works with it but yes I can run the code by itself and use my ir remote to control what way the motors are going so I doubt that is the problem. And I want to set the Cw rotation flag and clear the Ccw rotation flag. And also I want to increment value while it is less than 175. Tell you the truth I am just as confused as you are I'm pretty new to all this and some of the code is kinda of confusing. I just know the two codes work independently but won't work when I merge them together. And also I'm on my phone so it's even harder for me to figure how to use this forum. Please bare with me. I will have to look into how to use the switch/case function. I'm unfamiliar with that.

No problem. Hopefully we'll get there. I have to rely on you to have the wiring correct, and also to have the correct IR remote codes, and I should be able to help with the rest.
I've had a bit of a play with your code and modified it a bit. I can't test, so it might not be correct yet, but it's a lot closer. (Still using 'if/else' for the moment.)
See how this goes:- *** Instead see the revised version in reply #13.

#include <IRremote.h>
#include <Servo.h>

#define PLUS 0x827D20DF   //clockwise rotation button
#define MINUS 0x827D609F  //counter clockwise rotation button

const byte RECV_PIN = 4;
const byte servoPin = 5;
const byte pinI1 = 8;          //define I1 interface
const byte pinI2 = 11;         //define I2 interface
const byte speedpinA = 9;      //enable motor A
const byte pinI3 = 12;         //define I3 interface
const byte pinI4 = 13;         //define I4 interface
const byte speedpinB = 10;     //enable motor B

byte servoAngle;                //rotation angle
bool moveServo = false;
byte spead = 65;         //define the spead of motor

Servo servo;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
    Serial.begin(9600);
    irrecv.enableIRIn();
    pinMode(pinI1, OUTPUT); // UP DOWN MOTOR
    pinMode(pinI2, OUTPUT);
    pinMode(speedpinA, OUTPUT);
    pinMode(pinI3, OUTPUT); // FORWARD BACKWARD MOTOR
    pinMode(pinI4, OUTPUT);
    pinMode(speedpinB, OUTPUT);
    servo.attach(servoPin);     //servo pin
}

void loop()
{
    if (irrecv.decode(&results))
    {
        if (results.value == 0x827D40BF)        //  forward
        {
            analogWrite(speedpinB, spead);      //SPEED
            digitalWrite(pinI4, HIGH);          //turn FORWARD, BACKWARD MOTOR
            digitalWrite(pinI3, LOW);
        }
        else if (results.value == 0x827DC03F)   //  UP
        {
            analogWrite(speedpinA, spead);      //SPEED
            digitalWrite(pinI2, LOW);           //turn DC Motor A move clockwise
            digitalWrite(pinI1, HIGH);
        }
        else if (results.value == 0x827D807F)   //  DOWN
        {
            analogWrite(speedpinA, spead);      //SPEED
            digitalWrite(pinI2, HIGH);          //turn DC Motor A move clockwise
            digitalWrite(pinI1, LOW);
        }
        else if (results.value == 0x827D10EF)   //  backward
        {
            analogWrite(speedpinB, spead);      //SPEED
            digitalWrite(pinI4, LOW);
            digitalWrite(pinI3, HIGH);
        }
        else if (results.value == 0x827DA05F) // "STOP"
        {
            digitalWrite(speedpinA, LOW); // Unenble the pin, to stop the motor. this should be done to avid damaging the motor.
            digitalWrite(speedpinB, LOW);
        }
        else if (results.value == PLUS)
        {
            if (servoAngle < 175)
            {
                servoAngle++;
                moveServo = true;
            }
        }
        else if (results.value == MINUS)
        {
            if (servoAngle > 0)
            {
                servoAngle--;
                moveServo = true;
            }
        }
        irrecv.resume();
    }
    if (moveServo)
    {
        servo.write(servoAngle);
        moveServo = false;
        delay(15);          // Allow time for the servo to move 1 degree.
    }
    delay(200);          //General speed  *** Do you really want this? ***
}

I want the servo to move when I press the button and not stop moving till I press the same button again, or make it go the opposite way. And thanks so much man I appreciate you helping out. Unfortunately I gotta go to sleep to wake up in the am for work but will try it out tomorrow and I will let ya know how it goes. I'm 100% sure my wireing and ir remote are correct I will let ya know. Hopefully it works if not hopefully you can still help. Greatly appreciated sir.

Tmz1313:
I want the servo to move when I press the button and not stop moving till I press the same button again, or make it go the opposite way.

In that case my modified code won't quite do what you want. It was written to only move the servo while one of the buttons was pressed.
And your original "working" servo code didn't make it stop on a second button press, either. That adds another level of complexity.

And thanks so much man I appreciate you helping out. Unfortunately I gotta go to sleep to wake up in the am for work but will try it out tomorrow and I will let ya know how it goes. I'm 100% sure my wireing and ir remote are correct I will let ya know. Hopefully it works if not hopefully you can still help. Greatly appreciated sir.

Test it if you want, and a lot of stuff has been cleaned up, but as mentioned it still doesn't do quite what you want it to.

Don't worry about that last code. I modified it to move the servo the way you describe:-

I want the servo to move when I press the button and not stop moving till I press the same button again, or make it go the opposite way.

I didn't use a remote control, but tested the servo part of this code using a servo and two pushbuttons, "PLUS" and "MINUS". It works fine. (I can't vouch for the rest of the code - I don't have a seeed motor shield or a pair of loose DC motors sitting here, although I do have a decoded remote control and receiver.)

Oh, before I forget - the way you're doing things, the servo actually rotates in the opposite direction to what your code and comments say, when it's viewed from the shaft side. ie When CW is selected, the shaft actually turns CCW, and vice versa.
That's how your code originally was, and I know you tested the original servo code, so I left it like that in case you were looking at it with the shaft pointed away from you.
On a standard servo, with the shaft pointing toward you, "0" is fully CW and "180" is fully CCW.

If you want to reverse the direction, change this:-if(moveServoCW)                            // CW movement enabled.to this:-if(moveServoCCW)                            // CCW movement enabled.
and change this:-if(moveServoCCW)                            // CCW movement enabled.to this:-if(moveServoCW)                            // CW movement enabled.

Anyway, here's the modified code:-

// MergeCodes2.ino

#include <IRremote.h>
#include <Servo.h>

#define PLUS 0x827D20DF                 //clockwise rotation button
#define MINUS 0x827D609F                //counter clockwise rotation button

const byte RECV_PIN = 4;                // IR receiver input on pin 4.
const byte servoPin = 5;                // Servo signal output on pin 5.
const byte pinI1 = 8;                   //define I1 interface
const byte pinI2 = 11;                  //define I2 interface
const byte speedpinA = 9;               //enable motor A
const byte pinI3 = 12;                  //define I3 interface
const byte pinI4 = 13;                  //define I4 interface
const byte speedpinB = 10;              //enable motor B

byte servoAngle;                        //rotation angle
byte speed = 65;                        //define the speed of motor

bool moveServoCW = false;               // CW servo movement flag.
bool moveServoCCW = false;              // CCW servo movement flag.

Servo servo;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
    Serial.begin(9600);
    irrecv.enableIRIn();
    pinMode(pinI1, OUTPUT);             // UP DOWN MOTOR
    pinMode(pinI2, OUTPUT);
    pinMode(speedpinA, OUTPUT);
    pinMode(pinI3, OUTPUT);             // FORWARD BACKWARD MOTOR
    pinMode(pinI4, OUTPUT);
    pinMode(speedpinB, OUTPUT);
    servo.attach(servoPin);             // Attach the servo
}

void loop()
{
    if (irrecv.decode(&results))
    {
        if (results.value == 0x827D40BF)        //  forward
        {
            analogWrite(speedpinB, speed);      //SPEED
            digitalWrite(pinI4, HIGH);          //turn FORWARD, BACKWARD MOTOR
            digitalWrite(pinI3, LOW);
        }
        else if (results.value == 0x827DC03F)   //  UP
        {
            analogWrite(speedpinA, speed);      //SPEED
            digitalWrite(pinI2, LOW);           //turn DC Motor A move clockwise
            digitalWrite(pinI1, HIGH);
        }
        else if (results.value == 0x827D807F)   //  DOWN
        {
            analogWrite(speedpinA, speed);      //SPEED
            digitalWrite(pinI2, HIGH);          //turn DC Motor A move clockwise
            digitalWrite(pinI1, LOW);
        }
        else if (results.value == 0x827D10EF)   //  backward
        {
            analogWrite(speedpinB, speed);      //SPEED
            digitalWrite(pinI4, LOW);
            digitalWrite(pinI3, HIGH);
        }
        else if (results.value == 0x827DA05F)   // "STOP"
        {
            digitalWrite(speedpinA, LOW); // Unenble the pin, to stop the motor. this should be done to avid damaging the motor.
            digitalWrite(speedpinB, LOW);
        }
        else if (results.value == PLUS)         // "PLUS" pressed
        {
            if (moveServoCW)                    // If already moving the servo CW, stop.
                moveServoCW = false;
            else                                // If not already moving CW, start moving.
            {
                moveServoCW = true;
                moveServoCCW = false;
            }
        }
        else if (results.value == MINUS)        // "MINUS" pressed
        {
            if (moveServoCCW)                   // If already moving the servo CCW, stop.
                moveServoCCW = false;
            else                                // If not already moving CCW, start moving.
            {
                moveServoCCW = true;
                moveServoCW = false;
            }
        }
        irrecv.resume();
    }

    if (moveServoCW)                           // CW movement enabled.
    {
        if (servoAngle < 175)                   // If limit has not been reached,
        {
            servoAngle++;                       // increment the angle and
            servo.write(servoAngle);            // move the servo.
        }
        else                                    // Otherwise if limit has been reached
            moveServoCW = false;                // disable movement in this direction.
    }

    if (moveServoCCW)                          // CCW movement enabled.
    {
        if (servoAngle > 0)                     // If limit has not been reached,
        {
            servoAngle--;                       // decrement the angle and
            servo.write(servoAngle);            // move the servo.
        }
        else                                    // Otherwise if limit has been reached
            moveServoCCW = false;               // disable movement in this direction.
    }

    delay(200);                                 //General speed - Very slow. :)
}

Good luck. Let me know if you have a problem, and/or if I've made a mistake.
(And once it's basically working, I can easily show you how to change to using 'switch/case' instead of all of the cumbersome 'if/else' statements if you like.)

Hi,

I want the servo to move when I press the button and not stop moving till I press the same button again.
Or make it go the opposite way.
And thanks so much man I appreciate you helping out.
Unfortunately I gotta go to sleep to wake up in the am for work but will try it out tomorrow and I will let ya know how it goes.
I'm 100% sure my wireing and ir remote are correct I will let ya know.
Hopefully it works if not hopefully you can still help.
Greatly appreciated sir.

Sorry to do this, but it might be good if the OP reads his posts, spacing of your sentences makes reading your posts sooooo much easier.
It sets them up in point form so each problem can be addressed separately.

You will find if you do not show some structure to your request, people will find it hard to understand what you are trying to say.
Or will not even bother to read your post.

Thanks.. Tom... :slight_smile:

so I tried the code and we are getting somewhere lol. the servo works but the dc motors do not.
now on my motor shield it says its switching rotation when I try to change direction of motors when I push the ir remote buttons so I know its recieveing the ir light and is doing something. its just not sending voltage out to the motors.
maybe I cant run servo motors and servos at the same time with this motor shield? it says I can in the data sheet here is the info on the motor shield.

seeed motor shield v1.0

I hope I can ive spent a week building this thing and this would ruin the whole project :frowning:

Tmz1313:
so I tried the code and we are getting somewhere lol. the servo works but the dc motors do not.
now on my motor shield it says its switching rotation when I try to change direction of motors when I push the ir remote buttons so I know its recieveing the ir light and is doing something. its just not sending voltage out to the motors.
maybe I cant run servo motors and servos at the same time with this motor shield? it says I can in the data sheet here is the info on the motor shield.

seeed motor shield v1.0

I hope I can ive spent a week building this thing and this would ruin the whole project :frowning:

Yesterday, I concentrated on getting rid of the main errors and merging the code properly, then on the servo control. As I mentioned, I didn't look too closely at the DC motor stuff.

Now, however, when I do look at the DC motor control, the problem is immediately apparent. You say that the LED indicators show that the direction of the motors is changing OK, so we don't need to look at the I1, I2, I3 and I4 stuff. That only leaves the two motor enable pins that you control with PWM for speed control.

The seeed shield uses PWM pin 9 for motor A enable and PWM pin 10 for motor B enable.
Unfortunately, that can't work. The servo library doesn't allow use of those pins at the same time that you're driving a servo.
From the "Servo" library reference:-

On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.

You said:-

maybe I cant run servo motors and servos at the same time with this motor shield?

That appears to be the case.

it says I can in the data sheet

I couldn't see anywhere that they said this.

You can at least run the DC motors at full speed, by changing your 'analogWrite()' speed control statements to 'digitalWrite()', passing '1' to run or '0' to stop. That probably won't do what you want, though.

This is the big problem with shields as opposed to breakout boards/separate modules. They tie up a lot of pins and don't allow you to juggle pin numbers to suit your needs.

If you have a multimeter and are confident in using it, you could remove the jumpers from the enable connectors, check (on the DMM continuity setting, with power removed from everything), which pin of each connector goes directly to the chip's motor enable pin, then run a jumper cable to each of those enable pins from a PWM pin which is exposed at the Grove connectors.
It's a bit of messing around, though, and if you stuff up and connect wrongly you could connect an Arduino digital output directly to +5V and kill the Arduino.

Or, if this is correct, you could buy a Mega:-

On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.

Ok so I have an idea maybe it will work maybe it wont let me know what you think.

What if I did what you said and change it to digitalwrite and have the dc motors run at full speed. (But of course I need them to run at a little lower speed then full tilt boogie lol.)

I know this isn't the correct way of doing this but I could always use resistors in series with the motor to lower the voltage but I don't know how it would work when it switches polarity to change direction of the motors or would it?

I also have a adjustable voltage regulator that I could lower the voltage to the motors but once again switching polarity might mess it up?

And one more option just like how I am controlling the servo speed I could maybe put a delay on the motors.Maybe 500 mill or 750 mill sec at a time.(delay wouldn't matter because I'm not trying to do multiple things at once) I would just have to press the button multiple times on the ir remote to move the things I'm trying to move?

And I guess I could tell you what I'm making lol its a crane so the motors don't have to be on for a long time what do you think my best option is?

If you have a multimeter and are confident in using it, you could remove the jumpers from the enable connectors, check (on the DMM continuity setting, with power removed from everything), which pin of each connector goes directly to the chip's motor enable pin, then run a jumper cable to each of those enable pins from a PWM pin which is exposed at the Grove connectors.
It's a bit of messing around, though, and if you stuff up and connect wrongly you could connect an Arduino digital output directly to +5V and kill the Arduino.

for some reason they changed the design of the shield. their are no jumpers to remove beside the jumper that power he arduino

You can't use a regulator. Resistors wouldn't be very successful either, because the speed would vary a lot with load. Under low load, the motors would turn much faster, then slow right down or even stop under full load. Plus the resistors would possibly get pretty hot, depending on voltage and current.

You could 'bit-bang' a crude form of PWM for the two enable lines on pins 9 and 10, but rather than 'delay()' you'd be far better off using 'millis()'-based timing for that. You will be doing multiple things at once. While driving the motors, you also need to check for IR codes and take appropriate action. ie. Stop driving the DC motors. Check out the "BlinkWithoutDelay" example and this thread for tips on that:- Demonstration code for several things at the same time
Where previously (if it had worked) you could set your motor's speed and direction, than get back to other things like interpreting IR codes and acting on them, with 'delay()'-based PWM that won't be possible.

It's a good opportunity to learn how to use 'millis()'-based timing, if you haven't done it already. It's an essential part of learning to use an Arduino effectively.

Good point on the resistors.

well I did alter the code with delay since the last time I posted on here.
it doesn't seem to matter because I'm only have it delayed for 10-20 milli and I cant press the button fast enough for it to not pick up the incoming infared remote from the delay.

Now I did look at the milli function but tell you the truth it confused me lol. I know its a important to learn but I wouldn't know how to incorporate it into the code. if you want to do it for me I might beable to have a better understanding how to incorporate it into other codes I will use down the road. but please only if you want to. Like I said I just tested it out all motors and servos work with the remote. so its not a big deal if I just use the delay function.

But one thing I did notice with the servo is it goes to a certain position once started up and it will strip my gears on the outside of the servo (not inside of it lol)from going so fast. and it has a lot of weight it moves so its jerking he crane and will eventually make it fall apart or break something. could you maybe make it where it doesn't need to go to a certain position and just go from the position its in? I'm more worried about this a than the delay function.

Also I want to thank you oh so much for taking your time out to alter, troubleshooting, and showing me how to use this forum the correct way. it was driving me crazy on how much time ive spent on this project and it would have been a shame to throw it all away because of the timing issue.

here is the code I altered with the delay functions

// MergeCodes2.ino

#include <IRremote.h>
#include <Servo.h>

#define PLUS 0x827D20DF                 //clockwise rotation button
#define MINUS 0x827D609F                //counter clockwise rotation button

const byte RECV_PIN = 4;                // IR receiver input on pin 4.
const byte servoPin = 5;                // Servo signal output on pin 5.
const byte pinI1 = 8;                   //define I1 interface
const byte pinI2 = 11;                  //define I2 interface
const byte speedpinA = 9;
const byte pinI3 = 12;                  //define I3 interface
const byte pinI4 = 13;                  //define I4 interface
const byte speedpinB = 10;

byte servoAngle;                        //rotation angle
byte speed = 65;                        //define the speed of motor

bool moveServoCW = false;               // CW servo movement flag.
bool moveServoCCW = false;              // CCW servo movement flag.

Servo servo;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
    Serial.begin(9600);
    irrecv.enableIRIn();
    pinMode(pinI1, OUTPUT);             // UP DOWN MOTOR
    pinMode(pinI2, OUTPUT);
    pinMode(speedpinA, OUTPUT);
    pinMode(pinI3, OUTPUT);             // FORWARD BACKWARD MOTOR
    pinMode(pinI4, OUTPUT);
    pinMode(speedpinB, OUTPUT);
    servo.attach(servoPin);             // Attach the servo
}

void loop()
{
    if (irrecv.decode(&results))
    {
        if (results.value == 0x827D40BF)        //  forward
        {
            digitalWrite(speedpinB, HIGH);  
            digitalWrite(pinI4, HIGH);          //turn FORWARD, BACKWARD MOTOR
            digitalWrite(pinI3, LOW);
            delay(10);
            digitalWrite(speedpinB, LOW);
        }
        else if (results.value == 0x827DC03F)   //  UP
        {
            digitalWrite(speedpinA, HIGH); 
            digitalWrite(pinI2, LOW);           //turn DC Motor A move clockwise
            digitalWrite(pinI1, HIGH);
            delay(20);
            digitalWrite(speedpinA, LOW);
        }
        else if (results.value == 0x827D807F)   //  DOWN
        {
            digitalWrite(speedpinA, HIGH); 
            digitalWrite(pinI2, HIGH);          //turn DC Motor A move clockwise
            digitalWrite(pinI1, LOW);
            delay(20);
            digitalWrite(speedpinA, LOW);
        }
        else if (results.value == 0x827D10EF)   //  backward
        {
            digitalWrite(speedpinB, HIGH); 
            digitalWrite(pinI4, LOW);
            digitalWrite(pinI3, HIGH);
            delay(10);
            digitalWrite(speedpinB, LOW);
        }
         else if (results.value == PLUS)         // "PLUS" pressed
        {
            if (moveServoCW)                    // If already moving the servo CW, stop.
                moveServoCW = false;
            else                                // If not already moving CW, start moving.
            {
                moveServoCW = true;
                moveServoCCW = false;
            }
        }
        else if (results.value == MINUS)        // "MINUS" pressed
        {
            if (moveServoCCW)                   // If already moving the servo CCW, stop.
                moveServoCCW = false;
            else                                // If not already moving CCW, start moving.
            {
                moveServoCCW = true;
                moveServoCW = false;
            }
        }
        irrecv.resume();
    }

    if (moveServoCW)                           // CW movement enabled.
    {
        if (servoAngle < 175)                   // If limit has not been reached,
        {
            servoAngle++;                       // increment the angle and
            servo.write(servoAngle);            // move the servo.
        }
        else                                    // Otherwise if limit has been reached
            moveServoCW = false;                // disable movement in this direction.
    }

    if (moveServoCCW)                          // CCW movement enabled.
    {
        if (servoAngle > 0)                     // If limit has not been reached,
        {
            servoAngle--;                       // decrement the angle and
            servo.write(servoAngle);            // move the servo.
        }
        else                                    // Otherwise if limit has been reached
            moveServoCCW = false;               // disable movement in this direction.
    }

    delay(200);                                 //General speed - Very slow. :)
}