1
\$\begingroup\$

Tinkercad schematics of my circuit

I am a material science student currently working on a project to build a simple circuit for controlling the speed of a DC motor. My goal is to avoid using motor driver modules by utilizing a MOSFET, as I don't need directional control and want to keep the design as straightforward as possible.

I drew a schematic in Tinkercad.

Here are the details of the components I’m using:

  • DC motor: 9-12V, rated current at 12V is 1.23A
  • Power supply: 12V variable voltage adapter
  • MOSFET: INFINEON IRL540NPBF
  • Flyback diode: SR5100 Schottky diode
  • Control components: Arduino Uno, potentiometer, pushbutton
  • Gate resistor: 100 ohms

I’ve also written the code for the circuit, which I’ve included below.

    int potState = 0;
    int buttonNew;
    int buttonOld = 1;
    int buttonDelayTime = 100;
    int butPin = 3;
    int potPin = A0;
    int ledPin = 11;
    int pot;
    int speed;
    float voltage;
    int motorPin = 9;
    unsigned long lastVoltagePrintTime = 0; 
    const unsigned long voltagePrintInterval = 100;
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      pinMode(butPin, INPUT_PULLUP);
      pinMode(potPin, INPUT);
      pinMode(motorPin, OUTPUT);
      pinMode(ledPin, OUTPUT);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      buttonNew = digitalRead(butPin);
      if (buttonOld==0 && buttonNew == 1){
        if (potState == 0){
          digitalWrite(ledPin, HIGH);
          int potValue = analogRead(potPin);
          voltage = (5./1023.)*potValue;
          speed = map(potValue,0,1023,0,255);
          analogWrite(motorPin,speed);
          potState = 1;
        }
        else{
          digitalWrite(ledPin, LOW);
          digitalWrite(motorPin, LOW);
          potState = 0;
        }
      }
      buttonOld = buttonNew;
    
      if (millis() - lastVoltagePrintTime >= voltagePrintInterval) {
        lastVoltagePrintTime = millis();
        if (potState == 1) {
    
          int potValue = analogRead(potPin);
          voltage = (5. / 1023.) * potValue;
          Serial.println(voltage);
        }
      }
      delay(buttonDelayTime);
        
    }

Desired functionality:

I want to control the DC motor. The circuit should only be on when I push the button and the LED lights up. Then I want to control the speed with a potentiometer through the MOSFET to regulate the DC motor speed

Working parts

The LED lights on and off when I push the button, with the motor, when the button is off (MOSFET pin set LOW.) The motor doesn't move and I read 0V in my circuit (I added empty pins in the same column of motor pins across my motor to read with a multimeter.) The potentiometer seems to print voltage between 0 and 5V when I turn it.

Problematic parts and troubleshooting

When I push the button, which should activate the circuit, the motor turns on for a second then off and this repeats constantly ('jerks a little bit', starts turning and stops etc.) Voltmeter readings across my motor show increasing voltage (to 2V) and then goes back to 0. I have a pretty cheap voltmeter with slow response, so, probably this influences the readings in this situation.

If I take out the motor and I try controlling the voltage with the potentiometer I get 11,5V across where the motor would be no matter what I do with the potentiometer and 7V with the button turned off.
I checked all the parts and wires and nothing seems to be broken.

I am not an electrical engineer so this is pretty new to me, this is what I tried troubleshooting and I am trying to be as clear as possible, but if something else is needed I will be more than happy to provide any information.

There has to be an obvious error that I am making somewhere, could someone please point me in the right direction of what I am I doing wrong, what could I do to solve this or if this approach is feasible?

Edit: I tried making a schematic of the circuit here. positive side of the voltage source is connected to the motor (I am not sure if I used a correct symbol here). I tried to draw it to show a common ground per the breadboard schematic, I hope it is correctly shown. diagram

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Please post real schematics. Pictures of breadboards are not helpful. Unrelated to that, "problems" and "breadboard" do tend to go hand in hand. \$\endgroup\$
    – Lundin
    Commented Aug 27 at 11:49
  • \$\begingroup\$ Use decoupling capacitor... \$\endgroup\$
    – Antonio51
    Commented Aug 27 at 13:21
  • \$\begingroup\$ The circuit should only be on when I push the button and the LED lights up. ... that says that the LED somehow controls the circuit and the button also controls the circuit \$\endgroup\$
    – jsotola
    Commented Aug 27 at 14:03

1 Answer 1

1
\$\begingroup\$

What I take is intended to be debouncing for the button is killing your PWM control.

  • When the pushbutton changes state (if (buttonOld==0 && buttonNew == 1)) then you set the PWM output according to the potentiometer value. That starts the motor.
  • The next time through the loop, buttonOld and buttonNew have the same value, so you set the motor output to LOW. That should stop the motor.

You need to work through the logic you've implemented and correct it to do what you intended.


Take it one piece at a time.

  • Do only the debounce and LED first. Get it to work as intended (LED turns on after the button debounce says the button is really pressed, LED off when the debounce says the button is released.
  • Once the LED works, you can better see where to put your motor speed control code.
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.