## Introduction

 A great use for Arduinos is to run motors. Arduinos are great to provide code to switch these on and of, back and forth. However, the Arduino may not be robust enough to cary the load of electricity required to run these devices, so a series of solutions can be found. There are four main types of motors Brushed and brushless motorsServosSolenoid and relay motorsSteppers All these motors come in many different sizes and shapes. Remember we inly use 9 volts power supplies here! Type 1 : Brushed and brushless Put simply, a brushed motor is the more familiar electric motor that has a rotor that spins A brushless motor achieves movement by spinning it's outer case, therefore achieving greater torque. Type 2 : Steppers Steppers are contrived to move in discrete "steps", typically 200 per rotation. 50 steps then is 90o and hence steppers can turn to accurate angles. Type 3 : Servos Servos contain a simple analog motor and a potentiometer. The potentiometer tells the microprocessor how far it has travelled in a feedback loop. Type 4 : Relays and solenoids Conclusion

## Assessment : make a simple motor circuit

 Before building our robot, we will use a simple 9 volt motor to demonstrate the principles. Materials 9 v motor header pins stranded connecting wire soldering iron solder Arduino board USB connector breadboard Set up Arduino and breadboard. Assessment  Connect your motor to pins 13 and GND. It should spin when you run blink, indicating all is OK.

## Controlling a motor with a transistor

 detecting input and making decisions /** Button * Mark Weber* adapted from* http://www.arduino.cc/en/Tutorial/Button** The trick is to have the 5v input controlled by pull down resistor* I used a 3K resistor, tute says 2.2K*/// Declare data types and variablesint ledPin1 = 4; // choose the pin for the motorint ledPin2 = 5; // choose the pin for the motorint inputPin = 2; // choose the input pin (for a pushbutton)int val = 0; // declare variable for reading the pin status void setup() {  pinMode(ledPin1, OUTPUT); // declare as output  pinMode(ledPin2, OUTPUT); // declare as output  pinMode(inputPin, INPUT); // declare pushbutton as input  Serial.begin(9600); // you can read the value of the pushbutton // in Tools ==> serial window}void loop(){if (val == HIGH) { // check if the input is HIGH// first one way  digitalWrite(ledPin1, LOW);   digitalWrite(ledPin2, HIGH);  delay(200);  val = digitalRead(inputPin);  Serial.print("val = HIGH, "); // read the value in serial monitor  Serial.println(val); } else {// then the other  digitalWrite(ledPin1, HIGH); //   digitalWrite(ledPin2, LOW); //  delay(200);  val = digitalRead(inputPin);   Serial.print("val = low, "); // read the value in serial monitor  Serial.println(val); }} Can you find the serial window in the ADE? Vocabulary analogue, serial, clock, data types, variables, loops,

## Assessment : writing subroutines

 nd call from /* * Button * Mark Weber * adapted from * http://www.arduino.cc/en/Tutorial/Button * * The trick is to have the 5v input controlled by pull down resistor * I used a 3K resistor, tute says 2.2K */ // Declare data types and variables int ledPin1 = 4; // choose the pin for the motor int ledPin2 = 5; // choose the pin for the motor int inputPin = 2; // choose the input pin (for a pushbutton) int val = 0; // declare variable for reading the pin status void setup() { pinMode(ledPin1, OUTPUT); // declare as output pinMode(ledPin2, OUTPUT); // declare as output pinMode(inputPin, INPUT); // declare pushbutton as input Serial.begin(9600); // you can read the value of the pushbutton // in Tools ==> serial window}void loop(){ if (val == HIGH){ one_way(); } else { other_way(); }} void one_way(){ // first one way digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, HIGH); val = digitalRead(inputPin); } void other_way(){ // then the other digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, LOW); val = digitalRead(inputPin); } assessment write subroutines for forward, back, stop and call from main driver routine, loop. also, pass a global  variable to each routine to control the pause command.

## Controlling a motor's speed : PWM

 To build a robot, we will need to power it. To do so, we need to understand PWM. For now, we will just call it a way to control a device like a volume control using the Arduino and C. A techy introduction Knowlege : the difference between analog and digital. digitalWrte(ledPin, HIGH); analogWrite(ledPin,i); where i changes from a value of 0 to 255 We will start with the blink program just to see if everything is going ok. Pins 3,5,6, 9, 10, 11 can be used for PWM.  Connect you LED to pin 11 and modify your blink code. Run the loop. Skill : be able to write subroutines in C and call them from the main program. Now we will controll the LED with a transistor. We will use an npn transistor (2n2222 or 547). Sparkfun circ-03 Extra for experts : servo motors circ-11 Sparkfuncode11 Skill : Be able to search out a datasheet on the web and deduce from information.

