Lesson video

In progress...

Loading...

Hello, my name is Mrs. Holborow and welcome to Computing.

I'm so pleased you've decided to join me for the lesson today.

In today's lesson, we're going to be looking at how we can set up, test, and configure motors using a motor controller board.

Welcome to today's lesson from the unit Physical Computing to Create a Robot Buggy.

This lesson is called, "Working With Motors," and by the end of today's lesson, you'll be able to connect, test and set up motors using a motor controller board.

Shall we make a start? We will be exploring these keywords throughout today's lesson.

Let's take a look at them now.

Pin, pin, a physical connection point on a microcontroller, microprocessor, or electronic component.

Ground, G-N-D.

Ground, G-N-D, acts as a return path for an electric current and is essential for a circuit to work properly.

Motor controller! Motor controller, hardware that takes signals and manages how a motor behaves.

Library.

Library, a collection of pre-written code that you can use to make programming easier and faster.

Look out for these keywords throughout today's lesson.

Today's lesson is split into three sections.

We'll start by describing motors.

We'll then move on to connect and set up motors, and then we'll finish by testing and configuring motors.

Let's make a start by describing motors.

Physical computing is about connecting physical objects like motors, LEDs, and sensors to a computer, and using code to control physical objects to interact with the physical world.

Physical computing is important because it helps us to create technology that interacts with the real world, and allows us to create smart, useful systems. Microcontrollers are small, self-contained computers that can be used to perform specific tasks in embedded systems. They are flexible and can be set up in a variety of ways to solve real life problems. Microcontrollers are used in devices that need to sense, control or react to their environment.

The Raspberry Pi Pico is a low-cost microcontroller.

It has 26 GPIO pins that can be used to connect input and output devices.

The pins can be set up in an IDE, Integrated Development Environment, such as Thonny.

Alex says, "I know the Pico microcontroller has 26 GPIO pins, but how can you make use of all 26 pins when there are not the same amount of GND pins available?" That's a really good question, Alex.

Multiple components can be connected to a single GND or ground pin, using a common ground connection.

A common ground connection is when multiple components share a GND connection, such as through a rail on a breadboard.

In this example, the negative pins of the LEDs are connected to the same rail in the breadboard.

So you can see there that both LEDs are connected to that same rail on the breadboard.

To complete the circuit, a connection is made to the GND pin on the Pico to the common ground rail on the breadboard.

So there's the common ground rail, there's the connecting wire, and there's the GND pin on the Pico.

Microcontroller can be used to control far more than just LEDs.

They can control motors, read sensors, display data on screens, or even respond to voice or movement.

Microcontrollers are powerful tools for building many things such as smart devices, robots and interactive systems. Motors are devices that convert electrical energy into movement.

In physical computing, motors are used to make things spin, turn, or move.

Motors are ideal for things such as driving the wheels on a robot buggy or opening a robotic arm.

There are different types of motors, but the most common ones used in physical computing projects are DC motors, used for continuous spinning, servo motors, which are used to rotate to specific angles, or stepper motors, which are used to move in steps for very accurate positioning.

DC motors are great for driving wheels because they provide continuous rotation and are easy to control for speed and direction.

Servo motors are ideal for tasks that need precise angle control, like steering mechanisms or moving robotic arms to specific positions.

Stepper motors move in small precise steps, making them ideal for applications that need accurate positioning like 3D printers or CNC machines.

A buggy needs to be able to move forward, backwards, and change direction.

DC motors are most suitable for buggy wheels because they can spin in both directions and the speed can be adjusted.

To control a DC motor with a microcontroller like the Raspberry Pi Pico, you need a motor driver.

A motor driver is a special circuit that safely provides the power and signals the motor needs to work.

Time to check your understanding.

I have a question for you.

Which motor moves in small precise steps? Is it A, a servo motor? B, a DC motor? Or C, a stepper motor? Pause the video whilst you think about your answer.

Did you select C? Well done! A stepper motor is a motor which moves in small precise steps.

Which of the following is a special circuit that safely provides the power to motors? Is it A, a microcontroller? B, a motor controller? Or C, a breadboard? Pause the video whilst you think about your answer.

Did you select B, a motor controller? Well done.

I knew you'd get that right.

Which motor provides continuous rotation and so makes it easy to control speed and direction? Is it A, a servo motor? B, a DC motor? Or C, a stepper motor? Pause the video whilst you think about your answer.

Did you select B? Well done.

A DC motor provides continuous rotation.

Okay, we're moving on to our first task of today's lesson, Task A.

For part one, describe what a motor is and how they can be used in physical computing.

For part two, describe which type of motor is most suitable for a small buggy vehicle.

