Blog

Lab 5: Motors, Jetplanes, and Mobiles

 

Lab 5

In this lab we explored motors by building circuits using servo, DC and stepper motors. By using Arduino open source code, we generated a pseudo-analog output voltage (PWM) to control a servo motor. Through the skills that we have learned over the semester we further dove in to understand how to drive DC and stepper motors using an H-Bridge.

Lab Objectives:

  • Use PWM to drive a servo motor

  • Use an H-bridge to drive a DC motor

  • Drive a stepper motor with an H-bridge

Part 1: Servo Motor Control

We will conduct a servo motor circuit by connecting 3 different wires to the hook up male headers on the servo motor (white, black, and red). The black represents ground, red representing power and white will be our digital input. Below is the schematic to show the rest of the circuitry that we will be following:

Circuit

 
lab5-01.png
IMG_7731.jpg

Program

First, we need to include the servo library in our code. This can be found in the arduino built-in libraries under the Sketch Tab > Include Library. By including this library we are able to communicate through to the servo motor using necessary built-in functions.

After we find the range of the sensor with analogWrite, we need to map the values so we can convert the sensor to servo range. This range will be 0 - 179 representing the angle at which the servo motor can move at one time. We will be storing this number as a variable that will continually update in the loop() function.

We also need to remember to start the serial in the setup() function by using Serial.Begin(9600). Note: 9600 is the rate at which our hardware is communicating with software for parsing in sensor range numbers. Lastly, we will be using servo.attach() to initialize our servo motors.

You can find the rest of the code here.

Part 2: DC Motor Control

In part 2 of the lab, we will learn how to drive a DC Motor using an H-Bridge hookup. By incorporating a H-Bridge it will enable us to be able to write code that can make the motor go clockwise and counterclockwise. The H-Bridge is a valuable part to creating products and programs that enable to reverse direction.

Circuit

Building the circuit requires any type of digital input - we will be using a momentary button. This will connect to digital input 2 as you can see on the schematic and in pictures below. Then we will hook up the H-Bridge and the DC motor. Integrating the H-Bridge in to the circuitry is fairly simple just tedious with the amount of wires needed. On the H-Bridge, the notch side indicates the top of the component. By knowing top and bottom, we will start from the top with what types inputs/outputs it has. On the four corners, these will be used for power - usually hooked up to 5V but the lower left leg (when placed down on a breadboard) is used for VIN. From there the 4 legs in from the outer ones are used for logic pins. The next 4 legs are for motor terminals; this is where we will hook up the motors. Then the 4 inner legs are all used as pull downs to ground.

With the DC motor, we will only be using the left side. Where we will hook up the two wires to leg 3 and leg 6 that will then be put into digital input pins from legs 2 and 7 to digital pins 3 and 4. From there the rest of the hook up is straightforward. Follow the schematic and photos below:

Further explanation of H-Bridges from the Coloring Chaos Blog: The L293NE/SN754410 is a very basic H-bridge. It has two bridges, one on the left side of the chip and one on the right, and can control 2 motor coils. It can drive up to 1 amp of current, and will operate between 4.5V and 36V. The small DC motor you are using in this lab can run safely off a low voltage so this H-bridge will work just fine.

lab5-02.png
IMG_1314.jpg

Program

See code here.

Part 3: Stepper Motor Control

Similar to part 2, we will be using an H-Bridge to control the flow of energy to the stepper motor. This allows us to be able to change the direction of the motor to clockwise and counterclockwise. Stepper motors are multiple coiled, so this means that they have small increments or 'steps'. We will learn how to hook up  a stepper motor that is unipolar. Stepper motors can be unipolar or bipolar which needs one main power connection or two. 

Circuit

lab5-04.png
IMG_7718.jpg
IMG_7720.jpg

Program

See code here.

** In collaboration with Karina Micheli for the stepper motor