Arduino as potentiometer

I am trying to control some 48v motors using this motor controller: https://www.banggood.com/40A-2000W-PWM-DC-Motor-Controller-Reverse-Speed-Switch-Forward-and-Reverse-Motor-Speed-Controller-RC-Reverse-Control-Switch-12V-24V-36V-48V-p-1723672.html?cur_warehouse=CN&ID=6292600
The problem is that it uses a potentiometer to control the speed of the motor. The potentiometer is 100k ohm, and it is 5v between the two terminals. My idea for controlling it was to use a voltage DAC (MCP4725) to vary the signal wire of the potentiometer between 0-5v. However, I cannot get it to work. The DAC is mounted so that the GND are connected to the GND of the potentiometer, and the OUTPUT to the signal wire. That is all the connection, am I missing something that doesn't make this work?

And what do you get when you measure the voltage on the signal wire?

Could you please post a complete wiring diagram, showing how you have connected each component. It can be hand drawn.


Note that the potentiometer drawn are only there to show how the potentiometer was connected to the controller, it is now remowed

Do you mean when I measure the signal wire when the potentiometer is turned?

Hi,

Between OUT and GND.

What is your code?
Can you please post your complete code?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Yes. How close does it match the same wire from the 100k pot?

It goes between 0-5v measured over GND and OUT on the potentiometer.
Here is the code:

#include <Wire.h>
#include <MCP4725.h>
MCP4725 leftMotor(0x60);
MCP4725 rightMotor(0x61);

const int leftPin = 7;
const int rightPin = 8;
const int deadzone = 5;
bool _interruptTriggered = false;

void setup() {
  attachInterrupt(digitalPinToInterrupt(2), ESTOP, FALLING);
  Serial.begin(115200);
  pinMode(leftPin, INPUT);
  pinMode(rightPin, INPUT);
  leftMotor.begin();
  leftMotor.setPercentage(100);
  rightMotor.begin();
  rightMotor.setPercentage(100);
}

int readChannel(int channelInput, int minLimit, int maxLimit, int defaultValue) {
  int ch = pulseIn(channelInput, HIGH, 30000);
  if (ch < 100) return defaultValue;
  int value = map(ch, 1000, 2000, minLimit, maxLimit);
  if (abs(((maxLimit + minLimit) / 2) - value) <= deadzone) return defaultValue;
  return value;
}

void loop() {
  if (_interruptTriggered) {
    leftMotor.setValue(100);
    rightMotor.setValue(100);
    delay(50);
    Serial.println("STOP");
    while (1);
  }
  int leftValue = readChannel(leftPin, -50, 50, 0);
  leftValue = 100-leftValue;
  leftValue = constrain(leftValue, 50, 100);
  int rightValue = readChannel(rightPin, -50, 50, 0);
  rightValue = 100-rightValue;
  rightValue = constrain(rightValue, 50, 100);

  Serial.print(leftValue);
  Serial.print("\t");
  Serial.println(rightValue);
  leftMotor.setPercentage(leftValue);
  rightMotor.setPercentage(rightValue);
  delay(5);
}

void ESTOP() {
  _interruptTriggered = true;
}

EDIT: The voltage measurements in this reply is wrong!

Some additional information: when the MCP4725 outputs 0 volts, the motor turns at max speed. When I increase the voltage, (only by a small bit, like to 1v), then the motor stops running. So it only runs (at max speed) then the DAC does not output any voltage.
Measuring over the potentiometer between OUT and 5v (between Terminal 1 and Terminal 2, there is a 5v difference, so I think it is a 5v output(?)) gives values of like -8.5v, isn't that a bit strange?
Between the Terminal 2 (which I called 5v) and the ground of the arduino / ground at the DAC there seems to be a 9v difference(?).
I am very confused...
Please help, thanks in advance :wink:

Hi,
With the 4725 not connected to the motor controller, connect the pot.
Use your DMM to measure the voltages across the outside terminals of the pot as you adjust it.

Having established which of the two is negative, use that as reference and measure the wiper voltage as you adjust the pot.