Pause the video whilst you complete the task.

How did you get on with the tasks? I'm sure you did a great job.

Let's have a look at some sample answers together.

For part one, you were asked to describe what a motor is and how they can be used in physical computing.

A motor is a device that connects electrical energy into mechanical movement.

In physical computing, motors are used to create motions in projects such as spinning the wheels on a robot buggy, lifting a robotic arm, or opening a door.

For part two, you were asked to explain which type of motor is most suitable for a small buggy vehicle.

The most suitable type of motor for a small buggy vehicle is a DC motor.

This is because DC motors provide continuous rotation and are easy to control using a motor driver.

They can also spin in both directions and have adjustable speed, making them ideal for driving the wheels of a buggy backward and forward.

Did you have some similar responses? Remember, if you want to pause the video here and make any corrections, you can do that now.

Okay, so, so far we've described motors.

Let's now move on to connect and set up motors.

There are many different types and brands of motor controllers.

Each one may look different, but they'll have similar features and connections such as input terminals, output terminals, and power supply terminals.

The input terminals on a motor controller receive the logic signals from the microcontroller.

On this example, the input terminals are towards the bottom of the picture and have been highlighted on the diagram.

Note that the logic signals do not power the motors, but instead tell the motor controller how to control the motors.

The output terminals on a motor controller provide the output electrical power to the motors.

Here you can see the output terminals on either side of the motor controller.

The wires from the motor are connected to these terminals.

The power supply terminals on a motor controller are where the external power supply is connected.

On this example, the power supply terminals are towards the bottom of the picture.

This could be a battery pack or some other suitable supply of electrical power.

The diagram shows how to connect two motors to the controller board.

Note that a small screwdriver is needed to undo and tighten the terminal screws to connect the motor wires to the controller board.

So here's the terminal screw, which will need to be loosened and tightened to attach the wire.

The Pico microcontroller GPIO pins are connected to the motor controller input terminals with jumper wires.

So look carefully at the diagram to see how these are connected.

The motor controller input terminals are highlighted and so are the GPIO pins, and you can see they're connected.

Jumper wires are used to connect the breadboard and Pico GPIO pins to the microcontroller.

There are several types of jumper wire.

Each type is suitable for different connections.

Jumper wires can have female or male connectors.

Here's the male connector and here's the female connector.

This is called a male-to-female jumper wire because it has a male connector at one end and a female connector at the other.

This is called a female-to-female jumper wire because we've got a female connector at either end.

This is called a male-to-male jumper wire because we've got a male-to-male connector at either end.

Note that the colour of the wires in these diagrams has just been used for illustration purposes.

The colour of the wire doesn't indicate the type of connection.

Motors and other components often require more electrical power than microcontrollers, such as the Raspberry Pi Pico can safely supply.

To supply the required energy for these components, other sources of energy are used.

In most projects, external batteries are used to provide the power.

A single AA cell has a voltage of 1.

5 volts.

This is not enough to power most motors.

A small DC motor suitable for a robot buggy needs a supply voltage of around five to six volts.

To increase the power supply voltage, multiple cells can be connected in series to form a battery of cells.

A four by AA battery pack provides enough energy to power small DC motors as its output is around six volts.

And we can see this illustrated here.

So 1.

5 plus 1.

5 plus 1.

5 plus 1.

5 volts is equal to six volts.

The power supplies from the Pico and battery pack can be connected to the power terminals on the motor controller.

So you can see here the battery pack has been added to our diagram and the connections added.

The components are now connected and the setup is ready to be tested.

Time to check your understanding.

I have a question for you.

What voltage does a four by AA battery pack provide to a circuit? Is it, A, six volts? B, four volts? Or C, three volts? Pause the video whilst you think about your answer.

Did you select A, six volts? Well done.

Remember, each AA battery provides about 1.

5 volts.

What tool is needed to undo and tighten terminals on a motor controller? Is it A, a multimeter? B, a craft knife? Or C, a screwdriver? Pause the video whilst you think about your answer.

Did you select A, a screwdriver? Well done.

I've got a true or false statement for you now.

There is only one type of jumper wire.

Is this statement true or false? Pause the video whilst you have a think.

Did you select false? Well done.

Remember, there are several types of jumper wires such as male-to-male, female-to-male, and female-to-female.

Each type is suitable for different connections.

Okay, we're moving on to our second task of today's lesson, Task B.

If you can, follow the instructions in Task B, activity one, which is supplied as additional materials to this lesson, to set up the buggy motors with the controller board.

Pause the video whilst you complete the task.

How did you get on? Did you manage to successfully connect and set up the motors? Well done.

Remember, if you need to, you can pause the video here and look carefully at the diagram that's currently on the screen to help you get the connections set up correctly.

