Running Ground Through Motor Driver

So in a roundabout way I have two potentiometers, and one motor. I'm running the PS3 bluetooth library on top of this. The DC motor is connected to a motor driver that is passing 12v through to the motor. My problem is that to be able to run the motor two directions at 12v clockwise and counter-clockwise, I need the 12v and ground signals that run into the motor to switch. Here's my code:

#include <PS3BT.h>
#include <usbhub.h>
// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif

USB Usb;
BTD Btd(&Usb);
PS3BT PS3(&Btd);

#define MOT1pos 3
#define MOT1neg 5

void setup() {
pinMode(MOT1pos, OUTPUT);
pinMode(MOT1neg, OUTPUT);
Serial.begin(115200);
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while(1); //halt
}
Serial.print(F("\r\nPS3 Bluetooth Library Started"));
}

void loop() {
Usb.Task();
{
if (PS3.getAnalogButton(R2) > 0);
digitalWrite(MOT1neg, LOW);
analogWrite(MOT1pos, PS3.getAnalogButton(R2));
}
if (PS3.getAnalogButton(L2) > 0);
digitalWrite(MOT1pos, LOW);
analogWrite(MOT1neg, PS3.getAnalogButton(L2));
}

PS3.getAnalogButton(L2) and PS3.getAnalogButton(R2) are the potentiometers, and MOT1pos and MOT1neg are the motor leads. MOT1pos and neg are both going through the motor driver as well. When I try to drive the motor, both the ground and signal wires are outputting a signal, and I think this is because I'm trying to run a LOW signal through the motor driver. Any help would be greatly appreciated! XD

USEDIS.ino (754 Bytes)

Are you using an h-bridge motor driver? It will be very difficult to change the direction of the motor without one.

I believe so, here's a picture of it.

A photo isn't much use. Can you post a link to the specifications for the device. That will show the connections and enable people to advise you.

It would also be useful if you post a diagram of how you have everything connected. A photo of a clear pencil drawing will be fine.

...R

Sorry, completely slipped my mind. Anyway:
This is what I bought: http://m.ebay.com/itm?itemId=251080674810

And this is it's schematic: L298.jpg (image)

My setup is attached

Write a test sketch that does nothing but drive the motor and get that working before you try to use the motor in your main sketch. The picture you posted shows an L298 chip which is a dual h-bridge driver so you should be able to control the direction and speed of two motors, but exactly what I/O signals you need to output in order to do it will depend what inputs that board needs, and how it is connected to the Arduino. I would expect the board's supplier to provide documentation explaining how to use it.

I made literally the simplest of sketches and yet it still fails to run the motor in either direction.

void setup() {
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
}

void loop() {
digitalWrite(3, HIGH);
digitalWrite(5, LOW);
}

I don't know anything about the motor driver board you're using. Have you powered it correctly, connected the pins that need to be driven to the Arduino, also connected ground, and logic power if necessary, set any configuration jumpers on the board as required, and got to the point where you would expect pin 3 high and pin 5 low to do something?

Everything is connected exactly to my knowledge. The enable pins are jumped and 12v and ground are connected from the PSU. I have the pwm wires (3 and 5) connected to the input 1 and 2 on the driver, which IN THEROY should make output 1 and 2 copy whatever the input is giving it, whether that be a high or low signal. But that just isn't happening. Diagram attached.

97222937.jpg

legofan623:
Everything is connected exactly to my knowledge. The enable pins are jumped and 12v and ground are connected from the PSU. I have the pwm wires (3 and 5) connected to the input 1 and 2 on the driver, which IN THEROY should make output 1 and 2 copy whatever the input is giving it, whether that be a high or low signal. But that just isn't happening. Diagram attached.

I think if you are using an L298 with PWM that you usually drive the enable pin with the PWM signal and use the other two pins for direction control. Do you know whether it is is enabled with a HIGH or LOW voltage and have you measured the voltage on the enable pin?

...R

I'd imagine that it's enabled by HIGH because it can also be enabled by PWM, and I haven't measured the voltage on it and I won't be able to until tomorrow. do you think connecting the ground between the power supply and the Arduino would help or is it not necessary?

Is Arduino ground connected to logic ground on the driver?

I don't think so... And the arduino's power source and the driver's power source are different

That would be a problem, then.

legofan623:
I don't think so... And the arduino's power source and the driver's power source are different

You need to get the datasheet for the L298 to find out if it is necessary. Don't start connecting things you are not certain of.

...R

So I found this: How to use the L298N Dual H-Bridge Motor Driver

I never knew you were supposed to use the 5v out on the driver to power the arduino, which would also make the grounds common. And I'll try driving the enable pins instead of the direction pins.

in many of the cheap devices the ground for the 5 volt, the 9 volt, the 12 volt, the 24 volt.... are all tied together.

even the relay boards that have opto-isolators. not sure why these are made this way,

the L298 board you have should have a data sheet from the supplier, or from a similar supplier. if you got it on e-bay, search for that same photo from other sellers, you will find a connection diagram sooner or later.

http://www.ebay.in/itm/Dual-H-Bridge-DC-Stepper-Motor-Drive-Controller-Board-Module-L298N-for-Arduino-/171369616075?pt=LH_DefaultDomain_203&hash=item27e66cd2cb&_uhb=1

for many of the L298 dual-h-bridge boards, there is an on-board 5volt regulator. you have a choice to either use that for the logic voltage source or to use your 5v. in your case the seller says DO NOT SUPPLY 5VOLT, but 5volt out is available.

(as a note, there is an un-marked jumper behind the screw terminal. the notations say 5V enable)

that would mean you are completing the circuit by bringing the enable pin to ground in the Arduino.

the motor connections are the two 2-terminal screw connectors. for a stepper, each would be to a coil.

the 3 terminal screw is listed on the bottom of the board as 5v towards the center of the board, gnd as the center and 12v on the outside.

looks like you need to connect your arduino pins and connect the arduino ground to the center terminal in common with your power supply ground.

the board has 4 pins. for a regular DC motor, you can bring one to ground and the motor will get the voltage from the chip as provided by the power supply.

If it spins the wrong way, you can either swap leads, or bring the other pin on that side to ground and the driver chip will reverse the voltages and the motor will spin in the opposite direction.

In order to change speed, you can use a pulse or PWM signal on that pin. The duty cycle will be an approximation of your speed.