Getting 3v motor to work with photon * 2n2222 transistor

I need some help controlling this hobby motor. I’m using the 2n2222 transistor, 1k ohm resistor, and a 1uf diode. I posted some pictures below. The motor only turns on if I have one to diode + and then one to ground. But inwant to be able to control it via the digital pad. Right now when I do get it to work it restarts the photon due to drawing too much power.

Any help would be appreciate.


@thrgk, pictures from the top are always better to see the wire alignment. Howerver, from the picture I see you are trying to power the motor using 3.3V from the Photon. Unless you have a very low current motor, this will not work. If the motor can handle 5v then power it from the Vin pin instead. Having a flyback diode is good practice and I also recommend adding a large electrolytic capacitor between Vin and GND near the transistor to help handle motor startup current. I suggest 100uF or so.

BTW, I suspect when you said a “1uf diode” you meant to say a 1N4001 diode instead :wink:


Thanks for the suggestion. Using vin will I he able go control the motor though ? I need to be able to tell it to stop and start.

I’ll add the capacitor as well and yes that is what I meant when I said 1uf. Sorry he he and thank you

@thrgk, let’s review to make sure we are on the same page:

  • The motor side of the transistor which includes the motor and the flyback diode is to be powered from Vin.
  • The motor you have MUST be rated for 5v operation
  • The motor you have cannot draw in excess of 700ma (even though the 2n222 is rated for 800ma, let’s not take chances!)
  • The base of the transistor has a resistor connecting it to a GPIO pin on the Photon. This will allow the transistor to be switched via that GPIO pin. A HIGH on the pin will turn the transistor ON.
  • The base resistor needs to be selected so that enough current flows through the transistor to “start” the motor. This site is a great reference for using transistors as switches:

You will see your circuit there in one of the figures where Vcc in your case is Vin of the Photon. Have fun and let me know how it goes!

1 Like

Hmm my motor is a hobby motor 1.5 to 3v. I’m not sure of the ma as its not stated.

I did see this guide here, but would this not work with my motors ?


@thrgk, the motor you selected is designed for a max of 3v so you cannot power it from Vin. The hackster project uses a 6v motor.

In order to use the motor you have, you could power the motor with 2AA batteries that give you 3 volts total. A battery holder is ideal for that. The +3V side of the battery holder would be Vcc to the motor and the other side of the battery (typically black wire) would connect to GND of the Photon/transistor combo.

Ok so Put the + wire from the 2AA battery holder to the motor, put the - battery pack wire to ground on photon. I also put a wire from ground on photon to motor ? Should I still use any transistors? I thought I needed to have it go to Analog or Digital pads so I can control on and off?

Ill try to use paint to show what i mean.

Thanks for the help so far, really appreciate it. So hard to get this motor working

@thrgk, all grounds need to be common - 2n222 emitter, photon GND, battery ground wire (black typically). The motor “ground” goes to the transistor collector only. Refer to the schematics in the blog I linked to in a previous post.

The transistor is there because the Photon pins can’t handle more than 25ma of current. So the GPIO pin drives the transistor base via a current-limiting resistor and the transistor acts as a high(er) current switch for the motor. The voltage it is switching is provided by the battery pack. The Photon still needs to be powered via USB. :wink:

Ah so it cannot just be powered by the 2AA? As once I get it going I needed it to be wireless :frowning:

@thrgk, so we went from getting a 3v motor to work with photon and transistor to “how do I control a motor with a photon and have the whole thing battery powered”!

That is a different problem and here is why:

  • The Photon can be powered from a 3.3v or 5v supply but NOT a 6v supply directly
  • The motor takes too much current to drive from the 3.3v pin and besides it a 3v max motor!
  • A transistor is needed to switch the motor on/off due to the current required
  • When the motor switches ON, the current from the battery will spike so the battery(ies) need to provide enough power for the Photon and the motor under these conditions

Before I can propose a solution, what kind of battery were you hopping to power all this?

I currently have a couple of 18650 3.7v Lion batteries I was hoping to use

@thrgk, the battries you want to use may or may not come with built-in under-voltage protection. If they measure about 69mm in length then they most likely have that protection. If not, then I don’t recommend using them without an under-voltage circuit (or breakout). I recommend you read the following project post for how to setup a great LiPo/Photon/Motor controller configuration:

You should also consider using the two batteries you have (assuming they have built-in protection) with this great Photon shield:

Here is the schematic as well: