nickjantz
Posts: 4
Joined: Thu Dec 28, 2017 5:02 pm

12V Motor controlled via Transistor Switch issue

Thu Dec 28, 2017 5:18 pm

I am trying to use a 12V motor to operate a dog feeder remotely using a transistor switch from the GPIO pins on my raspberry pi. I am using the directions here, minus the part about the screen and email, basically just using the transistor switch and then plan on programming my own GUI around it. However I'm running into issues with the transistor switch.

I have a 12V 1Amp power cord running it. when it's plugged in directly to the motor it works just fine, when I add the flyback diode to it on a breadboard it also works just fine allowing the current to pass, the issue is when I run it through the transistor it stops working. Once I put it through the transistor, wired up to a GPIO pin, turn the pin on, nothing happens. If I skip the 270 Ohm resistor and the 10K Ohm resistor it will turn on, then when I turn the GPIO off it will lower the power, but not all the way.

Through my own tinkering I discovered that if I use a 150 Ohm resistor the motor will initially be off when plugged in, but then turn on when I turn the GPIO pin on, however, again when I turn the GPIO off, it lowers the power of the motor quite a bit but not fully off.

My only other concern was, my transistor says on it, that it's a MPS2222A, and not the PN2222 as required in the diagram, but from my googling it seems they have identical data sheets. I'm also using 1/4 W resistors, so wasn't sure if that would be an issue? I've googled and googled and searched these forums to no help. I'm begin to think I should scrap the whole thing and try it with a relay switch as that seems easier, and a main advantage of the transistor switch is the speed, which is not an issue here, but I would like to learn more about how these work as they seem useful in future applications.

User avatar
davidcoton
Posts: 4909
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: 12V Motor controlled via Transistor Switch issue

Thu Dec 28, 2017 6:51 pm

You may have damaged the transistor and/or the GPIO by omiting the 270R resistor completely. It's there for a reason. However, the 10K should not be necessary, but may help prevent stray operation at switch on.

Or you may have chosen a GPIO with a secondary function that interferes with normal operation.

Or there may be a problem with how you use the GPIOs.

So, put the 10K back in, and use a 270R for the lower value one. Disconnect the GPIO pin, and connect the wire from the resistor to 3V3 (pin 1) instead. Does the motor run? If not, try the 150R resistor. If it still doesn't work, there is a problem with your hardware, probably the transistor. Disconnect from the 3V3, and the motor should stop.

When you can get that far, post your code here (use code /code tags from the top bar of the edit window) so we can check that.
Last edited by davidcoton on Thu Dec 28, 2017 11:57 pm, edited 1 time in total.
Signature retired

pcmanbob
Posts: 9298
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: 12V Motor controlled via Transistor Switch issue

Thu Dec 28, 2017 9:23 pm

Further to what davidcoton said post some good quality pictures of your circuit showing wiring and transistor/resistors several such problems have been solved when I looked at posted pictures and spotted miss connections and reversed components transistors especially.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

nickjantz
Posts: 4
Joined: Thu Dec 28, 2017 5:02 pm

Re: 12V Motor controlled via Transistor Switch issue

Sat Dec 30, 2017 2:42 am

Or you may have chosen a GPIO with a secondary function that interferes with normal operation.
I originally was using GPIO 37, but have also tried using 19, 7 and now 11, still getting the same result. The motor is on fully(or close to it) when the GPIO pin is on, then when it's off it's still running, just a little bit lower.
So, put the 10K back in, and use a 270R for the lower value one. Disconnect the GPIO pin, and connect the wire from the resistor to 3V3 (pin 1) instead. Does the motor run?
This seems to make the motor run just fine, although it doesn't seem to be as high powered as when it's run directly attached to the power source, but that's fine for my application. When I plug it into the 3V3 pin it runs, when I disconnect it from the pin it stops running.

I am now just using standard code to turn the GPIO pin on and off. Two functions, one is on.py:

Code: Select all

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)

GPIO.setup(11,GPIO.OUT)

GPIO.output(11,True)
and the other is off.py, where I have the exact same thing, only the True is changed to False.


Here is the image of the setup on my breadboard. A little bit of explanation, the purple wire attached to the white heatshrink wrap is the power coming in from the plug, the yellow is the ground from the plug. Blue is attached to the GPIO pin 11, and the light red is attached to the GND on the pi zero.
Image:
https://imgur.com/a/U5MH3

pcmanbob
Posts: 9298
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: 12V Motor controlled via Transistor Switch issue

Sat Dec 30, 2017 10:20 am