## Controlling motors : l293d, the H bridge

 A motor should be able to spin two ways. To accomplish this, there are a number of ways. transistors h briges relays l293d This is a special chip that handles voltages up to 40 volts. It has 8 pins each side and each side can be made to control one device. Think of it as two chips in one. Vcc is the power input pin. The Arduino only supplies 5 volts so if you want your your motors to run at higher voltage (the point of the chip), connect your voltage to both pins. Inputs : there are four of these and these connect to the pins on the Arduino. These are the pins used to control the chip. Output : there are also four of these. These connect directly to the motors to run them The enable pins must be connected to 5 volts to change their state to HIGH. This enables the chip to function. Enable Interupt1interupt2EnablebInterupt3Interupt4 By changing the OUTPUT command to HIGH or LOW, you can open or close the gates in the chip h bridge theory and practice

## Using the l298 motor driver chip

 /*Robot 1This is the first program for running the simple robot.We just want to make sure the motors spin the right way and the robot moves forward.Note the use of the ena, enb. In the old version of l298, there were 6 inputs. ena and enbare set to HIGH. these can be set by hardware and hence are commented out.Depending on your driver, you can compile these commands or not. Use findand replace to remove the comment out directive if you wish.*/// int ena = 4;int int1 = 5;int int2 = 6;// int enb = 8;int int3 =9;int int4 = 10;int timex = 3000; //runs for 3 secondsboolean run;void setup() {//pinMode (ena,OUTPUT);pinMode (int1,OUTPUT);pinMode (int2,OUTPUT);//pinMode (enb,OUTPUT);pinMode (int3,OUTPUT);pinMode (int4,OUTPUT);run = true;}void loop() {if (run){forward(); // sets the robot forward. // check motors are spinning in same directiondelay(timex);halt(); // stops the code runningrun = false;} }void forward() // forward sub proceedure{//digitalWrite(ena,HIGH);digitalWrite(int1,HIGH);digitalWrite(int2,LOW);//digitalWrite(enb, HIGH);digitalWrite(int3,HIGH);digitalWrite(int4,LOW);}void halt() // halt sub procedure{//digitalWrite(ena,HIGH);digitalWrite(int1,LOW);digitalWrite(int2,LOW);//digitalWrite(enb,HIGH);digitalWrite(int3,LOW);digitalWrite(int4,LOW);}

## Drivers

 a Mechanica : servos and steppers b uln2003 c

## Bi polar stepper motors

 There are two basic winding arrangements for the electromagnetic coils in a two phase stepper motor, one being bipolar and the other unipolar. Unipolar Stepper Motors. The unipolar stepper motor operates with one winding with a center tap per phase.Bipolar Stepper MotorsWith bipolar stepper motors there is only a single winding per phase. unipolar v bipolar 4 wires suggest a standard bipolar 2-phase scheme. You need two full bridge drivers to supply it.You can use 5vdc to 9vdc but motor is started working at 3vdc. But if your motor is warm(normal is not warm) please checked the timing driver.Quick and dirty determine which phasesEach of the two phases should have the same resistance when measured with a multimeter. When measuring the resistance across one wire from each of the two phases, the resistance should be infinite because the circuit is open. Locate the two pairs of wires that represent the two phases; both pairs of wires will have similar internal resistance.

## CD ROM stepper

 /* Stepper Matsushita 02700B4  red to pin 7 (motorpin 4)  white pin 6 (motorpin 3)  blue pin 5 (motorpin 2)  orange pin 4 (motorpin 1)  red - blue are one coil orange - blue the other */  int motorPin1 = 4; int motorPin2 = 5;int motorPin3 = 6; int motorPin4 = 7; int delayTime = 10;  void setup() { pinMode(motorPin1, OUTPUT);  pinMode(motorPin2, OUTPUT);  pinMode(motorPin3, OUTPUT);  pinMode(motorPin4, OUTPUT); } void loop() {  for (int x = 0; x < 100; x++) {  forward(); }  delay(2000); for (int y = 0; y < 100; y++) { reverse(); } delay(2000); }  void forward() {  digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, LOW); delay(delayTime); digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin4, LOW); delay(delayTime); digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin4, HIGH); delay(delayTime); digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, HIGH); delay(delayTime); }  void reverse() { digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin4, HIGH); delay(delayTime); digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, HIGH); delay(delayTime); digitalWrite(motorPin1, HIGH); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, LOW); digitalWrite(motorPin4, LOW); delay(delayTime); digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin4, LOW); delay(delayTime); }

