MX1508 With Arduino and Single Motor

by Paramprakash in Circuits > Arduino

57 Views, 0 Favorites, 0 Comments

MX1508 With Arduino and Single Motor

components.jpg

There are not many tutorials about the mx1508 online (like almost none). They are very cheap to use and quite small too. The best thing about them is that they support voltages from as low as 2v which makes them perfect to use with 3.7v motors as well as their capability to supply 1.5A per motor (perfect for dc coreless motors!!).

So I wrote this instructable as an example for controlling a motor with mx1508 and potentiometer. Do give it a like if it helps you!!

Supplies

components.jpg
images.jpg
MX1508-DC-Motor-Driver-Pinout.jpg
Breadboard.jpg
ETR-103-Arduino-Nano.png
image_2024-12-04_171112016.png

1) Arduino

2) MX1508 motor driver

3) Dc motor

4) Jumper wires

5) Arduino cable

6) Potentiometer

7)Breadboard

Thats it

Connections

Mx1508 1.jpg
mx1508 2.jpg

1) Arduino pin A5 to potentiometer middle pin

2) 5v to Potentiometer 5v and mx1508 +ve [Note that the motor should not take too much current, recomendation is to use a separate battery pack for the motor to prevent burning out your arduino)

3)D9 to IN1

4)D10 to IN2

5) Motor A to Motor connection

MX1508 Library

Install the mx1508 library by Cheng Saetern

https://github.com/Saeterncj/MX1508


This library allows us to easily use the mx1508 with arduino and motors. It has very basic commands such as

1)cwDirection = true/false allows us to set the direction of the motor

2)motor(A/B).motorGo(pwmvalue) this sets the speed of the motor in accordance to the analog input

3)MX1508 motorA(PINA,PINB, FAST_DECAY, NUMPWM)

Code


#include <MX1508.h>

#define PINA 9
#define PINB 10
#define NUMPWM 2

const int potpin = A5;
// MX1508 schematics(in Chinese) can be found here at: http://sales.dzsc.com/486222.html
/*
* MX1508(uint8_t pinIN1, uint8_t pinIN2, DecayMode decayMode, NumOfPwmPins numPWM);
* DecayMode must be FAST_DECAY or SLOW_DECAY,
* NumOfPwmPins, either use 1 or 2 pwm.
* I recommend using 2 pwm pins per motor so spinning motor forward and backward gives similar response.
* if using 1 pwm pin, make sure its pinIN1, then set pinIN2 to any digital pin. I dont recommend this setting because
* we need to use FAST_DECAY in one direction and SLOW_DECAY for the other direction.
*/
MX1508 motorA(PINA,PINB, FAST_DECAY, NUMPWM);

void setup() {
Serial.begin(115200);
}

void loop() {
// put your main code here, to run repeatedly:
int potvalue = analogRead(potpin);
int pwmvalue = map(potvalue,0,1023,-250,250);

static unsigned long lastMilli = 0;
static bool cwDirection = true; // assume initial direction(positive pwm) is clockwise

if(millis()-lastMilli > 50){ // every 50 millisecond
if (cwDirection && pwmvalue > 100 ) {
cwDirection = false;
} else if (!cwDirection && pwmvalue < -100) {
cwDirection = true;
}
motorA.motorGo(pwmvalue);
lastMilli = millis();
Serial.print("Potentiometer value : ");
Serial.println(pwmvalue);
}

}

Upload to Arduino

Upload the given code to Arduino.

Done!!!

Downloads

Afterthoughts

I am thinking about using this motor driver to modify a cheap rc car of mine and make it speed controlled using nrf24. If it works out, will upload an instructable for the same!!


Good Day!