using a motor and servo

i am writing a program using a dc motor and servo. but when i run the motor the servo is going crazy. i am guessing that it is because the engine is creating some noise. is there a way to filter it out?

That's one possibility, but another one is that the power supply to motor and servo are inadequate.
You are not trying to power either from the Arduino 5V rail I hope, that's not good

no i am powering the motor with a 9V battery using a mosfet

9V battery, that's your problem. Hopeless for power, wrong voltage for servo. High current 6V supply
or battery pack needed.

the servo is getting its 5 volts from the arduino. the 9V battery is only for the motor. so they have their own power supply.

Don’t power a motor or servo from the 5V logic supply, its a recipe for disaster, logic supply voltage
must be stable and clean.

9V battery is inadequate for a motor. Servo needs 1A or so. You probably need a 2A capable 6V supply

i am writing a program

I wonder what that looks like...

Question: Power to relay board.

Interesting thing happens, have a new 16 channel relay board.

When had the old 2 relay board connected I could have BOTH the USB and external power connected and everything works fine.

BUT now when the 16 channel board is connected, and BOTH USB and external power are connected ALL relay LEDs light up!(half brightness), Same if only the external power is used.

If I disconnect the external power it works fine...

Have read many many comments that indicate the both can be connected, and states that the external power is usually selected automatically.

Any suggestions? Again the 2 channel relay board works fine with BOTH USB and external power connected, lights behave "normally" Only on the 16 channel relay board.

P.S the external power supply is the Arduino external power supply.