Brushed DC Motor interference

Hi,
I am using NPN proximity sensors lj12a3-4-z/bx and motor controller VNH5019, they are connected as in the picture. When driving the motor on low pwm all is fine but when pwm is increased the motor will stop right at start in one of the directions never the other. These sensor have a indicator light, and at higher pwm I see the "wrong" sensor light come on at motor start and stop the motor, could this be because of interference? If I switch the sensors the problem follows the same sensor, could the sensor be faulty(I have tried two others with same result)? How do I suppress the interference, or is it something else?

Code used:

const int leftSwitch = 12; // Left Limit Swtich
const int rightSwitch = 11; // Right Limit Switch
const int MRight = 9; // Motor Right
const int MLeft = 10; // Motor Left

const int PWMpin = 8;
const int analogSpeedPin = A0;



bool direction = false;             //direction flag
unsigned long previousMillis = 0;   //will store last time offtime was reached
unsigned long previousMillis1 = 0;

long OffTime = 3000;                //milliseconds of offtime, waiting between turns
int Pot_value = 0;

void setup()
{
  pinMode (leftSwitch, INPUT_PULLUP);
  pinMode (rightSwitch, INPUT_PULLUP);
  pinMode (MRight, OUTPUT);
  pinMode (MLeft, OUTPUT);
  pinMode(PWMpin, OUTPUT);

  digitalWrite (MLeft, LOW); // Stop the motor.
  digitalWrite (MRight, LOW); // Stop the motor.

  Serial.begin(9600);
}

void loop()
{

  //=================================================


  Pot_value = (analogRead(analogSpeedPin));

  Pot_value = map(Pot_value, 0, 1023, 40, 100);
  analogWrite(PWMpin, Pot_value);

  //=================================================

  unsigned long currentMillis = millis();
  //stop motor if limitswitch on
  if (digitalRead(leftSwitch) == LOW && direction == false)
  {
    digitalWrite(MRight, HIGH); //With VNH5019
    digitalWrite(MLeft, HIGH); //With VNH5019
    direction = true; // change direction to right.
    previousMillis = currentMillis; // Remember time
  }

  //stop motor if limitswitch on
  if (digitalRead(rightSwitch) == LOW && direction == true)
  {
    digitalWrite(MRight, HIGH); //With VNH5019
    digitalWrite(MLeft, HIGH); //With VNH5019
    direction = false; // change direction to left.
    previousMillis = currentMillis; // Remember time

  }

  //Starts motor

  if (direction == true && (currentMillis - previousMillis >= OffTime))
  {
    digitalWrite(MLeft, LOW);
    digitalWrite(MRight, HIGH);
  }
  //Starts motor
  else if (direction == false && (currentMillis - previousMillis >= OffTime))
  {
    digitalWrite(MRight, LOW);
    digitalWrite(MLeft, HIGH);

  }
}

Well prepared posting, both proper code and schematics.

I suggest using Serial.println and serial monitor, Serial.println("Stop at pos. 1"); , stop at pos 2 etc.

Brush type motors can create voltage spikes when the commutator changes segments.

I suggest:

  1. 0.01µF across the motor at the motor wires. But no higher than 0.01µF due to the PWM drive.

  2. Keep the wires of the motor and driver well away from the sensors and Arduino

  3. connect the ground for each device to a single point on the 12V supply.

  4. Same as 3) but only really needs to be a the 12V+ for the runs to the motor power and all the other lines.

The schematic diagram does not show the required filter capacitors across the voltage regulator.

Also, see this article Pololu - 9. Dealing with Motor Noise

Forgot to mention the LM7805 is a module:
LM7805 Module on eBay

Also the pins D14 and D15 is wrong in picture :slight_smile:

I will try the suggestions, but I still wonder why not the other sensor is affected?

Hi,
The LM7805 is not a real 7805, it is a SMPS DC-DC converter replacement for the 7805.
I would be putting at least a 0.1uF cap between the output and gnd pin of the module.

How have you got your wires routed, have you kept your sensor wires away from the motor wires and their power supply wires?
You may need stronger pullup resistors than the approx 40K in the controller.

What model controller are you using?

Can you please post an image(s) of your project so we can see your layout.

What is your 12V power supply?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

I have used Serial.print and the program seems to work fine, motor will stop when sensor gives the arduino input a signal. So the problem is the sensor giving signal at wrong time ie when motor starts not when the sensor actually should be sensing. (It is a sledge going back and forth between the sensors).

I have yet not added caps on the motor, or on the SMPS converter, still need to try that. But what I did was take the power to the sensor from the SMPS converter and after that I have had no problems at all, even if it is only 5v and the sensors are 6v->

This article Pololu - 9. Dealing with Motor Noise suggests “Place decoupling capacitors (also known as “bypass capacitors”) across power and ground near any electronics that you want to isolate from noise.”

Should I add decoupling capacitors between the sensor power and ground?

Power supply I have tried is 12v car battery and 18v laptop power supply.
I am using a mega board.

In the picture is the connection I had when there was problems with the sensors. The Arduino is in another box a couple of meters away.

But as mentioned I will try to add caps to motor and see if it helps..

It looks like you input power (12V or 18v) is going to your sensors.
Its not clear what the Yellow + Red + Blue are doing. Are the connected in the white "shrink tubing".

You HW-275 board is not a SMPS, it looks like a motor driver. Can you supply a link to it?

The blue/red /yellow is going to the 5v SMPS converter, the HW-275 is the VNH5019 motor driver. In this picture the 12 or 18v is going to sensors.

OK so what does the SMPS power? It seems to only go to the motor driver. What voltage is this?

What you should do is separate the dirty ground (SMPS and Motor Driver) from the clean ground (Arduino and sensors)

Do you have a link to the SMPS?

The SMPS is 5volt and powers the motor driver. Link to SMPS in replay 5. Will try to seperate grounds.

Here's a quick sketch of how I think the best connection approach is.
Pardon the "roughness" of the sketch.

I will try your suggestion. What size should the capacitors be?

I recommend a 0.01µF and a 10µF of at least 35 volts.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.