looking at your posted image it looks to me like you have the diode the wrong way round the lead on the end with the silver strip should go to the motor positive terminal.

Image

this might help colour codes on resistors will be wrong as just grabbed first ones that came to hand.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

gordon77
Posts: 4992
Joined: Sun Aug 05, 2012 3:12 pm

Re: 12V Motor controlled via Transistor Switch issue

Sat Dec 30, 2017 3:17 pm

Removed.
Last edited by gordon77 on Sat Dec 30, 2017 4:12 pm, edited 1 time in total.

User avatar
davidcoton
Posts: 4909
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK
Contact: Website

Re: 12V Motor controlled via Transistor Switch issue

Sat Dec 30, 2017 3:40 pm

gordon77 wrote:
Sat Dec 30, 2017 3:17 pm
Are you sure the power rails on the bread board are continuous? Why are only certain links in? Are you getting an earth to the transistor?
You seem to be looking at pcmanbob's picture, which shows how it should be done (presumably the links are where the breaks are!) -- if you want to analyse the OP' problem, see the picture he linked on imgur. :o
Signature retired

gordon77
Posts: 4992
Joined: Sun Aug 05, 2012 3:12 pm

Re: 12V Motor controlled via Transistor Switch issue

Sat Dec 30, 2017 4:12 pm

davidcoton wrote:
Sat Dec 30, 2017 3:40 pm
gordon77 wrote:
Sat Dec 30, 2017 3:17 pm
Are you sure the power rails on the bread board are continuous? Why are only certain links in? Are you getting an earth to the transistor?
You seem to be looking at pcmanbob's picture, which shows how it should be done (presumably the links are where the breaks are!) -- if you want to analyse the OP' problem, see the picture he linked on imgur. :o
D'oh! My mistake :roll:

nickjantz
Posts: 4
Joined: Thu Dec 28, 2017 5:02 pm

Re: 12V Motor controlled via Transistor Switch issue

Sat Dec 30, 2017 10:51 pm

pcmanbob wrote:
Sat Dec 30, 2017 10:20 am
looking at your posted image it looks to me like you have the diode the wrong way round the lead on the end with the silver strip should go to the motor positive terminal.

Image

this might help colour codes on resistors will be wrong as just grabbed first ones that came to hand.
When I do this setup it doesn't work at all via GPIO pin, but when I attach it to the 3V3 it spins the motor very slowly, as in I can barely see it move. I even tried a new diode to make sure I didn't fry the other one. I will try later today or tomorrow with completely new diode, resistors and transistor just to make sure.

pcmanbob
Posts: 9298
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: 12V Motor controlled via Transistor Switch issue

Sat Dec 30, 2017 11:07 pm

Most likely you have damaged the transistor, it's unlikely you have damaged the resistors.
But starting over with all new components is not be a bad idea.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

nickjantz
Posts: 4
Joined: Thu Dec 28, 2017 5:02 pm

Re: 12V Motor controlled via Transistor Switch issue

Sun Dec 31, 2017 10:22 pm

pcmanbob wrote:
Sat Dec 30, 2017 11:07 pm
Most likely you have damaged the transistor, it's unlikely you have damaged the resistors.
But starting over with all new components is not be a bad idea.
Okay, so it turns out I likely had damaged the transistor as mentioned above. I did it with all new components, resistors, diode, transistor. Run the code off.py so the GPIO pin is completely off, when I plug the motor in, it should not spin. Plug it in, it doesn't spin. But, the transistor starts smoking out of the emitter side, something is definitely not right here. Took the transistor out of the breadboard and it seems to be cracked(from the smoking?), I did this with two brand new transistors so I would assume we have the circuitry right now, it's just overpowering the transistor?

pcmanbob
Posts: 9298
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: 12V Motor controlled via Transistor Switch issue

Sun Dec 31, 2017 10:41 pm

If you are destroying transistors then NO you don't have it connected up correctly.

Do you have a larger breadboard so you can lay it out and then take a picture like I did so we can see if you have it connected correctly or at least one that's not black.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

tenochtitlanuk
Posts: 156
Joined: Fri Jul 06, 2012 8:51 pm
Location: Taunton, Somerset, UK
Contact: Website

Re: 12V Motor controlled via Transistor Switch issue

Sun Dec 31, 2017 11:00 pm

I'd bet heavily that you are using the diode the wrong way round. When the transistor is turned on it ( the diode) will pass most of the current and the motor will hardly get any. Meanwhile the excessive current is frying your transistors.
The diode should be oriented so it seems it would never conduct- ie as others have described. It is only there to handle the very brief 'back emf current' as the transistor turns off.

Return to “Troubleshooting”