User:Christopherwilson202/Arduinomotorcontrol

Problem/project Goal
I must work to develop a tutorial that can take the average or introductory level Arduino user and instruct them how to use Arduino to control a motor based on a sensory input.

My First Task
My first task is to research as much Arduino material as possible that is associated with my task.

Summary of actual work over first weekend
I have searched several strands of Arduino code and have searched several Arduino resources (i.e. forums and blogs). I am still working to learn this computer language as it is based off of C++ and I have very little experience of knowledge in the realm of computer code.

Week1 Narrative
15 October 2012: We received our new project, to create a tutorial for somebody who wants to use an arduino take a sensory input, and then through a logic, create a motor output. We decided it would be best to actually make such a system work before writing up a whole tutorial. I began researching different types of motors and what it takes to run them.

We decided to make a program that would take a range sensors input and control a DC motor. We believe that such a program would benefit the most possible users based on what others in the class are doing.

17 October 2012: I googled "Arduino motor control code with sensor". I found several sites to include Arduinos own forums. A lot of time was spent on this site searching under the 'using arduino > sensor' and 'using arduino > robotics'. Unfortunately an extended search of these pages turned up little as most of the threads were questions with no answers. Also a lot of people were trying to control something with blue tooth or a remote control, nothing using a sensor to directly control a motor.

I took home an Arduino, along with a bread board, wires, LEDs, and a sonic range sensor to attempt to further work some of these codes from home.

21 October 2012: A few decent resources were found. I found another schools lab project that does something very similar to what we are trying to do. Only difference is they are using a servo motor and a stress sensor.

link can be found here: itp.nyu.edu/physcomp/labs/servo

I also found another link to a person who is using arduino to control a 4wd vehicle.

The link can be found here: http://www.instructables.com/id/Arduino-4wd-robot-with-ping-sensor-J-Bot/?ALLSTEPS

About halfway down the page is the code to operating the vehicle fully laid out. Though this is for controlling a whole vehicle it contains code needed to build what we are going for. Not only that but it contains both servo motor and DC motor code.

My Second Task
The second task is to take the codes I have found and try to merge them to create a code that matches what we are trying to do.

Summary of actual work over second weekend
I have taken two codes, one for a working robot car that used servos, and one that is exclusively servo control, and worked on merging the two to make one functional code.

Week2 Narrative
22 OCT 2012: today I began searching for codes to use for this project again. I have decided I am going to use a code I pulled off of Arduinos site for servo control and another code I pulled off of a site that had robot car and merge the two.

Code for robot car can be found here: http://www.instructables.com/id/Arduino-4wd-robot-with-ping-sensor-J-Bot/?ALLSTEPS

code for stepper motor control can be found here: http://www.ladyada.net/make/mshield/use.html

I did some work on both codes trying to figure out what everything means. I learned a few things this day.

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.

24 OCT 2012: Today I am going to take apart the robot car code that I found and begin fashioning it to my needs.

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 my project.

5: I began work deleting codes that referred to left and right. The codes that refer to forward, backward, and stop will be retained.

28 OCT 2012: Working from home I downloaded Arduino software onto my computer and went to work. I have hit a very unexpected snag today. I knew that I had left the code not operational, however now a different error is popping up in the beginning of the code. The program does not seem to recognize AF_DCMotor; motor1(1); as any type of anything any more. I tried a number of things to remedy thins and nothing seems to work any more. I have tried:

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: I finally tried putting the original code back in. 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.

From here I decided to begin working the other code to see if I could use that one. The same problem occured. The on the top that reads 'AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm' does not work. This is very similar to the code that did not work in the last sketch. This code was pulled directly off of Arduinos site.

I have tried searching online for a solution or explanation with no luck. The Arduino forums are little help and most sites that provide help with computer code give answers that are heavily laden in jargon that I have still yet to learn. Also the answers they give and not related closely enough to my issue for me to use.

After some more searching I finally landed a hit. I found a code that is designed to operate a bipolar stepper motor here: http://fritzing.org/media/fritzing-repo/projects/a/arduino-bipolar-stepper-motor-controller/code/stepper_motor_script.txt

The only part that did not work was at the end of the code he has written "MotorReset". This comes up with the error "MotorReset not defined" as there is no other reference to 'MotorReset' in the code. I replaced this with 'MotorReset' as there are reference to this and it appears that resetting is what you would want to do in that point of the code. This code has worked out and now I will be working with this code.

