Unit-3 4
Unit-3 4
DEPARTMENT OF ECE
Bachelor of Engineering (Electronics And Communication
Engineering)
Arduino Based System Design
Interfacing Motor with Arduino
4
Selecting DC Motor
• The operating voltage This can vary, from 3 V to more than 12 V.
• The current without a load The amount of current the motor uses at
its operating voltage while spinning freely, without anything connected
to the motor’s shaft.
• The stall current The amount of current used by the motor when it is
trying to turn but cannot because of the load on the motor.
• The speed at the operating voltage The motor’s speed in revolutions
per minute (RPM).
5
Interfacing DC Motor
We will do three program examples with DC motor -
• Just make your motor spin
• Control motor speed
Components required
• 1x Arduino UNO board
• 1x PN2222 Transistor
• 1x Small 6V DC Motor
• 1x 1N4001 diode
• 1x 270 Ω Resistor
7
Interfacing Diagram
8
Example 1 for Spin Control
int motorPin = 3;
void setup()
{
pinMode(motorPin, OUTPUT);
}
void loop()
{
digitalWrite(motorPin, HIGH);
}
9
Point to be note
• The transistor acts like a switch, controlling the power to the motor.
• Arduino pin 3 is used to turn the transistor on and off and is given the
name 'motorPin' in the sketch.
Result
• Motor will spin in full speed when the Arduino pin number 3 goes
high.
10
Example 2 Motor Speed Control
void setup()
{
pinMode(9, OUTPUT);
}
void loop()
{
u for (int a=0; a<256; a++)
{
analogWrite(9, a);
delay(100);
}
delay(5000);
for (int a=255; a>=0; a--)
{
analogWrite(9,a);
delay(100);
}
delay(5000);
}
11
Result
• The DC motor will spin with different speeds according to the value (0
to 255).
12
Selecting a Servo Motor
When you’re selecting a servo, consider several parameters:
• Speed - The time it takes for the servo to rotate, usually measured in seconds per angular
degree.
• Rotational range - The angular range through which the servo can rotate— for example, 180
degrees (half of a full rotation) or 360 degrees (one complete rotation).
• Current - How much current the servo draws. When using a servo with an Arduino, you may need
to use an external power supply for the servo.
• Torque - The amount of force the servo can exert when rotating. The greater the torque, the
heavier the item the servo can control. The torque produced is generally proportional to the
amount of current used.
13
Example 4 - Servo motor rotation angle
control
• #include <Servo.h> // servo library
• Servo myservo;
• void setup()
• {
• myservo.attach(4); // Servo is connected to digital pin 4 of arduino
• }
• void loop()
• {
• myservo.write(180); // servo will rotate between 0 to 180 degree
• delay(1000);
• myservo.write(90);
• delay(1000);
• myservo.write(0);
• delay(1000);
• }
14
Applications of Servo Motor
• servos are used in radio-controlled airplanes to position control
surfaces like the elevators and rudders.
• They are also used in radio-controlled cars, puppets, and of course,
robots.
• Servos are extremely useful in robotics. The motors are small, have
built-in control circuitry, and are extremely powerful for their size
15
THANK YOU