Controling a vibrating motor linked to a USB-powered PWM frequencency modulator

Hi !

I'm looking to make a motor vibrate at a given frequency and intensity, and to be able to turn it ON and OFF at given timepoints thanks to an Arduino UNO R2 controled by PyFirmata.

I tried to run my code by making a LED blink through the StandardFirmata on my Arduino and it worked just fine, but problems started when I tried to add my motor to the circuit.

The vibrating motor is linked to a PWM generator, to modulate the motor's vibration frequency and intensity (depending by the input voltage, defined by the duty cycle on the generator). The PWM modulator VIN+ and VIN- was soldered to be powered by USB without the need of the Arduino. I want to mention the motor vibrates just as it should when it is connected to the PWM generator only and powered through USB. Problems come when I want to command when it should be ON or OFF by Arduino.

I tried to replicate the circuit I made on Tinkercad and Powerpoint. I got inspired by the 9th project of the Arduino starter kit making a motor rotate with a 9V battery.

My intuition is that the problem is about voltage reaching the motor, but my knowledge of electronics are kinda limited. So far, the motor works for like 3 seconds as it should, and it stops.

PWM characteristics are in the linked image.

Motor characteristics are the following :
-Nominal voltage: 5.0VDC
-Operating voltage: 3.0 - 5.3VDC
-Rated speed: min. 9000 rpm
-Rated current: 60mA max.
-Inrush current: 90mA max
-Starting voltage: DC3.7V
-Insulation resistance: 10Mohm
-Ideal for DIY projects

Do you have any idea on how to make this project work?
Thank you by advance!

A little neuroscientist looking for help for their thesis.

My best guess is there's an error in your code.
Which you didn't post.
Also pin 2 doesn't do PWM. Use one of the pins marked ~.

Hi,

I uploaded the StandardFirmata code to my Arduino and managed to make a LED blink (3 times, 2 sec HIGH, 10 sec LOW).

Here is my Python code to control it.

import pyfirmata 
import time

arduino_port = 'COM5'

HIGH = True# Create a high state for turn on led 
LOW = False # Create a low state for turn off led 
board = pyfirmata.Arduino(arduino_port) # Initialize the communication with the Arduino card
Vibrator_pin = board.get_pin('d:2:o') # Initialize the pin (d => digital, 2 => Number of the pin, o => output)

for i in range(3): # Loop to blink the LED 3 times
    Vibrator_pin.write(HIGH) # Turn on the led
    time.sleep(2) # Delay of 2 seconds
    Vibrator_pin.write(LOW) # Turn off the led
    time.sleep(10) # Delay of 10 seconds

The PWM is not arduino-generated, but generated by an external part (what I call the PWM generator above) that allows me to change its duty cycle and vibration frequency. I hope that helps better to understand my problem. To close the circuit generated by the external PWM generator thanks to the MOFSET transistor, as far as I understood, a "HIGH" digital signal should be OK so the pin controling it doesn't need to be ~/PWM, but feel free to tell me if I'm wrong.

I also want to mention that, as I wanted to see if the code was the problem, plugging the arduino power input from 5V instead of the pin 2 can make the motor vibrate for few seconds before it stops.

If you have any other question or if I'm not clean enough, don't hesitate to ask me.

What MOSFET are you using? Some are designed to turn on/off at higher voltages than +5V from the adruino. Some are designed to work with 5V input signals. These are usually referred to as logic-level transistors or TTL-compatible transistors.

Hi blh64!

I'm using the one included in the Arduino Starter Kit.

I also have a BC547B transistor from what I'm reading on it, if that can help to solve the problem.
https://pdf.datasheetcatalog.com/datasheet/fairchild/BC547B.pdf

I'm not really familiar with how transistors work, but that sounded like a good idea to use one for my project so I'll be interested to have your feedback~

That Mosfet (although commonly used with arduino) is not suited for logic level. It is an IRF520. The logic level version of that is IRL520 (L = logic level). If you look at the datasheet, all the performance specs and graphs are defined as Vgs = 10V (The amount of voltage applied to the gate). You are only applying 5V so the Mosfet is only partially turning on.

The BC547B transistor is a very different type of transistor. It is a bipolar junction transistor (BJT) v. a MOSFET. It would work as well if your motor only draws a max of 90mA

Oh well, that's a useful information, thank you very much! At it was used in one of the official basic Arduino projects, I didn't expect it to not work as intended being powered by the 5V of the Arduino.

According to the vibrating motor sheet, its rated current is 60mA max, and its inrush current is 90mA max. So according to what you said, maybe the BC547B transistor might be good? Then, do you have any idea if I can just replace the MOSFET by the BC547B or the circuit needs to be change, and how?
I've seen people using resistance between the arduino pin digital output and the middle input of this type of transistor but my knowledge of electronic being limited, I don't have a clear understanding of how this work. I would be really thankful for you to explain me how it works if you know how to deal with this.

Otherwise, do you know the reference of another MOSFET-like transistor that could fit my requierment?

Have a nice day!

if you want to use this transistor, it will be different than a mostfet. BJTs are current driven devices rather than voltage driving. That is why there is a resistor between the arduino pin and the base of the transistor. From a datasheet, you want around 5-10mA flowing into the base. Your arduino pin is at 5V, the junction from base to emitter is .7V so you need to drop 4.3V across the input resistor
Rin = 4.3V/10mA = 430 ohms or 4.3V/5mA = 860 ohms
So you input resistor should be somewhere in there. The exact value isn't critical.

Connect the collector to 5V and the emitter to the V+ of your motor.

Hello blh64,

Thank you for all of these informations. I checked where was the base, collector and emitter pins on the BC547B transistor, and tried to plug everything according to what I understood of what you said. But as I am pretty unsure of what I did (I tried to plug it on the arduino 5V port instead of pin 2 and it didn't work), I let you judge of the circuit. Tinkerpad didn't close the circuit on the left when I tried to replicate it, and maybe that could help me to find where the problem is from?

I used a 560ohms resistor, but I'm not sure I put it where it is supposed to be. I removed the diode for now, but maybe I should add it back, but where?

Thank you again for helping me, very needed and appreciated!

You have to switch the positions of the transistor and the motor. Now you're switching high side, and with an NPN transistor you have to switch the low side. So positive to the motor, to the transistor, to the negative.

If you want to do a simple breadboard test: connect the base of the transistor, via the resistor(!), to the ground and the motor should stop; to the +5V and the motor should start running. That's basically what the Arduino pin is doing as well: when HIGH it connects to the 5V, when LOW it connects to the ground. With the caveat that an Arduino pin and source or sink no more than 20 mA of current.

Hi everyone,

Thank you all very much for your help. The last scheme I sent was the good one, despite the fact I misconnected the resistor on it (silly me...). I had to change the motor because all of my tests ruined the first one, but at least it works now! :smiley:

I will now close the post.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.