For output devices week I need to control motors with
Arduino UNO board and Arduino motor shield Rev3.
To achieve that goal I will start experimenting with motors and motor-shield.


DC Motors Servo Motors Stepper Motors
DC motor is the most common type of engine that can be used for many applications. We can see it in remote control cars, robots, and etc. This motor has a simple structure. It will start rolling by applying proper voltage to its ends and change its direction by switching voltage polarity. DC motors speed is directly controlled by the applied voltage. When The voltage level is less than the maximum tolerable voltage, the speed would decrease. Servo motor is a simple DC motor with a position control service. By using a servo you will be able to control the amount of shafts rotation and move it to a specific position. They usually have a small dimension and are the best choice for robotic arms. But we can’t connect these motors to microcontrollers or controller boards such as Arduino directly in order to control them since they possibly need more current than a microcontroller can drive so we need drivers. The driver is an interface circuit between the motor and the controlling unit to facilitate driving. Drives come in many different types. In some projects such as 3D printers, scanners, and CNC machines we need to know motor spin steps accurately. In these cases, we use Stepper motors. Stepper motor is an electric motor that divides a full rotation into a number of equal steps. The amount of rotation per step is determined by the motor structure. These motors have very high accuracy.

Motor shield

The Arduino Motor Shield Rev3 is built around the L298 dual full-bridge driver, made by STMicroelectronics. With
the shield, you can drive DC motors, a stepper motor, relays, and solenoids. It comes with two separate channels,
called A and B, that you can use to drive 2 DC motors, or 1 stepper motor when combined.


As it was mentioned above stepper motors are very accurate and divide rotation to the small steps. Stepper motors
are DC motors that move in discrete steps. They have multiple coils that are organized in groups called "phases".
By energizing each phase in sequence, the motor will rotate, one step at a time. With a computer-controlled stepping,
you can achieve very precise positioning and/or speed control.

Controling stepper motor

first of all, I need to connect the stepper motor to board using channels A and B each channel to one coil if the stepper
has 6 pis instead of 4 we can ignore middle viers of each coil and it will work just okay. there are many libraries for controlling
steppers but it is possible to control them without using any library simply turning on each coil separately in the right sequence.
to make it more simple each channel is connected to one coil and I’m turning on each coil separately to make the motor rotate. However,
I found the stepper with 4 pins and go around with it.


int delaylegnth = 30; void setup() { //establish motor direction toggle pins pinMode(12, OUTPUT); //CH A -- HIGH = forwards and LOW = backwards??? pinMode(13, OUTPUT); //CH B -- HIGH = forwards and LOW = backwards??? //establish motor brake pins pinMode(9, OUTPUT); //brake (disable) CH A pinMode(8, OUTPUT); //brake (disable) CH B } void loop(){ digitalWrite(9, LOW); //ENABLE CH A digitalWrite(8, HIGH); //DISABLE CH B digitalWrite(12, HIGH); //Sets direction of CH A analogWrite(3, 255); //Moves CH A delay(delaylegnth); digitalWrite(9, HIGH); //DISABLE CH A digitalWrite(8, LOW); //ENABLE CH B digitalWrite(13, LOW); //Sets direction of CH B analogWrite(11, 255); //Moves CH B delay(delaylegnth); digitalWrite(9, LOW); //ENABLE CH A digitalWrite(8, HIGH); //DISABLE CH B digitalWrite(12, LOW); //Sets direction of CH A analogWrite(3, 255); //Moves CH A delay(delaylegnth); digitalWrite(9, HIGH); //DISABLE CH A digitalWrite(8, LOW); //ENABLE CH B digitalWrite(13, HIGH); //Sets direction of CH B analogWrite(11, 255); //Moves CH B delay(delaylegnth); }

Stepper motor

Controling DC motor

DC motors are the most common type of electric motors and easiest in use. To control Dc motor I connect it
to channel A using jumpers. and with simple code make it rotate wit delays.

Rotat with delays

The next challenge was to make it rotate in 2 directions clockwise and counterclockwise. For that I need a H-bridge.
An H-bridge is an electronic circuit that switches the polarity of a voltage applied to a load. These circuits are often
used in robotics and other applications to allow DC motors to run forwards or backwards.
Most DC-to-AC converters (power inverters), most AC/AC converters, the DC-to-DC push–pull converter, most motor controllers,
and many other kinds of power electronics use H bridge.


In fact I donn't need to make the H-bridge because the shield hes it builtin.

void setup() { //Setup Channel A pinMode(12, OUTPUT); //Initiates Motor Channel A pin pinMode(9, OUTPUT); //Initiates Brake Channel A pin } void loop(){ //forward @ full speed digitalWrite(12, HIGH); digitalWrite(9, LOW); analogWrite(3, 255); delay(1000); digitalWrite(12, LOW); digitalWrite(9, LOW); delay(1000); digitalWrite(12,LOW); digitalWrite(9, HIGH); delay(1000); }

Dc motor cw and ccw

Usefull links


I combined the input and output devices weeks and use the sensor to control both side rotation in
distance. To see ther result go here
There are many libraries for Arduino use them and twise more tutorials for them.