Okay, so, so far we've described motors and we've connected and set up motors.

Let's now move on to test and configure motors.

Once the DC motors, Pico, and microcontroller are correctly connected, code can be used to test that the motors function.

First, connect the Raspberry Pi Pico to a computer and open up Thonny.

Make sure your Pico is showing as connected in the shell window.

If it isn't, click Run, then click Stop/Restart backend to reestablish a connection.

One of the motors should be connected to GP pin 12 and GP pin 13.

One of the pins will turn the motor one way, the other will turn the motor in the opposite direction.

So forwards and backwards.

This will be set up in the code with the help of modules from a code library.

MicroPython comes with many useful modules in the standard library.

A library is a collection of pre-written code that you can use to make programming easier and faster.

To make use of a module from a library, it must first be imported into the code.

The machine and utime modules are useful in physical computing projects.

The following code imports the modules: So you can see we have, "From machine import Pin," and "Import utime." Note that in this case the code tells the IDE, "We want to use the Pin class from the machine module." So machine is the module and Pin is the class.

The utime module is also imported as it includes useful time related functions.

The machine module is used to create Pin objects for the connections on one of the motors.

The code below sets pins 12 and 13 as output pins.

So we have motor_right_fwd, which stands for forward, =Pin open bracket 12, so setting pin 12, comma Pin.

OUT close bracket.

And then we have the similar line of code underneath but this time we have B-W-D for backwards and we're using pin 13.

Pin 12 will be used to drive the motor forwards, so that's why we've used that F-W-D there.

Pin 13 will be used to drive the motor backwards, so we've used B-W-D.

You can test the motor by sending a high signal to the pin.

In the example below, the motor should go in the forwards direction for three seconds and then stop.

So we have motor_right_fwd.

value(1) Which is on, sending a high signal.

utime.

sleep(3) So that's three seconds.

And then motor_right_fwd.

value(0) to turn it off.

So one turns on the motor, three is waiting for three seconds, and zero is turning off the motor.

You can test the motor works in the backwards direction by adding the following code underneath the previous code.

So note this time, we're using B-W-D for the backwards direction.

One to turn on the motor, three to wait three seconds, and zero to turn off the motor.

Now you have one motor tested and working, repeat the process for the second motor using the previous code as a guide.

Note that the second motor should be controlled by pins 14 and 15.

And as a tip, check to make sure both motors are going in the same direction when using the forward variables and backwards when using the backward variables.

Otherwise, you'll have the wheels spinning in opposite directions.

Time to check your understanding.

I have a question for you.

The pin class is used from which module? Is it A, utime? B, machine? Or C, math? Pause the video whilst you think carefully about your answer.

Did you select machine? Well done.

The pin class is used from the machine module.

I have a true or false statement for you.

A library is a collection of pre-written code that you can use to make programming easier and faster.

Pause the video whilst you think about your answer.

Did you select true? Well done.

Okay, we're moving on to our final task of today's lesson, Task C.

If you can, follow the Task C activity two instructions to set up and configure the buggy motors.

Remember the instructions are provided as an additional resource for today's lesson.

Pause the video whilst you complete the task.

How did you get on? Did you manage to test and configure your motors? Well done! Let's have a look at some sample code together.

So on line one we have: From machine import Pin.

And then line two we have: From utime.

So we're importing those modules.

On line three, we have: Motor_right_fwd for forward.

=Pin(12, Pin.

OUT) On line four, we're doing the backwards for that motor.

So motor_right_bwd=Pin This time 13.

And then on line five and six we're doing the left-hand motors, so exactly the same lines of code, although we've replaced right for left and the pins are now 14 and 15.

Then we're testing the motors.

So on line seven, motor_right_fwd.

high() Line eight, motor_left_fwd.

high() And then we have utime.

sleep(3) So we're turning those forward motors onto high for three seconds.

And then on lines 10 and 11, we're turning them back to low.

And then on line 12, we have utime.

sleep for one second, and then we're going to test the backwards motors.

So exactly the same lines of code, but this time we're using the B-W-D motors, not the forward motors.

Remember, if you didn't quite get your motors working correctly, you can pause the video and use this code to help you.

Okay, we've come to the end of today's lesson, "Working With Motors," and you've done a fantastic job.

So well done.

Let's summarise what we've learned together in today's lesson.

Motors convert electrical energy into motion.

Motor drivers are needed to safely control motors as microcontrollers cannot directly drive motors.

The direction and speed of motors can be controlled with code.

A library is a collection of pre-written code that you can use to make programming easier and faster.

I hope you've enjoyed today's lesson and I hope you'll join me again soon.

Bye!.