Anda di halaman 1dari 4

UG 106: Praxis I September 2012 Semester Undergraduate Program Asian Insitute of Technology Handout: Arduino Tutorial DC Motor Motion

Control Instructors: Waqar Shahid, Matthew N. Dailey

Arduino Tutorial DC Motor Motion Control

Introduction:
In this tutorial we will learn how to run and control motion of a simple DC motor using a Arduino Uno Rev3 with the help of an motor driving integrated circuit chip. We will also learn to control the speed of the motor using PWM, which we generated last time.

Hardware Summary
There are three type of motors which you may come across in robotics application, DC motor, servo motor, and stepper motor. Today we will learn how to use DC motor. DC Motor: is a motor that runs on DC voltage. The toy cars and robots may have one or more DC motors to move their wheels or arms. In fact in robotics it is the most popular one. It is composed of a permanent cylindrical magnets and a wire wound shaft. It has two power connections to apply the voltage. One is termed as positive and the other is negative. If we apply at least 1.5 volts DC to the motor it will start moving in a clockwise direction, It can accept upto 6 volts. If we reverse the polarity then it will move in the opposite direction. It is called as a 3 volt motor due to the typical voltage rating. The current required to move the motor is higher than the Arduino pin can directly supply. Arduino, as mentioned previously, can only provide 40mA current through its portspins, which is not sucient to run motors which require more than 40mA current. To use Arduino for such type of control applications we usually use either a MOSFET transistor or some other integrated circuit (IC) chip. H-bridge IC Chip: An H-bridge motor driver IC is used to control the motor. The pin conguration of the IC is shown in the data-sheet. Usually information regarding the electric or electronic device is available on a data-sheet, which is published by the relevant manufacturer. It gives you the function of the device, complete conguration of each pin on the device and sometimes even internal circuit in case of an integrated circuit. It also gives us the complete mechanical and electrical characteristics of that component. Please go through the data-sheet of L293D IC, attached as appendix-A. It will brief you as how much current or voltage can be given to input pins or can be taken from output pins. L239D is a 16-bit IC, with 2-channel motor control or in other words, you can control and move two motors using this IC both in clockwise and anti-clockwise direction. Each channel has a separate enable pin, 2 input pins, 2 ground pins, and 2 output pins. We will use only one channel for todays experiment. There is one supply voltage pin and a logic reference voltage pin. Output-1 and output-2 will be plugged to positive and negative terminal of the DC motor. The rest of the details are mentioned in the next section. For revision the summary of the boards specications is follows:

Microcontroller Operating Voltage Input Voltage (recommended) Input Voltage (limits) Digital I/O Pins Analog Input Pins DC Current per I/O Pin DC Current for 3.3V Pin Flash Memory SRAM EEPROM Clock Speed

ATmega328 5V 7 12V 6 20V 14 (of which 6 provide PWM output) 6 40 mA 50 mA 32 KB (ATmega328) of which 0.5 KB used by bootloader 2 KB (ATmega328) 1 KB (ATmega328) 16 MHz

Simple DC Motor Motion Control


Components required For this Lab we need the following equipment and components: 1. Arduino UNO R3 2. Proto-board 3. Digital Oscilloscope 4. Digital Multimeter 5. Jumpers (connecting wires) 6. Light emitting diode (LED) 7. Resistors ( 470) or ( 220) 8. DC Motor 9. L293D IC 10. push button 11. 5 Volts D.C power supply Arduino pin numbers
Pin 2 as switch pin pin 12 as positive terminal of motor pin 05 as negative terminal of motor pin 04 as enable pin for IC.

You can connect the circuit as shown in the Figure 1a,1. We will use 2 x output pins from the Arduino to control the motion of the DC motors. A switch on or o button is used to control the clockwise or anti-clockwise motion of the motor. Code: Write your program to move the motor, the code given below is not complete, you should be able to write a complete working code till now.
//pin const const const const assignments int switchPin int motor1Pin int motor2Pin int enablePin = = = = 2; 12; 5; 4; // switch input // H-bridge leg 1 (pin 2, 1A) // H-bridge leg 2 (pin 7, 2A) // H-bridge enable pin

(a) Schematics generated by Fritzing-0.7.7b

(b) Diagram generated by Fritzing-0.7.7b

Figure 1: Implementation Diagram The Setup function


pinMode(switchPin, INPUT); set all the other pins you're using as outputs: pinMode(motor1Pin, OUTPUT); pinMode(motor2Pin, OUTPUT); pinMode(enablePin, OUTPUT); // set enablePin high so that motor can turn on:we do not need to repeat digitalWrite(enablePin, HIGH);

// if the switch is high, motor will turn on one direction: if (digitalRead(switchPin) == HIGH) { digitalWrite(motor2Pin, HIGH); digitalWrite(motor1Pin, LOW); } // if the switch is low, motor will turn in the other direction: else { digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge high digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge low } // set leg 2 of the H-bridge high // set leg 1 of the H-bridge low

Conclusion and results: Press cntrl-R to compile the code. If there is no errors, then press cntrl-U to upload the compiled program on your C Flash memory. As told earlier, once the program is uploaded successfully, the board will automatically get a reset and after a few second will start running your code. Press the push button to check if the motor moves in the opposite direction when the signal at pin-2 is high.

Controlling Speed of DC Motor Using PWM


As told in the previous lab that we can make use of the PWM to control the devices which require analog voltage. A square-wave of 50% duty-cycle, i.e. goes on for 50% of the cycle and goeso for the rest of

the cycle have an average voltage of half as much as the maximum voltage of the pulse. Therefore, reducing the output voltage across the motor, which in turn makes the motor runs slower than at maximum voltage. In this section we will make use of the square wave at the PWM pin which you generated in your assignment. Connect the In-1 and In-2 of the L293D to pin-3 and pin-5 of Arcuino respectively. Both pin-3 and pin-5 generates PWM signal by default. You may change the enable pin of L293D to pin-9. Use the pin-13 and show the status of the on or o status of the push button on pin-2. Now, write a program to generate a square-wave of 50% duty-cycle for the motor pin-1. you can set the other pin to 0. Do the same for reverse motion of the motor. Code Write you code for PWM motor control:
\\ Do the pin assignments here

Write the setup function

\\ PWM does not require setup as they generate PWM output by default

Write the loop function


\\ make the LED on, only when the push button is pressed

Conclusion and results: Did you observe the change in the speed of the motor. Now try a smaller value for the duty-cycle. You can make use of oscilloscope to see your PWM signal or the signal to the motors and to measure the average DC voltage, you can use the multi-meter.

References
http://arduino.cc. http://arduino.cc/en/Main/ArduinoBoardUno. http://arduino.cc/en/Guide/Introduction. www.atmel.com/Images/doc8161.pdf. Arduino Programming Notebook by - by Brian W. Evans. Beginning Android ADK with Arduino by Mario Bohmer http://arduino.cc/en/Tutorial/Button http://arduino.cc/en/Tutorial/Blink http://arduino.cc/en/uploads/Main/arduino_Uno_Rev3-02-TH.zip. http://arduino.cc/en/uploads/Main/Arduino_Uno_Rev3-schematic.pdf. http://arduino.cc/en/Main/ArduinoBoardUno. urlhttp://www.aishack.in/2010/07/the-three-motors-youll-ever-use-in-robotics/

Anda mungkin juga menyukai