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);
}
}
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.
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?