• Espruino newbie here. My project requires me to periodically drive a vibration motor, something like this: https://catalog.precisionmicrodrives.com­/order-parts/product/310-114-10mm-vibrat­ion-motor-13mm-type

    I'm using a 3.7v Lipo battery. The motor at that link above says it's 3v.

    The motor doesn't need to change speeds or directions. It just needs to come on for a few seconds every now and then.

    I'm confused about whether I need a L293D, a ULN2003, a Relay, or if that's all overkill and if I can just hook up the wires to some pins on the board and do a "digitalWrite()"?

    Any tips? Thanks!

    John

  • You cannot just do digitalWrite() - the rated operating current is 250ma, which the Espruino cannot supply.

    The next question is whether the motor can be run directly off the LiPo battery (which could put out up to 4.2v at full charge). If that's too much (read the spec sheet - somewhere it will list a maximum operating voltage), you need a way to lower the voltage. You could use a 3.3v LDO regulator (these are common and good things to have on hand anyway), but I'd be worried about whether the "Low drop out" was low enough (would have to check datasheets). You could even just put a diode in series with it, to drop the 0.7v or so, or a schottky diode to drop 0.3v. Or, since you know the current should be around 250ma (but ofc this will depend on voltage), and use a resistor of appropriate resistance (somewhere around 1-4 ohms, depending on how picky it is about the voltage it gets fed).

    As for driving it, you need either a ULN2003/2803, a MOSFET, or a transistor of some sort.

    Actually, if you're using a ULN2003, you might not even need the resistor/diode/etc - those things drop some voltage internally.

    If using a ULN2003, the wiring is pretty obvious.

    If using an N-Channel MOSFET, gate goes to the Espruino output, source to ground, and the drain to the negative side of the motor. Put a 10k ohm resistor between gate and ground to keep it turned off when you're not turning it on. Note that many N-channel mosfets (and in fact, anything I could find that has nice big easy-to-solder leads) don't work very well with a 3.3v gate drive. There are lots of great mosfets that work on 2.5 or even 1.8v gate drive, but they're all in annoyingly small packages. Luckily, SOT-23 package is the right spacing to solder down to the Espruino's SMT prototyping area. So - make sure you use a mosfet where the datasheet shows specs for a gate voltage of 3.3v or lower. The Vishay SI2312 is cheap as dirt and will easily handle this load, though the SI2356 is still under 50 cents a pop, and has higher specs that might be useful on a future project.

    The L293D would also work, but it's a bit more complexity than you probably want.

  • So, probably my two best options are:

    Option 1. Go with the ULN2003 and follow these instructions: http://www.espruino.com/ULN2003

    It seems reasonably straightforward. The + / - wires on the motor seem to go in the pink area of that diagram. Although, I have no idea what this part means:

    "Note: COM is connected to each output (1-7 C) via a diode. If you're driving inductive loads then you can connect it to the other side of the load being driven, and it will help to clamp the Back EMF generated when the load is turned off. For instance if you are powering your load from BAT, just connect COM to that."

    Option 2. Use one of the MOSFET thingys. Is there a tutorial somewhere that shows what to solder to what, including where the motor wires go?

    Thanks!

  • The bit about COM - if you're driving an inductive load (like a motor), you should connect the positive side of the supply (for whatever you're powering) to that. That way, when you turn off the load the voltage spike won't exceed the supply voltage.

    There are no doubt many tutorials about using mosfets in various contexts. I don't think there's one specific for the Espruino.

    I just took that pic of one sitting on an Espruino

    Wiring:
    Source of MOSFET to ground.
    Drain of MOSFET to the negative side of the load.
    Gate of MOSFET to whatever pin you're using to control it.
    10k resistor between gate and ground
    Positive side of power source to positive side of the load (through a diode or 1 or 2 ohm resistor - I read the datasheet, and it says 3.5v max on the motor).
    For good measure, I'd put a diode across the motor terminals (with the band towards the positive side) for same purpose as the diode in the ULN2003 above. Might not need it, but diodes are cheap.

  • I added some labels to the diagram. Here are my guesses as to what solders to what for 1-7:

    1. Non-band side of diode - not sure where this goes
    2. Band side of diode - solder to the positive side of the motor (3)
    3. Wire to the positive side of the main 3.7v power source. You mention another diode tho?
    4. Use wire to connect to any pin in "General purpose IO Pin" section here: http://www.espruino.com/EspruinoBoard
    5. Drain - connect to 7
    6. Source - use a wire to connect to the board's "GND" terminal.
    7. Negative side of motor - connect to 5 (drain)

    Except for #1, does that look right?

  • That looks good - I'd wire:

    1. To Battery 3.7v
    2. yes - to motor positive (3)
    3. to diode (2)
      4,5,6,7 as you suggested

    So the diode will drop 0.7v of the 3.7v. The other diode was so that if there's a voltage spike when the motor is disconnected, it's soaked up in the diode. To do that, simply connect it backwards across the motor (so the band side is on motor +).

    Only other thing I'd say is to connect the battery to the actual JST battery connector if at all possible. Espruino's got some circuitry to automatically switch between the JST connector and USB for power, but if you connect to the (slightly misleadingly named) 'Bat' on the pins, when you plug in USB and the battery, it'll be trying to put 4.3v into the Li-Ion battery, which is going to be bad news if it's left in for any length of time.

    1. Non-band side - goes on negative side of the motor. (When a motor (or other inductive load) is turned off, a brief voltage spike will be produced at the negative side - this diode will prevent it from getting above the supply voltage.

    2. Yeah, just something in series with the motor to drop a bit of voltage and keep the motor within spec. Either a 1-2 ohm resistor, or a diode (in the forward direction, ie, with the band towards the motor) would do the trick.

    Looks good.

  • Guys, this is great help. Thank you so much.

    I feel that I need a primer on how volatage/watts/amps work and how to tell what I need to do to connect things to other things and to the Espruino. Is there a quick resource you could recommend, other than going back to school? :)

  • So, I got this all working, including adjusting the speed with PWM. I used a 5V/500mah power supply. So far so good.

    For a different iteration of the project, I needed to change the motor out and use this one: https://www.adafruit.com/products/1150. This motor is 12v and uses 200-300ma of current.

    A few other components in the project require a lot of power, so my power supply is 12v/5 amps.

    Here's the problem. With everything wired exactly as indicated above, it doesn't work very well with the new motor. It's set up so that when I press a button on the Espruino, an LED is lit and the motor is turned on (via PWM on the pin attached to the mosfet's gate). Instead of nice smooth motor power, the motor is very choppy and the LED starts blinking off and on in sync with the motor cutting out. It's almost as if there's not enough power for both the Espruino and the motor. But, the power supply is 5A and I disconnected everything else, so that's ridiculous.

    I've tried various PWM duty cycles and frequencies and I can't seem to smooth out the motor.

    What am I doing wrong?

  • That does sound like there's some issue with the power supply... You could try adding a capacitor onto the Espruino board across where the power supply attaches.

    Have you connected the power supply as in the image above? If you connected it to the actual battery JST connector then there's a 1A self-resetting fuse that could be causing problems.

  • Gordon, do you think that it's possible TOO much current is being drawn and that the power supply is shutting down to protect itself?

    Also - what kind of capacitor could I try and where could I insert it into the circuit?

  • The power supply definitely isnt, unless you got a defective unit (or the motor is shorted or something)

    Maybe the Espruino's self-resetting fuse is tripping - but if that's the case, i'd say your motor is drawing more current than you think it is, or the self-resetting fuse doesn't tolerate inductive loads well. In any event, you can bypass this by just connecting the + side of the motor to the power supply, rather than the espruino's VBat pin. That's probably better in general, as it provides less of a path for noise to get into the Espruino.

    Did you remember the diode across the terminals of the motor to clamp the back EMF? PWMing a DC motor will put a lot of noise on the power line.

    I'd put the filter cap between power and ground where it enters the Espruino. Could even solder it onto the board onto the pins of the JST connector (probably make sure it fixes the problem first, though ;-) )

  • I did NOT remember the diode. I will add it.

    What size capacitor? And in general, how would I calculate what type of capacitor I need?

    Thanks!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

How to: simple motor connection (real post this time)

Posted by Avatar for lavamantis @lavamantis

Actions