Using Motors

Note: Connecting a motor directly to a GPIO pin WILL BREAK YOUR RASPBERRY PI!!! So don’t do it!

David Ferguson supplied the diagram below which shows a very cheap way of getting 2 motors connected safely to your Raspberry Pi. The chip used is a very cheap one(37 pence) called a ULN2003. motor_pinout Wire pin11 of your Pi to Pin1 on ULN2003 and then Pi pin12 to ULN2003 pin2 and finally Pi Pin6 (Gnd) connects to ULN Pin8

Then ULN2003 pin16 goes to one motor, ULN2003 pin15 goes to other motor.

The other connections on each motor are both connected to ULN Pin 9.

Finally connect a separate motor power supply (I use a 4xAA battery pack to give 6V) and CAREFULLY connect +ve to the ULN2003 Pin 9 and -ve to ULN2003 pin 8)

Once you’ve got your motor(s) SAFELY connected up,  to control a motor, it is usually required to be able to not just switch it on or off but to vary its speed.

To do this in Scratch you can create 2 special variables called MotorA and MotorB and then assign these values from 0 (off) to 100 (fully on)

MotorA controls pin11 and MotorB controls pin12.

e.g To make MotorA go at half speed use ma50

To make MotorA switch off use ma0

Although MotorA controls pin 11 and MotorB controls pin12, you could have used variables called Motor11 and Motor12. In fact all the pins on the Raspberry Pi can be controlled in this way – to use a motor on pin 13 you would simply crate a variable called Motor13 and set that from 0-100 to control the speed

(Remember – pins on the Raspberry Pi must NEVER be connected directly to motors – always go through some sort of buffer electronics)

Power
As well as using the term “Motor” you can use the word “Power” instead. Using “Power” makes more sense if you are just controlling the brightness of an LED. To make an LED go from off to full brightness try this

spower11

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s