Go Down

Topic: Motor unexpectedly moving at reset (Read 492 times) previous topic - next topic

windard

I'm playing with the standard L298N motor board and Arduino MKR 1000. However something strange happens: when I upload a new firmware and when I turn on the Arduino power supply (every time Arduino resets) the motors unexpectedly move for 2 seconds.



From what I've seen in other questions, it should be enough to pull down the pwm signal (in fact it seems that the floating status of these pin in the reset procedure produces this problem). I used a 10k resistor as suggested, but with no effect.

I've tried also a 100 ohm resistor: in this case the motor makes some noise but it doesn't move. However, it won't move when it is supposed to in the loop section.

I've also tried to pull down all the three signals (enable, in1, in2) of the motor but with no difference. I've also tried to pull up to 5V, instead of pulling down: same issue at reset, but the motor spinning in the other direction.

I've also tried to put a relay controlling the motor external supply. However the reset procedure also turn 'on' the relay (no progress on the problem).

It isn't a software issue because it happens with an almost empty sketch. Same software+circuit on Arduino UNO doesn't cause the problem.
What should I do?


jremington

#1
Jun 09, 2018, 06:28 pm Last Edit: Jun 09, 2018, 06:29 pm by jremington
Quote
What should I do?
Post the code, using code tags, and a complete wiring diagram (not Fritzing).

wvmarle

Definitely related to the floating state of the pins upon reset/boot, need complete schematics to see what could possibly be wrong.

Pulling down ENA and ENB should be enough to disable the motors.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Southpark

#3
Jun 09, 2018, 09:02 pm Last Edit: Jun 09, 2018, 09:53 pm by Southpark
I'm playing with the standard L298N motor board and Arduino MKR 1000. However something strange happens: when I upload a new firmware and when I turn on the Arduino power supply (every time Arduino resets) the motors unexpectedly move for 2 seconds.
Maybe you can see what happens ..... for a start ... when you have a bare minimum firmware upload..... such as have a setup() code only and nothing in the loop() code. For the setup code.... do something simple, like set the arduino's output pins to all '0'. And then load the code to the arduino.

If the motor's don't move when you start the arduino (or reset), then at least you can home-in on the issue more quickly.

Appropriate initialisation of a control system can be important for making your controlled device operate in the way we want upon system startup. Also... if using external or internal pullup resistors....need to make sure they're doing what you want them to do..... and make sure that the initial settings you choose for the system are suitable ones.

windard

This is one of the sketch I wrote dealing with this issue. There's also a servo attached, but the problem is completely independent from it (tested).

The motor is powered with a 7.5V separated supply. Its ground is not connected to the arduino GND. The problem (motor moving at board initialization) happens also with connecting them.

Code: [Select]

#include <Servo.h>
#define ENA 11
#define IN1 6
#define IN2 7
#define SERVO_PIN 5
Servo myservo;  // create servo object to control a servo


void setup() {

  pinMode(ENA,OUTPUT);
  digitalWrite(ENA,LOW);
  pinMode(IN1,OUTPUT);
  pinMode(IN2,OUTPUT);

 // Starting the motor
  analogWrite(ENA, 200);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);

  myservo.attach(SERVO_PIN);

  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  delay(1500);

// Stopping the motor
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
}

void loop() {
 myservo.write(90);
 delay(2000);
 myservo.write(120);
 delay(2000);
}

wvmarle

Where's the circuit diagram?

And what happens if you do absolutely nothing to the motor pins in the sketch? Strip it down to:

Code: [Select]

#include <Servo.h>
#define SERVO_PIN 5
Servo myservo;  // create servo object to control a servo

void setup() {
  myservo.attach(SERVO_PIN);
}

void loop() {
 myservo.write(90);
 delay(2000);
 myservo.write(120);
 delay(2000);
}
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

windard

Where's the circuit diagram?

And what happens if you do absolutely nothing to the motor pins in the sketch? Strip it down to:

Code: [Select]

#include <Servo.h>
#define SERVO_PIN 5
Servo myservo;  // create servo object to control a servo

void setup() {
  myservo.attach(SERVO_PIN);
}

void loop() {
 myservo.write(90);
 delay(2000);
 myservo.write(120);
 delay(2000);
}


Tried your sketch, with no luck.


Circuit is as follows:

jremington

Please post a correct hand drawn diagram, not an incorrect, useless Fritzing diagram.

wvmarle

Tried your sketch, with no luck.
No luck in what way? What actually happened?

Quote
Circuit is as follows:
Indeed doesn't look correct or complete. Where are the ENA and ENB pins? Doesn't the Arduino have power supply? Are you really using a such a 9V battery to operate a motor? Must be a very small motor!
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

windard

I hope this will be useful..
.


Well, the motor supply is a wall supply but I didn't think it was relevant..

Arduino is USB powered..

The sketch provided reproduced the problem with no change (motor unwillingly moving at initialization / reset).

Southpark

#10
Jun 11, 2018, 12:02 am Last Edit: Jun 11, 2018, 12:05 am by Southpark
See what happens (for testing) when you physically connect the ENA pin and the ENB pin of the L298N directly to GND (0V). This is with GND of L298 connected to GND of arduino, and these are connected to ENA and ENB. Here, we expect no motor activity upon power-up.

If this is all good, then we can move onto looking at the states (and setup - software and hardware) associated with the arduino pins that are going to control ENA and ENB.

wvmarle



Well, the motor supply is a wall supply but I didn't think it was relevant..
This may or may not be relevant - which is why we always ask for a COMPLETE schematic. More often than not it turns out that the problem is in the parts you didn't show.

One issue with the schematic: ENA is connected to pin 2, but you sketch uses pin 11.

The sketch provided reproduced the problem with no change (motor unwillingly moving at initialization / reset).
Which is really odd as the sketch doesn't do anything with the motor pins. So nothing is supposed to happen at all. The pins are by default set to INPUT upon startup.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up