My Third task
I am going to take this new code that I have found and fashion it into what I need. This new code seems to include a lot of things that the old codes did not. This will not only further my learning experience but hopefully allow for a more modular code. Also when I return to class I will retry the old codes to see if the issue that came up is some how only associated with my computer or my load of the Arduino software.

Summary of actual work over third weekend
Arduino code and stepper motors were further researched. A document has begun that will outline how a stepper motor works and how to implement Arduino code to operate a stepper motor.

Week3 Narrative
31 OCT 2012: Today I began attacking another angle of this project. I have began researching information on stepper motors. Also a document was started for which information will be compiled and the tutorial will be formed. This document will start with information about stepper motors and lead into how to read, understand, and implement code to operate a stepper motor. Most research was done on wikipedia.org and Aduino.cc.

4 Nov 2012: Today research was furthered in several directions. First some YouTube videos were viewed where Arduino code was broken down into much smaller understandable chunks. These are the vidios I have viewed:

https://www.youtube.com/watch?feature=player_embedded&v=fCxzA9_kg6s#!

https://www.youtube.com/watch?v=_LCCGFSMOr4&feature=fvwrel

https://www.youtube.com/watch?v=abWCy_aOSwY&feature=fvwrel

I also took some time to view some of the projects on Element14.com. This has pushed me quite a bit further into understanding Arduino and has allowed me to further my work on the document.

The culmination of my work for this week can be read on this document: (document removed due to new developments on this project)

My Fourth task
My fourth task is to complete the document and have the Arduino program successfully operating a stepper motor.

Summary of actual work over fourth weekend
Week 4 was wrought with failure as I was unable to get the motor to work. However deeper digging deeper has turned up that stepper motors are much more complex to operate than once thought and require a specific driver to control the current that signals the motion of the motor.

Week4 Narrative
5 Nov 2012: Today the focus was deciding up team responsibility as far as team page and where to post our tutorials. I took some time to acclimate myself to the area of wikiversity that goes over Arduino totorials.

7 Nov 2012: This day did not go over easy. I uploaded the program into Arduino and the Motor did not operate. I tried many solutions:

1: wires could be backwards: reversing wires did not work

2: wires at wrong ports: I tried moving the wires around and changing the ports in the code. This also acted as a test to try out other ports

3: connections were tested

4: other motors were tested

5: the original motor was tested

6: Arduino was tested against a regular DC motor

7: code was modified several times and other codes were tested

8: online trouble shooting was tried

9: operating the stepper motor with a Moto shield was tried

None of this got the project going. The Moto Shield did not work and direct line off of the Aduino did not work. Judging by the gauge of the wires it should work fine off of the Arduino.

This leaves me almost back at step 1.

11 Nov 2012: Today I did some searching to try and find awnsers. I started by only searching element14.com since everything I have read off of that page has always worked.

Here I quickly found out that the Arduino only acts as a logic module and a driver module is needed to modify the signal. This is because as the motor moves to different positions the different magnets require minute changes in charge. The driver takes care of this thinking for you and drivers often have integrated all the other things it turns out you need to operate a stepper such as PWM delay/decay circuts. The driver or translator only controls the power, you also need Pulse Width Modulated circuits to control the timing of the power.

An example of a driver can be found here: https://www.sparkfun.com/products/9402 Driver motors are plentiful and are made by many different companies. Most can be found for under $20.

With this new information I began to do more searching and found that every stepper motor setup that was working had some sort of logic module, translator, power supply, and something resembling a relay or motor shield. This is far more than I have been working with. I have found some all in one circuit boards but these are far more complex than the Arduino Uno I have been working with.

The work a translator does is illustrated in this attached document. This shows the differing power requirements at each set of magnets to acquire a desired step, and to subsequently make most stepper motors move at all.

Also attached is a bare bones basic diagram of what is needed to make a stepper work.

More information on stepper motor drivers and what they do can be found here: http://www.element14.com/community/message/55439#55439/l/arduino-motor-shield-canakit-stepper-motor http://www.element14.com/community/docs/DOC-33352/l/an2820-driving-bipolar-stepper-motors-using-a-medium-density-stm32f103xx-microcontroller

If I had more time I could defiantly make this project work with my new knowledge. When I learned about the stepper driver it opened a whole other world of knowledge that just did not exist before trying to work with Arduino Uno alone.

The culmination of my work was added here: http://en.wikiversity.org/wiki/Arduino/Motor_Control/DCMotors

Team Page
Arduino Motor Control/P2-501 CDMN