Page 1 of 1

### Running a button motor via pi GPIO

Posted: 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.

### Re: Running a button motor via pi GPIO

Posted: 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.

### Re: Running a button motor via pi GPIO

Posted: 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.

### Re: Running a button motor via pi GPIO

Posted: Wed Sep 26, 2012 11:42 am

Thank you Mahjongg

### Re: Running a button motor via pi GPIO

Posted: 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.

### Re: Running a button motor via pi GPIO

Posted: Wed Sep 26, 2012 1:37 pm
It's always a pleasure to publicly demonstrate my incompetence for the greater good.

### Re: Running a button motor via pi GPIO

Posted: Wed Sep 26, 2012 9:02 pm
Or you could check out my channel for some simple GPIO tutorials! Here it is: