• 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.

About

Avatar for DrAzzy @DrAzzy started