# Arduino Motor Control/Howard Community College/Fall2012/P2-501-CDMN
## Electronic Sections Expected
### Problem Statement

We must develop a tutorial that will enable the average Arduino user to set up an Arduino to take a sensory input, and then using a logic process execute commands to an electric motor.

### Team Members

Mark Muhlbock Christopher Wilson Derek Staub Neil Pasricha

### Poster

Poster by: Mark Muhlbock

### Summary

We are taking a mixture of program codes from other people and sources in an effort to breed our own code. The goal is to make this code modular enough to fit in several applications. From this creation a tutorial in Microsoft Word will be made and attached to this page.

### Story

On 15 October we received our new project. The objective of which was to develop a tutorial that would enable people who are less experienced on Arduino to build a program that can take a sensory input, and then using a basic logic, command a motor or otherwise perform a function.
We spent time researching different types of motors and different ways Arduino could be used. We also spent time researching what some of the symbols and commands in Arduino code actually mean.
On 17 October we met again in class to further development. We decided that it would be best to develop the program first instead of trying to build the tutorial and the program at the same time. We also furthered our search into what may laready be available for our project. Unfortunately though most people on forums such as the one on Arduinos website seem to have more questions than answers. Chris took home an Arduino with a bread board, LEDs, and a range sensor to further development on this end.
On October 22 we subdivided to work on three different types of motors at once. Mark will be working on servo motor control, Derek will be working on DC motor control, and Chris and Niel will be working on stepper motor control.
On October 22 Chris and Neil began researching code to work with on the stepper motor tutorial. Several codes were dug up to be used. Namely a code to operate stepper motors was pulled directly off of Arduinos site and another code was used that had already been build for a robot car.
http://www.instructables.com/id/Arduino-4wd-robot-with-ping-sensor-J-Bot/?ALLSTEPS
http://www.ladyada.net/make/mshield/use.html
From there work was done to figure out what some of this code means. It was found that:
1: int This code is used at the beginning of a line of code to detonate a word as a command that will be used later in the code.
2: void setup This code is used to separate processes. It also starts processes. This code would be used to separate sections of code. For instance to separate the motor control code from the sensor control code.
3: void This code can be used to separate individual commands within a 'void setup' set of commands.
4: if and else if these can be used in the decision making process of a command. For instance if you wanted the program to do one thing under one sensor condition and then something else under a different sensor condition.
On October 24th work was done to take a code and work it down to something that would be useful for this tutorial. The robot car code was used first because it already takes sensor input and turned it into a motor function. The ultimate plan being to take the code off of Arduinos site and work it in to the car code. Here was some of the work done on the robot car code:
1: Code associated with operating a second motor was deleted
2: Code associated with inches was deleted and replaced with code referring to centimeters.
3: Code for motor speed was altered to output full power
4: "neck turn" associated codes were deleted. The 'neck turn' code was there so that the robot could rotate its sensor. This will not be needed for the project.
5: Work was begun deleting codes that referred to left and right. The codes that refer to forward, backward, and stop will be retained.
On 28 October Chris did work from home to further development on this project. For some reason with the version of Arduino that was downloaded a new problem had occurred. The line of code that reads 'AF_DCMotor; motor1(1);' no longer would work. Several fixes were tried to include:
1: putting 'int' in front of the code.
2: eliminating 'AF_DCMotor' from the code.
3: making the whole line "int motor1 = 1 ;". This appeared to work but now the motor control code does not work.
4: Finally the original code was tried again. This is where things got weird. The original code completely checked out in class, however now the line that is giving me problems is also popping up in the original code.
Several codes were pulled and tried to include many directly off of Arduinos website. Amazingly nothing would check out.
After spending some time searching for awnsers a code was found that was very close to operating with the Arduino software:
http://fritzing.org/media/fritzing-repo/projects/a/arduino-bipolar-stepper-motor-controller/code/stepper_motor_script.txt
This code only required that 'MotorReset' at the end of the code be changed to 'MotorFree'.
Work will be done on this code and also the old code will be taken back to class to see if there really is a diffrence between the Arduino on the class computer and the Arduino that was downloaded on the 28th.
On October 30th Neil and Chris met up again to continue their work on Stepper Motors.
There are some differences between stepper motors and types of motors. Though a stepper motor is not that far from a brushless DC motor there are some thing you need to know:

#### Stepper Motor Control

-A stepper motor, much like a DC motor has a rotating permanent magnet propelled by stationary electrical magnets, however the motion is divided into a number of steps around the rotation of the rotating magnet.
-Stepper motors can spin like a regular DC motor, however they can also stop on a position like a servo motor.
-Stepper motors are generally inexpensive
-They have a low RPM torque, which allows for more control and faster "jump-off" points
-When faced with obstacles, Stepper motors face almost 100% no backlash
-They, much like the other two motors can be very small and compact
Chris has completed some development on completing a tutorial after doing much research. For now it is in the form of a pdf however it will soon be moved to a google doc.
(document removed do to changes in project)
This document includes explanation of what a stepper motor is and goes in depth on what Arduino coding is needed to operate it. Please note that this is not a finished product and will go through several more editing stages.

### Servo Motor Control

-Average price is about double that of a Stepper motor
-Relies heavily on encoders to provide positioning info back to computer
-The complexity of the motor, as well as the amount of service it requires are just about double that of a Stepper motor
-Uses "closed-loop" circuitry, which has no real advantages over a stepper motor
-The main advantage in a Servo motor is the fact that they can be significantly larger than that of a stepper, and used for more industrialized needs
-Our conclusion about Servo motors is that they are inferior to Stepper motors unless they are necessary in extremely large size

#### DC Motor Control

-Have rotating permanent magnets on rotor propelled by stationary electrical magnets, just like Stepper motors
-A computer controls the brushes
-No sparking, less noise, and no brushes to wear out
-Many more electromagnets on stator for more control (compared to the other two motors)
-Higher cost than a stepper, but more lifespan so the proportions end up looking almost the same

### Story Continued

Throughout the early days of November, all members of our group worked tirelessly to get their respective codes up and running. While Neil and Chris continued to highlight the differences between the three types of motors, they still had to revise their code to make it work.
On November 7th, Neil began work on the team poster. A lot of pictures were taken in class and sample codes from each member were screen shot as well. We plan on being done with everything by Monday, as everyone is coming close to a break through.
On November 7th, Chris toiled with the stepper motor and the Arduino to make them work. Lots of troubleshooting was done and nothing was made to work. Everything from changing codes to different motors were tried.
On November 12th, Chris made many advances in figuring out stepper motors. It was discovered that a driver circuit is needed to operate stepper motors due to each step requiring an individual voltage and timing map. Arduino can still be used and it acts as the logic module, however control of the motor must be done by a separate driver. Luckily these drivers are available online for under $20.
Upon learning about driver modules and how they are necessary in stepper motor control I now believe I could have one operating once the module has arrived in the mail and I have had the opportunity to work with it some.

### Material List

1: Adruino Uno
2: Arduino Monster Moto Shield
3: solderless bread board
4: assorted wires
5: Sonic range sensor
6: LEDs for testing
7: Steering device from robot car project for testing
8: TIP-120 Transistor
9: 9v Battery

### Software List

* Arduino 1.0.1
* Google Chrome

### Tutorials

DC Motor Tutorials
Servo Motor Tutorials
Stepper Motors

### Next Steps

To take tutorials deeper on the subject of using different input funtions like using a sensor for when you want a motor to go. Also to take these tutorials deeper into individual control of the motors.