Reiterpallasch
Posts: 2
Joined: Wed Sep 26, 2012 1:36 am

Running a button motor via pi GPIO

Wed Sep 26, 2012 1:46 am

I have the code for this project completed. Basically I have a scenario in which when a particular device sounds and alarm, it will also create a voltage to go to a GPIO input and register as a high, or registering as 1. I must first state that my understanding of circuitry is limited. I understand basic circuit analysis up to transformers, but not board logic. My first question is in the event that my input voltage cannot be lowered to at or under 3.3 volts, what would be the best method of dropping that voltage? I know that DC-DC converters exist, but they are expensive. I also know that either a voltage division setup using resistors can be used to drop the voltage as well as a zener diode or even a voltage regulator.

Second, I have the button motor, but it requires about a 300 milliamp source. I know that to stay in safe operation, the Pi should not output more than 16 milliamps. What is the best way to amplify this value? I am also curious as the best way to include an external power source, such as a battery. Any aid in this matter is greatly appreciated. I understand that many try to use transistors to increase the voltage.

User avatar
morphy_richards
Posts: 1603
Joined: Mon Mar 05, 2012 3:26 pm
Location: Epping Forest
Contact: Website

Re: Running a button motor via pi GPIO

Wed Sep 26, 2012 11:08 am

The magpi magazine issue 2 has an article starting on page 10 "in control" that explains how you can do your GPIO monitoring / input. (http://www.themagpi.com/)

You could use a separate power supply for your motor and join together the ground of this with the ground on the Pi, which will enable the two things to work together with separate power supplies. I personally wouldn't try to draw the power to run the motor from the 3v3 or 5v supply on the GPIO of the Pi.

For this you could use some batteries or run another line from your power supply. If you need to modify voltage the easiest way is to use a voltage divider.

You can use a transistor as a switch to turn on and off the motor. You connect the "base" of the transistor to a GPIO pin via a current limiting resistor. This resistor prevents too much current being drawn and dmaging the GPIO.

When that GPIO pin is turned on a current flows to the "base" on the transistor. This will then "switch on" the transistor and allow current to flow from your motors power supply through the transistor and into the motor.

That way you safely allow 300ma to flow from another source into a motor while only delivering a safe current from the GPIO.

You need to calculate the value of the resistor using Ohms law.
R = V/I
(resistance = PD (volts)/Current (amps)

For this you need to know the voltage you will be delivering and the current.
As you said 16mA is safe. (0.00016 Amps)
The GPIO delivers 3.3v
3.3/0.00016 = 20625 Ohms - which is just over 2 Kilo Ohm (2K) and a smaller one. You will probably be safe with just a single 2K resistor IMHO.

PS. Someone else check all this please am sleep deprived and liable to silly errors.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 11836
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Running a button motor via pi GPIO

Wed Sep 26, 2012 11:31 am

Yes, you made a few errors. :)

16mA = 0.016 A not 0.00016 A
and
20625 Ohms is 20K not 2K.

Also you did not subtract the base-emmitter diode voltage, typically 0.6V, so not 3.3 V but 3.3-0.6 = 2,7V

Thus the real answer is 2,7/0.016 =168 Ohm nearest E6 value is 160 Ohm.
But IMHO I would use a slightly lower current, (5mA) and thus a higher resistance, so I would use 470 Ohm.



Also you need to connect a diode across the motor, as its an inductive load, and when switching an inductive load with a transistor you need a dampening diode across the induction, so that the fly-back current is shortened.

User avatar
morphy_richards
Posts: 1603
Joined: Mon Mar 05, 2012 3:26 pm
Location: Epping Forest
Contact: Website

Re: Running a button motor via pi GPIO

Wed Sep 26, 2012 11:42 am

:oops:
Thank you Mahjongg
:)

Reiterpallasch
Posts: 2
Joined: Wed Sep 26, 2012 1:36 am

Re: Running a button motor via pi GPIO

Wed Sep 26, 2012 1:26 pm

Thank you two very much.The replies will really aid in this project with both learning and actually getting to the building.

User avatar
morphy_richards
Posts: 1603
Joined: Mon Mar 05, 2012 3:26 pm
Location: Epping Forest
Contact: Website

Re: Running a button motor via pi GPIO

Wed Sep 26, 2012 1:37 pm

It's always a pleasure to publicly demonstrate my incompetence for the greater good. :D

User avatar
raspberrypiguy1
Posts: 379
Joined: Sun Sep 02, 2012 7:01 pm

Re: Running a button motor via pi GPIO

Wed Sep 26, 2012 9:02 pm

Or you could check out my channel for some simple GPIO tutorials! Here it is:

http://www.youtube.com/user/TheRaspberr ... ature=mhee

Enjoy
The Raspberry Pi Guy
Matt, The Raspberry Pi Guy YouTube channel, author of Learn Robotics with Raspberry Pi, available now: http://mybook.to/raspirobots, Computer Science & Electronics Undergraduate at The University of Edinburgh

Return to “Automation, sensing and robotics”