bb12jo
Posts: 62
Joined: Tue May 27, 2014 10:16 pm

How many motors can be hooked up on Raspberry Pi?

Tue May 27, 2014 10:21 pm

Hi! I was wondering how many motors can I hook up on a Raspberry Pi's GPIO pins without needing to buy adapters? I have 4 motors running on two H-bridges and I need to know if I can hook up all the motors. Thanks in advance!!

User avatar
DougieLawson
Posts: 35790
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: How many motors can be hooked up on Raspberry Pi?

Tue May 27, 2014 10:49 pm

Zero.

You need opto-isolators, transistors, relays or motor controller chips. The GPIO pins can't provide enough current to run a 3V3 motor and the back emf when a motor stops is deadly to your RPi.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
joan
Posts: 14181
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How many motors can be hooked up on Raspberry Pi?

Tue May 27, 2014 10:52 pm

You have not given enough information.

I suppose the correct answer is between 0 and infinity.

bb12jo
Posts: 62
Joined: Tue May 27, 2014 10:16 pm

Re: How many motors can be hooked up on Raspberry Pi?

Tue May 27, 2014 11:16 pm

Sorry I am a serious noob at the Pi. I need to run 4 6V motors on the Pi pins. I will hook up the motors like this guy did in this picture: http://i1.ytimg.com/vi/b4uhh_j8uR0/maxresdefault.jpg

User avatar
mikronauts
Posts: 2716
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: How many motors can be hooked up on Raspberry Pi?

Tue May 27, 2014 11:41 pm

You need three Pi GPIO's per motor, using the driver from that photo.

So with four motors, that's 12 GPIO's.

For each motor, use PWM for its enable line, and use its direction pins to set /forward/reverse/break

Enable A, IN1, IN2 is for motor A
Enable B, IN2, IN3 is for motor B

You must drive the motors from a different power supply than the Pi if you wish to avoid potential problems.

Use joan's excellent PIGPIO library, it makes the PWM and I/O easy.
bb12jo wrote:Sorry I am a serious noob at the Pi. I need to run 4 6V motors on the Pi pins. I will hook up the motors like this guy did in this picture: http://i1.ytimg.com/vi/b4uhh_j8uR0/maxresdefault.jpg
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

bb12jo
Posts: 62
Joined: Tue May 27, 2014 10:16 pm

Re: How many motors can be hooked up on Raspberry Pi?

Wed May 28, 2014 12:57 am

Could you please link Joan's PIGPIO library?
Thanks for your help!

User avatar
mikronauts
Posts: 2716
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: How many motors can be hooked up on Raspberry Pi?

Wed May 28, 2014 1:06 am

Here you go:

http://abyz.co.uk/rpi/pigpio/

And a YouTube video for it:

https://www.youtube.com/watch?v=pqz2W6ekKS4
bb12jo wrote:Could you please link Joan's PIGPIO library?
Thanks for your help!
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: How many motors can be hooked up on Raspberry Pi?

Wed May 28, 2014 6:14 am

mikronauts wrote:You need three Pi GPIO's per motor, using the driver from that photo.

So with four motors, that's 12 GPIO's.

For each motor, use PWM for its enable line, and use its direction pins to set /forward/reverse/break

Enable A, IN1, IN2 is for motor A
Enable B, IN2, IN3 is for motor B

You must drive the motors from a different power supply than the Pi if you wish to avoid potential problems.

Use joan's excellent PIGPIO library, it makes the PWM and I/O easy.
bb12jo wrote:Sorry I am a serious noob at the Pi. I need to run 4 6V motors on the Pi pins. I will hook up the motors like this guy did in this picture: http://i1.ytimg.com/vi/b4uhh_j8uR0/maxresdefault.jpg
Surely 2 GPIO's per motor for a total of 8 GPIO's.
connect the enables permanently on via the link jumper and just use inputs.
Doug.
Building Management Systems Engineer.

User avatar
mikronauts
Posts: 2716
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: How many motors can be hooked up on Raspberry Pi?

Wed May 28, 2014 1:38 pm

Depends on the H-Bridge

If you PWM enable, than the motors will coast when disabled.

If you tie enable high, and pulse one of the directions, the motors will break during the low period of the pulsed direction pin, which causes more power to be used, and shortens the life of the motors.

Mind you, there are some modules that take care of this internally to avoid such breaking, but for example the common L298 driver boards would behave thus.
BMS Doug wrote:
mikronauts wrote:You need three Pi GPIO's per motor, using the driver from that photo.

So with four motors, that's 12 GPIO's.

For each motor, use PWM for its enable line, and use its direction pins to set /forward/reverse/break

Enable A, IN1, IN2 is for motor A
Enable B, IN2, IN3 is for motor B

You must drive the motors from a different power supply than the Pi if you wish to avoid potential problems.

Use joan's excellent PIGPIO library, it makes the PWM and I/O easy.
bb12jo wrote:Sorry I am a serious noob at the Pi. I need to run 4 6V motors on the Pi pins. I will hook up the motors like this guy did in this picture: http://i1.ytimg.com/vi/b4uhh_j8uR0/maxresdefault.jpg
Surely 2 GPIO's per motor for a total of 8 GPIO's.
connect the enables permanently on via the link jumper and just use inputs.
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

johndough
Posts: 254
Joined: Sun Jan 13, 2013 2:00 pm

Re: How many motors can be hooked up on Raspberry Pi?

Thu May 29, 2014 9:39 am

BMS Doug wrote:
mikronauts wrote:You need three Pi GPIO's per motor, using the driver from that photo.

So with four motors, that's 12 GPIO's.

For each motor, use PWM for its enable line, and use its direction pins to set /forward/reverse/break

Enable A, IN1, IN2 is for motor A
Enable B, IN2, IN3 is for motor B

You must drive the motors from a different power supply than the Pi if you wish to avoid potential problems.

Use joan's excellent PIGPIO library, it makes the PWM and I/O easy.
bb12jo wrote:Sorry I am a serious noob at the Pi. I need to run 4 6V motors on the Pi pins. I will hook up the motors like this guy did in this picture: http://i1.ytimg.com/vi/b4uhh_j8uR0/maxresdefault.jpg
Surely 2 GPIO's per motor for a total of 8 GPIO's.
connect the enables permanently on via the link jumper and just use inputs.
Hi

I agree 8 pins it is.

2 pins per motor. Driving 2 relays.
Gives Forward and Reverse with the option to connect for a locked rotor.

1 little sainsmart relay board per motor.

User avatar
Cancelor
Posts: 757
Joined: Wed Aug 28, 2013 4:09 pm
Location: UK

Re: How many motors can be hooked up on Raspberry Pi?

Thu May 29, 2014 10:30 am

bb12jo wrote:Sorry I am a serious noob at the Pi. I need to run 4 6V motors on the Pi pins. I will hook up the motors like this guy did in this picture: http://i1.ytimg.com/vi/b4uhh_j8uR0/maxresdefault.jpg
If you are hooking them up to one of those .... do you want variable speed or just forward, reverse and stop?

If you just want unidirectional, fixed speed on and off then one pin and a relay will do! ;)
Can't find the thread you want? Try googling : YourSearchHere site:raspberrypi.org

Return to “Troubleshooting”