## Stepper motors

 // This Arduino example demonstrates bidirectional operation of a // 28BYJ-48, which is readily available on eBay, using a ULN2003 // interface board to drive the stepper. The 28BYJ-48 motor is a 4-// phase, 8-beat motor, geared down by a factor of 68. One bipolar // winding is on motor pins 1 & 3 and the other on motor pins 2 & 4. // Refer to the manufacturer's documentation of Changzhou Fulling // Motor Co., Ltd., among others. The step angle is 5.625/64 and the // operating Frequency is 100pps. Current draw is 92mA. In this // example, the speed and direction of the stepper motor is determined // by adjusting a 1k-ohm potentiometer connected to Arduino pin A2. // When the potentiometer is rotated fully counterclockwise, the motor // will rotate at full counterclockwise speed. As the potentiometer is // rotated clockwise, the motor will continue to slow down until is // reaches its minimum speed at the the potentiometer's midpoint value . // Once the potentiometer crosses its midpoint, the motor will reverse // direction. As the potentiometer is rotated further clockwise, the speed // of the motor will increase until it reaches its full clockwise rotation // speed when the potentiometer has been rotated fully clockwise.//////////////////////////////////////////////// //declare variables for the motor pinsint motorPin1 = 8; // Blue - 28BYJ48 pin 1int motorPin2 = 9; // Pink - 28BYJ48 pin 2int motorPin3 = 10; // Yellow - 28BYJ48 pin 3int motorPin4 = 11; // Orange - 28BYJ48 pin 4 // Red - 28BYJ48 pin 5 (VCC) int motorSpeed = 500; //variable to set stepper speedint potPin = 2; //potentiometer connected to A2int potValue = 0; //variable to read A0 input //////////////////////////////////////////////////////////////////////////////void setup() { //declare the motor pins as outputs pinMode(motorPin1, OUTPUT); pinMode(motorPin2, OUTPUT); pinMode(motorPin3, OUTPUT); pinMode(motorPin4, OUTPUT); Serial.begin(9600);} //////////////////////////////////////////////////////////////////////////////void loop(){ clockwise(); //go to the ccw rotation function } ////////////////////////////////////////////////////////////////////////////////set pins to ULN2003 high in sequence from 1 to 4//delay "motorSpeed" between each pin setting (to determine speed) void clockwise(){ // 1 digitalWrite(motorPin4, HIGH); digitalWrite(motorPin3, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin1, LOW); delay(motorSpeed); // 2 digitalWrite(motorPin4, HIGH); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin1, LOW); delay (motorSpeed); // 3 digitalWrite(motorPin4, LOW); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin2, LOW); digitalWrite(motorPin1, LOW); delay(motorSpeed); // 4 digitalWrite(motorPin4, LOW); digitalWrite(motorPin3, HIGH); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin1, LOW); delay(motorSpeed); // 5 digitalWrite(motorPin4, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin1, LOW); delay(motorSpeed); // 6 digitalWrite(motorPin4, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin1, HIGH); delay (motorSpeed); // 7 digitalWrite(motorPin4, LOW); digitalWrite(motorPin3, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin1, HIGH); delay(motorSpeed); // 8 digitalWrite(motorPin4, HIGH); digitalWrite(motorPin3, LOW); digitalWrite(motorPin2, LOW); digitalWrite(motorPin1, HIGH); delay(motorSpeed);} zc-a0591 stepper motor driver

## Stepper motors from old 5.25 inch disk drives

 There are a number of stepper motors available from a variety of sources. They can be salvaged from old disk drives, printers and photocopiers. A stepper motor is one that accurately turns in incriments, and needs to be driven with a sequence of steps. Typically a step is equal to 1.8 degrees, but this may vary. With a motor salaged from a Teac 8506 stepper motor, each drive is run by a coil is approx 150 ohms centre tapped. Some of these motors have only 1 common (brown) wire. * Brown (Coil 2 common) * Brown (Coil 1 common) * Yellow (Coil 1 phase 1) * Red (Coil 2 phase 1)  * Blue (Coil 1 phase 2) * White (Coil 2 phase 2)  informations provided via - http://www.audiovisualdevices.com.au/...Other info: 1.8 degree step.Control done via Arduino UNO, and ULN2003AN driver. be aware The stepper requires 12 volts to run. The stepper driver chip gets very hot. Probably not designed to run as analogue motor. Wire with grey stripe is negative. Created 11 Mar. 2007Modified 30 Nov. 2009by Tom Igoe*/ #include #define ledPin 13 const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution// for your motor // initialize the stepper library on pins 8 through 11:Stepper myStepper(stepsPerRevolution, 8,9,10,11); void setup() {// set the speed at 60 rpm:myStepper.setSpeed(60);// initialize the serial port:Serial.begin(9600);} void loop() {// step one revolution in one direction:Serial.println("clockwise");myStepper.step(stepsPerRevolution);delay(500);blink(2);// step one revolution in the other direction:Serial.println("counterclockwise");myStepper.step(-stepsPerRevolution);delay(500); blink(4);}// Blink the reset LED:void blink(int howManyTimes) {int i;for (i=0; i< howManyTimes; i++) {digitalWrite(ledPin, HIGH);delay(200);digitalWrite(ledPin, LOW);delay(200);}}

## Motor controller Shield

anual