How are you powering the motor controller?
Is one of the pot terminals on it connected to gnd or batt -ve of the motor controller supply.

I think we need a more elaborate schematic with power supplies and the other hardware involved.

Tom... :smiley: :+1: :coffee: :australia:

If you take 1.5v battery and connect between ground and out on the motor regulator without any pot or dac connected, do you get different speed? what if you use 2x1.5v in series? 3x1.5v?

Me too.
You havent labelled the connections to the controller, so we are having a hard toime interpreting your results.
You havent shown the psu or motors.
Why do you suppose you can connect the arduino 0V to the controller?

Yes, that value (between the terminal which is ground and the wiper) is between 0v (motor running full speed) and 5v (motor running at lowest speed)

The motor controller is powered by a 48v li-lon battery
After some measurements of continuity, there is no connection between the gnd of the pot, and any other part of the motor controller. Same with the other terminal and wiper.

Well, I do not know how the motor controller works internally. I have tested with a 24v battery and 24v motor, same problem. I can draw a schematic, but I am not sure that it would add so much more information

Good idea!
When the three wires of the potentiometer are separated, the motor runs at full speed.
If I only touch the GND or the Wiper of the potentiometer, the motor stops.
I tried to connect the GND and Wiper/signal wires to the 1.5v battery, the speed of the motor did not change.

This is the way I think we can imagine the motorcontroller working with the potentiometer. (I know that it is more complex than just connected to the motor though)

So I tought that I could control it like this: (In tinkercad, controlling it like this worked)

The psu is a 48v li-ion battery, the motors doesn't seem to matter.

In the drawn schematic the wire connected to the middle of the potentiometer is the Wiper (OUT on the DAC), and the GND of the potentiomer is connected to the GND of the arduino. (Note that the potentiometer is removed when I try to control it using the DAC.

When the wiper is positioned so that there is no resistance between the GND and the Wiper of the potentiometer, there is a 0 volt potential difference between the two. When there is no resistance between the 5v pin on the potentiometer and the Wiper, there is a 5v potential difference between the GND and the Wiper. That is at least how I understand it

I was able to measure the strange voltage results I got a bit better now.
This is how it works:
article-2021may-the-fundamentals-of-digital-fig1

There is a constant 5v differential between GND and Vcc (as in the picture over)
If I set the GND of the multimeter at the GND of the potentiometer, I get a reading of (for instance) -3v between it and the Output. If I then set the GND of the mulitmeter at the Output of the potentiometer, I get a reading of 8v between it and the Vcc.
The voltage difference I got to the arduino (which I said was 9v in the earlier reply) is the same as the reading of 8v (between the Output, and Vcc of the potentiometer)

The DAC was connected:
DAC-GND to potentiometer-Output
DAC-OUT to potentiometer-GND

Hi,

So you will not be able to use a grounded pot like the 4725 to control your motor controller properly.

No we don't assume that, but all the hardware around it like the motor supply and the gnds and UNO connections and terminal/pin labels.

Looking at the AliExpress, it looks like it is designed for a very simple electric outboard motor, trolley etc.
The images on that page do not look very encouraging towards assembly standards for a start.
The Q&A answers are not the most explanatory either except its okay for an E-Bike.

The controller does not seem to have any current limit either, are you powering from the Lipo through a fuse?

It says;

With positive and negative switch, potentiometer knob with switch, you can use PLC to control positive and negative.

Yes you can control direction with a PLC but not so much the speed.

A solution would be an array of resistors and opto-couplers, to provide a substitute for a pot.
But that depends on how fine you want to control your speed.
What is the motor part of?

Tom.... :smiley: :+1: :coffee: :australia:

Your assumption how it works is wrong, therefore your approach is wrong. you need to find circuit diagram of the motor driver. Alternatively you can create a powerful driver using mosfet and drive it from arduino directly with pwm

Since the motor controller I am using is called PWM controller, doen't that mean that there is some circuit that translates the potentiometer input to a PWM signal. If that is the case, maybe I could bypass that circuit, and apply PWM from the arduino straight?

No, Arduino cannot drive motors directly, you just burn it