1

I have 3 motor drivers and all 3 other them only seem to only work on one of the 2 sides. I have used a voltmeter to check the voltages across the each of the 2 sections on each motor driver. For all 3 of the motor drivers, 2 of them had one side which had a voltage of 5V (which should be 7.2 volts as thats the power supply) and the other sides of the 2 motor drivers was 0-0.05V (so effectively no voltage). The other motor driver had no voltage from either of the 2 sides. Are all 3 of the motor drivers faulty or have I broke them? The schematic for the motor drivers was as follows: enter image description here

(Apart from instead of a 12V source, a 7.2V source is used buts thats the amount of Volts I need for the motors. The arduino I used was an Arduino mega rather than an UNO shown in this diagram as I got this diagram off the internet) Heres a link for the place where I ordered the motor drivers from: https://thepihut.com/products/l298n-motor-stepper-driver

Here is my code:

    #include <PS2X_lib.h> //for v1.6
    int enA = 3;
    int in1 = 8;
    int in2 = 7;
    int enB = 9;
    int in3 = 5;
    int in4 = 4;
    int error = 0; 
    byte type = 0;
    byte vibrate = 0;
    int light_one_pin = 36;
    int light_two_pin = 38;
    bool lights_on = false;
    PS2X ps2x;
    void setup(){
     Serial.begin(9600);
     pinMode(enA, OUTPUT);
     pinMode(in1, OUTPUT);
     pinMode(in2, OUTPUT);
     pinMode(in3, OUTPUT);
     pinMode(in4, OUTPUT);
     pinMode(light_one_pin, OUTPUT);
     pinMode(light_two_pin, OUTPUT);
    
     //CHANGES for v1.6 HERE!!! **************PAY ATTENTION*************
     for(int x = 0; x < 100; x++)
     {
      error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error
     }
     error = 0;
      
    }
    
    void loop() {
      ps2x.read_gamepad(false, vibrate);
    
      if(ps2x.ButtonPressed(PSB_GREEN) && lights_on == false)
      {
         digitalWrite(light_one_pin, HIGH);  
         digitalWrite(light_two_pin, HIGH);  
         lights_on = true;
         Serial.println("on"); 
      }
      else if(ps2x.ButtonPressed(PSB_GREEN) && lights_on == true)
      {
          digitalWrite(light_one_pin, LOW);  
          digitalWrite(light_two_pin, LOW);  
          lights_on = false;
          Serial.println("off");
      }
    
      if(ps2x.Analog(PSS_LY) < 128)
        {
          digitalWrite(in1, LOW);//all fowards wheel
          digitalWrite(in2, HIGH);
          digitalWrite(in3, HIGH);
          digitalWrite(in4, LOW);
          analogWrite(enA, 255);
          analogWrite(enB, 255);
          Serial.println("forwards");
          
        }
    
        else if(ps2x.Analog(PSS_LY) > 128)
        {
          digitalWrite(in1, HIGH);//all backwards wheels
          digitalWrite(in2, LOW);
          digitalWrite(in3, LOW);
          digitalWrite(in4, HIGH);
          analogWrite(enA, 255);
          analogWrite(enB, 255);
          Serial.println("backwards");
    
        }
    
        else if(ps2x.Analog(PSS_LY) == 128)
        {
          analogWrite(enA, 0);
          analogWrite(enB, 0);
          Serial.println("stationary");
    
        }
    
        else if(ps2x.Analog(PSS_LX) == 128)
        {
            //Serial.println("still");
            //wheel_steering_servo.write(wheel_steering_servo_angle);
        }
    
        Serial.println(ps2x.Analog(PSS_LX));
        
    }
7
  • Please provide a link to the exact product that you are using for the motor drivers. And also show us your code. You can put those information into your question by editing it
    – chrisl
    Oct 15, 2021 at 18:16
  • 1
    @chrisl I have done that. Oct 15, 2021 at 18:25
  • You have an UNO with pin numbers 36 and 38, eh?
    – timemage
    Oct 15, 2021 at 19:47
  • 1
    @timemage Oh yeah sorry, my bad I forgot to mention it is an arduino Mega I am using Oct 15, 2021 at 20:32
  • the correct thing to do, is to edit your post, instead of providing important detail in comments
    – jsotola
    Oct 15, 2021 at 20:42

2 Answers 2

2

Just a correction to something Coder9390 wrote:

The ENA and ENB pins on this motor drive are not supposed to be used as digital pins and receive HIGH or LOW, but as analog pins and receive a value in range 0-255 using a PWM pin (PWM pins are marked on the board with a ~). This enables you to control the speed of the motor, by simulating low voltage.

In your code you actually seem to do this correctly, so I don't think this is the problem. Setting the pinMode of ENA and ENB to OUTPUT on the other hand is correct, so it might actually be the problem. I couldn't reproduce your bug this way though, so it might be something else.

In case you don't need to control the speed of the motor and want it to always go full speed, you can use jumpers to short each EN pin with it's orthogonal-adjacent pin (which are marked in your image as 5v) to achieve the same effect of connecting them to 5v "manually" as Coder9390 suggested (basically by placing the jumpers there you are doing exactly that - connecting the EN pins to 5v).

Coder9390, if you implicitly meant to suggest using jumpers like this, then sorry for misrepresenting your answer. I thought it wasn't clear to beginners who might get here, and that it requires an elaboration.

See this motor driver usage explained here: https://create.arduino.cc/projecthub/ryanchan/how-to-use-the-l298n-motor-driver-b124c5

1
  • Very true, I having not much experience with these board, only knew that they enable the outputs, not control the speed, good info 👌.
    – Coder9390
    Oct 21, 2021 at 10:57
1

There are a couple of things that you can check-

Your code-

Chances are that all of the motor drivers are functional (as manufacturing defects are very rare) and that there is something wrong with the code.

1- The motor driver that you are using has 2 pins that should be labeled "ENA", "ENB" (or some variant of these), in order for the motor driver to work on both sides, both these pins must be high, if any one of these are low, then that side will not work. I highly recommend that you directly connect these 2 pins to 5V, and use the 4 inputs for the control.

2- The 4 input pins labeled "IN1", "IN2", "IN3", "IN4" are the pins that instructs the driver to move each side forward or back, check your code to make sure that these pins are high or low as per your requirement.

Another thing is that both the forward and back inputs of one side must not be high at the same time otherwise it won't work

Your hardware-

If you find that something is getting abnormally hot on the boards or worse if something is burnt, then you should check your circuit and make sure there are no problems.

-- A problem in your code, is that "ENB" is not set as an output and hence is not high, you should also modify the setup to set the "ENA", "ENB" to high to make sure that it is on.

So your setup should go something like this-

     Serial.begin(9600);
     pinMode(enA, OUTPUT);
     pinMode(enB, OUTPUT);
     digitalWrite(enA, HIGH);
     digitalWrite(enB, HIGH);
     pinMode(in1, OUTPUT);
     pinMode(in2, OUTPUT);
     pinMode(in3, OUTPUT);
     pinMode(in4, OUTPUT);
     pinMode(light_one_pin, OUTPUT);
     pinMode(light_two_pin, OUTPUT);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.