DC Motor doesn't stop but reduces speed

I’m trying to test a simple regenerative braking system using a 1.5-5V motor controlled by Arduino Uno used to rotate a wheel for several seconds and stop the motor, a which point the Arduino will read the voltage produced by the motor (which is flowing back into the Arduino) because the wheel continues to spin due to its inertia. However, when I try to stop the motor in the program, it simply reduces its speed.
(Btw - I am new to this.)

I have connected the Arduino to the motor through a transistor, and the hardware layout is as follows: Analog pin A1 is connected to the left side of the transistor (facing away), though there is a resistor between them. Then, the right side of the transistor is connected to a ground pin on the Arduino. The middle pin of the transistor is connected to the motor through one of the motor’s wires (the black one in this case if it matters). Finally, the other wire from the motor (the red one) is connected to the 5V pin on the Arduino.

Here is the code I used for this:

float totalSum = 0;
float voltage;
float totalAvg;

void setup() {
pinMode(A1, OUTPUT);

void loop() {
pinMode(A1, OUTPUT);
digitalWrite(A1, LOW);
digitalWrite(A1, HIGH);
voltage = readVoltage();
Serial.print(String(voltage) + “\n”);

float readVoltage() {
pinMode(A1, INPUT);
int sample_count = 0;
int num_samples = 20;
float sum = 0;

while (sample_count < num_samples) {
sum += analogRead(A1);

float avg = sum/20;
float voltage = avg * (5.0 / 1023.0);
return voltage;
pinMode(A1, OUTPUT);

When I upload this to the Arduino and it runs, even though I used digitalWrite(A1, HIGH); to stop the motor, the motor simply reduces its speed. This problem occurs only with the readVoltage() call. If I remove it, the motor succesfully stops. What is the solution to this?


I am sorry to inform you that telling us something about the left side of a transistor actually tells us NOTHING. Please make a drawing of your circuit, scan it as a picture and post it to the forum so we can see what you are seeing.


Which transistor (out of tens of thousands)? Are the leads sticking up or down? Which side is the face? C’mon now, post a drawing. :slight_smile:

You must know what type of transistor you are using so tell us. You must also know which 'pins' are base, collector and emitter so use those terms not "the left pin".

If you don't know those things then the chance of you putting together a circuit that does anything useful is approximately zero.


(which is flowing back into the Arduino)

I hope you are wrong about that because it sounds like a good way to destroy your Arduino.


It sounds like a typical Arduino DC motor control circuit:
'T' is an NPN Transistor or N-Channel MOSFET
+5 to Motor+, Motor- to Collector/Drain of T, Emitter/Source of T to Ground. Base/Gate of T through a resistor to an OUTPUT pin. Set the pin HIGH to GO and LOW to STOP.

Reading the voltage at the Base/Gate of T is unlikely to tell you anything useful about the power coming from the motor acting as a generator. Have you looked at any articles on how to implement regenerative braking?

IF the OP ever shows a schematic it will probably show a diode across the motor leads. This immediately stops any regenerative braking capability.