Motor Controller for Cordless Drill Motor

Ok, so I updated some code and attached the wiring diagram of what I've done. I plotted a serial output (also attached) to see what kind of data I'm getting from the current sensing pins. I'm just looking for curves that show a change when the motor feels an external load (i.e. my fingers holding the motor), so I don't necessarily need the analog readings (0-1023) to be translated into amps.

In the serial plotter picture, the parts that I've circled correspond to when I apply slight pressure to the motor shaft with my fingers (not enough pressure to stall). No matter how much pressure I put, I get a full 1023 reading. I want to see a curve corresponding to the amount of load I apply to the motor, but I seem to be getting readings that don't really make sense. Can anyone help?

/*
 * BTS7960 Motor Driver Code
 */

 int RPWM = 3;
 int R_EN = 4;
 int R_IS = A0;
 
 int LPWM = 5;
 int L_EN = 6;
 int L_IS = A1;

void setup() {
  //Set up input/output pins
  Serial.begin(9600); //Initialize Serial monitor
  pinMode(RPWM, OUTPUT);
  pinMode(R_EN, OUTPUT);
  pinMode(LPWM, OUTPUT);
  pinMode(L_EN, OUTPUT);
}

void loop() {
  digitalWrite(R_EN, HIGH);
  digitalWrite(L_EN, HIGH);

  digitalWrite(LPWM, LOW);
  digitalWrite(RPWM, HIGH);
  
  float currentR = analogRead(R_IS);
  float currentL = analogRead(L_IS);
  Serial.print(currentR);
  Serial.print(" ");
  Serial.println(currentL);
}

"No matter how much pressure I put, I get a full 1023 reading"

What do you expect to see from the current sensing part of the H-bridge? If you expect a voltage, have you checked with a multimeter to see what you are getting? Do you perhaps need a voltage divider or pot to get the voltage into an acceptable range for the A pins?

Hi,
As @zoomcat has suggested the current signal output from the driver module is more then 5V.
An analog input can only read 0 to 5V.
You will need to use a potential divider to scale the voltage to 0 to 5V.

Use you DMM and measure what voltage the module is outputting when you apply load to the motor.

Tom... :slight_smile: