So I am currently working on a project as part of my Uni assignment that uses 3 DC motors and 2 Servo Motors, I currently have a servo and a DC motor connected to my Arduino Uno - l293d motor shield. The DC motor is routed through a PCB which I have manufactured which includes uses MOSFET. I have also opted to power my servo motors with 4 AA Alkaline Batteries so that I can connect the other 2 DC motors from the shield.
My issue is that whenever I send power to my PCB, the Servo motor is affected by it; in that the position of the servo changes while the DC motor is powered. I have also discovered that it is the ground pin of the servo which is being affected and not the S pin, which on the shield is pin 9. I have tried changing the ground pin to every spot on the board to no avail.
Does anyone know what the specific issue is and how I can go about solving it?
If a schematic of the PCB is required, I can provide one. I am just cautious about uploading Uni content online. My l293d motor shield was purchased from my local Jaycar (Australian Electronics Store)
Almost certainly a lack of decoupling of the power supply. Not only do you have no servos on your schematics you seem to have only one ( value unmarked ) large decoupling capacitor.
You need star wiring where all the grounds meet at one common point.
What has the A5 mentioned in title got to do with this code or this schematic?
What Arduino are you using?
I find it strange that your post topic says:
"Output from pin A5 to DC motor via external pcb causing servo motor connected to arduino to
react".
A5 is an analog INPUT , NOT an OUTPUT so it is highly unlikely that is the problem.
And then there's this:
Servo pitch; // Pitch of Nozzle at Pin 9
Servo rotate; // Rotating plate for nozzle at Pin 10
const int pumpPin = A5;
int p_pos = 90; // variable to store the pitch position
int r_pos = 20; // variable to store the rotation position
void setup() {
Serial.begin(9600) ;
pitch.attach(9); // attaches the servo on pin 9 to the servo object
rotate.attach(10); // attaches the servo on pin 10 to the servo object
pitch.write(p_pos);
rotate.write(r_pos);
nsIrNec::begin(2) ; // MUST BE EXTERNAL INTERRUPT PIN
}
void loop() {
nsIrNec::loop() ; // check for new data
if ( nsIrNec::dataOut != 0 ) {
// print interpreted data then reset it
Serial.println(nsIrNec::dataOut,HEX) ;
Serial.println();
switch (nsIrNec::dataOut)
{
case 0xFFA25D:
{
Serial.println("CH-");
p_pos += 20;
pitch.write(p_pos);
break;
}
case 0xFFE21D:
{
p_pos -= 20;
pitch.write(p_pos);
break;
}
case 0xFF629D:
{
p_pos = 90;
pitch.write(p_pos);
break;
}
case 0xFF22DD:
{
r_pos -= 5;
rotate.write(r_pos);
break;
}
case 0xFF02FD:
{
r_pos += 10;
rotate.write(r_pos);
break;
}
case 0xFFC23D:
{
analogWrite(pumpPin, 255);
delay(500);
analogWrite(pumpPin, 0);
break;
}
case 0xFFA857:
{
motor.setSpeed(255);
motor.run(FORWARD);
delay(1000);
motor.run(RELEASE);
}
}
nsIrNec::dataOut = 0; //clear
}
if (p_pos > 180)
{
p_pos = 180;
}
if (p_pos < 20)
{
p_pos = 20;
}
if (r_pos > 45)
{
r_pos = 45;
}
if (r_pos < 0)
{
r_pos = 0;
}
delay(500);
}
``
What's wrong with the above ?
1. A5 is an analog input pin.
2. No pinMode declaration for the output
3. A5 is not a PWM pin (pins 9 and 10 are) Since it is not a PWM pin, analogWrite will not work
on A5. Pins 9 or 10 will work as inputs for J2. A5 will not.
4. I don't see any servo motors in the schematic so have no idea what they have to do with it.
5. I don't see any errors in the schematic but fail to see the relevance to your post title.
My apologies for the terrible title. I am new to Arduino so I didn't know that the "A" pins were for input and the schematic was for the external PCB I was using.
In terms of the issue, I have since found the problem with the circuit. Turns out it was my cheap motor releasing a lot of EMF and occasionally sending current through the wrong direction.
Even expensive motors do this, all motors that use brushes and many other types of motors need a reverse biased diode, and a small ceramic capacitor across it.
Yes I did try this but didn't appear to help too much. I ended up having to completely isolate the servo motors using a MOSFET. But it is something I will remember from now on working with DC motors.
How do you mean isolate the servo motors?
Can you please post a picture of your project and a schematic?
Please include power supply and all hardware connected.