You are on page 1of 21

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/342425973

Arduino Project Report - Academic Project

Preprint · November 2018

CITATIONS READS
0 73,062

1 author:

Syed Tasnim Ahmed


Carleton University
4 PUBLICATIONS 0 CITATIONS

SEE PROFILE

All content following this page was uploaded by Syed Tasnim Ahmed on 24 June 2020.

The user has requested enhancement of the downloaded file.


MCG 5184 Mechatronics

Arduino Project Report

Group 7

Syed Tasnim Ahmed


Student No.: 0300099267

November 26, 2018

1
Contents
1 Introduction 4
1.1 Arduino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Common Components of Arduino Boards . . . . . . . . . . . . . . . . . . . . . . . . . 4

2 Components Description 6
2.1 Arduino UNO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2 Breadboard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 DC Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.4 Servo Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.5 Transistor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.6 H-bridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.7 Potentiometer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.8 External Power Source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.9 Arduino Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

3 Project 1 8
3.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2 Necessary Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.3 Experimental Planning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.4 Experimental Circuit Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.5 Arduino Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.6 Observation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.7 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

4 Project 2 11
4.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.2 Necessary Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.3 Experimental planning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.4 Experimental Circuit Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.5 Arduino Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.6 Observation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4.7 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

5 Project 3 (Voluntary Project) 16


5.1 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.2 Necessary Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.3 Experimental Planning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.4 Experimental Circuit Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5.5 Arduino Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.6 Observation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.7 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

6 Conclusion 18

2
7 References 18

8 Appendices 19
8.1 Appendix 1 : Code for Project 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
8.2 Appendix 2 : Code for Project 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
8.3 Appendix 3: Code for Project 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

List of Figures
1 Common Components of Arduino Boards . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3 Circuit Schematic for Project-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4 Experimental Layout of the circuit 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
5 Output Graph using Arduino Serial Plotter function . . . . . . . . . . . . . . . . . . . 10
6 H-bridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
7 Circuit Schematic for Project-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
8 Experimental Layout of the circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
9 Output Graph for Project 2 using Arduino Serial Plotter function . . . . . . . . . . . 15
10 Experimental Layout of the circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

3
1 Introduction
1.1 Arduino
Arduino comprises of both a physical programmable circuit board (commonly known as a microcon-
troller) and a programming software, or IDE (Integrated Development Environment) that can be run
on a PC, used to compose and transfer PC code to the circuit board. It can be done by using the
Arduino programming language (based on Wiring), and the Arduino Software (IDE), based on Pro-
cessing. Unlike other programmable circuit boards, the Arduino does not require a different equipment
(called a software engineer) to upload code to the circuit board, one can essentially utilize a USB link.
Also, the Arduino IDE utilizes a rearranged rendition of C++, making it simpler to figure out how
to program. In a word, Arduino make the functions of the micro-controller into a more accessible
package. The Uno is one of the more prevalent boards in the Arduino family and an extraordinary
option for the beginners. [6]

1.2 Common Components of Arduino Boards


There are different types of Arduino boards for different purposes. But all the boards have the majority
of following components in common.

Figure 1: Common Components of Arduino Boards


[1]

Starting clockwise from the top center: [1]


• Analog Reference pin (orange)

• Digital Ground (light green)

• Digital Pins 2-13 (green)

• Digital Pins 0-1/Serial In/Out - TX/RX (dark green) - These pins cannot be used for digital
i/o (digitalRead and digitalWrite) if serial communication is also being used (e.g. Serial.begin).

4
• Reset Button - S1 (dark blue)
• In-circuit Serial Programmer (blue-green)
• Analog In Pins 0-5 (light blue)
• Power and Ground Pins (power: orange, grounds: light orange)
• External Power Supply In (9-12VDC) - X1 (pink)
• Toggles External Power and USB Power (place jumper on two pins closest to desired supply) -
SV1 (purple)
• USB (used for uploading sketches to the board and for serial communication between the board
and the computer; can be used to power the board) (yellow

Digital Pins
The digital pins on an Arduino board can be used for general purpose input and output via the pin-
Mode(), digitalRead(), and digitalWrite() commands. Each pin has an internal pull-up resistor which
can be turned on and off using digitalWrite() (w/ a value of HIGH or LOW, respectively) when the
pin is configured as an input. [1]

• Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data.[1]
• External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low
value, a rising or falling edge, or a change in value.[1]
• PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function. On
boards with an ATmega8, PWM output is available only on pins 9, 10, and 11.[1]

Analog Pins
The analog input pins support 10-bit analog-to-digital conversion (ADC) using the analogRead()
function. Most of the analog inputs can also be used as digital pins: analog input 0 as digital pin 14
through analog input 5 as digital pin 19. [1]

Power Pins
• 9V: The input voltage to the Arduino board when it’s using an external power source (as opposed
to 5 volts from the USB connection or other regulated power source). Different boards accept
different input voltages ranges. [1]
• 5V: The regulated power supply used to power the microcontroller and other components on
the board. This can come either from VIN via an on-board regulator, or be supplied by USB or
another regulated 5V supply.[1]
• 3V3: (Diecimila-only) A 3.3 volt supply generated by the on-board FTDI chip. [1]
• GND: Ground pins.

5
2 Components Description
2.1 Arduino UNO
The Uno is one of the most popular Arduino boards. It consists of 14-digital I/O pins, where 6-pins
can be used as PWM(pulse width modulation outputs), 6-analog inputs, a reset button, a power jack,
a USB connection and more. It includes everything required to hold up the microcontroller; simply
attach it to a PC with the help of a USB cable and give the supply to get started with a AC-to-DC
adapter or battery. [7]

2.2 Breadboard
A breadboard is a construction base for prototyping of electronics. In the 1970s the solderless bread-
board (a.k.a. plugboard, a terminal array board) became available and nowadays the term ”bread-
board” is commonly used to refer to these. Because the solderless breadboard does not require
soldering, it is reusable. This makes it easy to use for creating temporary prototypes and experiment-
ing with circuit design. For this reason, solderless breadboards are also popular with students and
in technological education. A variety of electronic systems may be prototyped by using breadboards,
from small analog and digital circuits to complete central processing units (CPUs).[7]

2.3 DC Motor
DC motor is any of a class of rotary electrical machines that converts direct current electrical energy
into mechanical energy. The most common types rely on the forces produced by magnetic fields.
Nearly all types of DC motors have some internal mechanism, either electromechanical or electronic,
to periodically change the direction of current flow in part of the motor. A DC motor’s speed can
be controlled over a wide range, using either a variable supply voltage or by changing the strength of
current in its field windings. Small DC motors are used in tools, toys, and appliances. The universal
motor can operate on direct current but is a lightweight brushed motor used for portable power tools
and appliances.[7]

2.4 Servo Motor


A servomotor is a rotary actuator or linear actuator. It can precisely control angular or linear position,
velocity and acceleration. It consists of a suitable motor coupled to a sensor for position feedback. It
also requires a relatively sophisticated controller, often a dedicated module designed specifically for
use with servomotors.

2.5 Transistor
A transistor is a semiconductor device used to amplify or switch electronic signals and electrical power.
It is composed of semiconductor material usually with at least three terminals for connection to an
external circuit. A voltage or current applied to one pair of the transistor’s terminals controls the
current through another pair of terminals. Because the controlled (output) power can be higher than
the controlling (input) power, a transistor can amplify a signal. Today, some transistors are packaged
individually, but many more are found embedded in integrated circuits.[7]

6
(a) Arduino UNO (b) Breadboard (c) DC Motor (d) H-bridge

(e) Transistor (f) Potentiometer (g) 9V Battery (h) Servomotor

Figure 2: Components

2.6 H-bridge
An bridge is an integrated circuit (IC) 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 bridges.
In particular, a bipolar stepper motor is almost invariably driven by a motor controller containing
two H bridges.[7]

2.7 Potentiometer
A potentiometer is a three-terminal resistor with a sliding or rotating contact that forms an adjustable
voltage divider. If only two terminals are used, one end and the wiper, it acts as a variable resistor
or rheostat. The measuring instrument called a potentiometer is essentially a voltage divider used
for measuring electric potential (voltage); the component is an implementation of the same principle,
hence its name.[7]

2.8 External Power Source


For stand-alone operation, the board is powered by a battery rather than through the USB connection
to the computer. While the external power can be anywhere in the range of 6 to 24 V (for example,
you could use a car battery), a standard 9 V battery is convenient. While you could jam the leads
of a battery snap into the Vin and Gnd connections on the board, it is better to connect the battery
snap leads to a DC power plug and connect to the power jack on the board.[7]

7
2.9 Arduino Software
The open-source Arduino Software (IDE) makes it easy to write code and upload it to the board.
The environment is written in Java and based on Processing and other open-source software. This
software can be used with any Arduino board.

3 Project 1
3.1 Objective
The objective of this project is to get the Arduino to spin a shaft in only one direction using a DC
motor.

3.2 Necessary Components


Arduino UNO, Breadboard, DC Motor, 1 Transistor, 1 Battery(9V), 1 Diode, 1 Switch or pushbutton,
2 LED, 1 Resistors (10 kilo ohm), wires, tape.

3.3 Experimental Planning


When current is passed through a DC motor , it spins continuously in one direction until the current
stops. Unless specifically marked with a +(ve) or -(ve), DC motors have no polarity, meaning that
one can swap the two wires over to reverse the direction of the motor. To spin the motor, we have
to send 5V through it and then to ground. By using a transistor in the circuit after the motor, we
can enable the Arduino to control the motor’s power. Transistor is a semiconductor device used to
amplify or switch electronic signals and electrical power and it can be actuated by Arduino’s digital
pins. In our project 1, the transistor is controlled by digital pin 9. This circuit has one problem that
there is a slight chance of having a reverse current due to the momentum of the motor as it slows
down, or in light of the fact that the motor could be turned. If reverse current is produced, it goes
from the negative side of the motor and tries to locate the most effortless route to ground. [3] This
route might be through the transistor or through the Arduino. For Arduino’s safety, a diode is used
which blocks the current from flowing back to the Arduino.

3.4 Experimental Circuit Setup


• First, power and ground was connected to the breadboard through the Arduino.

• A momentary switch was added to the board, connecting one side to power and the other side
to digital pin 2 on the Arduino. For a pull-down resistor, a 10-kilo ohm resistor was added to
ground on the output pin of the switch.

• As there was 2 circuits with different voltages, their ground mus be connected together to provide
a common ground. 9V battery was connected the other side of the breadboard.

• The transistor was placed on the board in a way that the metal tab was facing away from us.
Then digital pin 9 was connected to the left pin on the transistor. This pin is called the gate.
A change in voltage in the gate makes a connection between the other two pins. One end of the

8
Figure 3: Circuit Schematic for Project-1

motor was connected to the middle pin of the transistor. This pin is called the drain. When the
Arduino activates the transistor by supplying voltage to the gate, this pinget connected to the
third pin, known as the source. The source was connected to the ground. [4]

• After that, the motor’s voltage supply was connected to the motor and breadboard. The last
component to be added is the diode. The diode is a polarized component, it can go only one
way in the circuit. Notice that the diode has a stripe on one end. That end is the negative end,
or cathode, of the diode. The other end is the positive end, or anode. The anode of the diode
has to be connected to the ground of the motor and the cathode of the diode to the power of the
motor. This was the diode will prevent any everse-voltage generated by the motor from going
back into the circuit.[4]

3.5 Arduino Code


The code for project 1 is provided in Appendix 1. It is similar to the code provided in the project
manual.

3.6 Observation
In this project, only one input signal which is obtained from the switch and one output signal which
goes to the transistor is used. For better understanding the current flow in the circuit an LED is
connected to the switch in series as an indicator. When current passes through the switch, it turned
on. As the switch is pushed, Arduino board receives the input signal. As per the code programmed
in the Arduino board, it sends an output signal in the form of a low voltage current (approximately 5
volts) to the gate pin of the transistor, which allows the high voltage current (approximately 9 volts)
of the battery through the source and drain pin of the transistor and finally to the motor which results

9
Figure 4: Experimental Layout of the circuit 1

is motor spinning. The switched has to be pressed the entire time to spin the motor and when the
switch is turned off the motor stops spinning.
With the help of the Arduino Serial Plotter function in Arduino IDE, a graph is plotted using serial
data from out Arduino to computer in real time. The X axis indicates time and the Y axis indicates
the magnitude of the output.When the switch is pressed, the Arduino Board send output signal which
is depicted by the blue line in the graph.

Figure 5: Output Graph using Arduino Serial Plotter function

10
3.7 Discussion
• After connecting all the component as advised in the manual, our motor didn’t spin at first. We
thought if any component was broken. We went through the procedure again with different sets
of components but didn’t have any luck with that too. Then we noticed the battery became
very hot when we pressed the switch. AS a result, we came to a conclusion that there may exist
a short in our breadboard and we were right. Power rail on one side was shorted. So we used a
component rail to connect the battery and the motor and in this way we managed to make the
motor spin.

• It was also our plan to use the LCD, but as the breadboard is small and one power rail is shorted,
we couldn’t do it.

• If the diode is not placed properly, the back voltage generated by the motor may harm the
arduino as well as the usb port of the pc that the arduino is connected to.

• A well organized and clean code with proper side comments and variable names is desirable.
Sometimes A small mistake in the code can make the entire program fail. If that happens, it
can be revised easily.

4 Project 2
4.1 Objective
The objective of this project is to control the direction of spin of a DC motor using Arduino UNO
and an H Bridge.

4.2 Necessary Components


Arduino UNO, Breadboard, DC Motor, H-Bridge (L293DNE IC), Potentiometer, 4 LED, 4 Resistors
(10 kilo ohm), Wires,

4.3 Experimental planning


A DC motor spins when its two leads, one positive and one negative is connected directly to a power
source. If the leads are switched, the motor will spin in the opposite direction.
An H-Bridge circuit can be used to control the direction of spin of a DC motor, without switching
the leads connection. It has four switching element within it and they are often called high side left,
high side right, low side right, and low side left (when traversing in clockwise order). An H-bridge
with a dc motor load is shown in figure 6(a). The motor will be turned on when the switches that are
diagonally opposite are on. For clockwise spin of the shaft, the high left and low right side switches
must be turned on. To rotate the motor shaft counter-clockwise, the high right and low left must be
turned on.
[3]
The potentiometer can control the speed of rotation. It has 3 pins and center pin has to be connected
with the analogue pin A0 on arduino. By rotating the regulator of the Potentiometer, it varies the

11
input current. This variation is sensed by the Arduino and Pulse Width Modulation PMW allows the
variation the rotational speed of the motor shaft.

(a) Working of an H-bridge (b) Pin Diagram of an H-bridge

Figure 6: H-bridge
[2]

4.4 Experimental Circuit Setup


1. First, power and ground was connected to the breadboard through the Arduino.

2. 2 momentary switches were placed on the breadboard, connecting one side of each to power. A
10 kilo ohm pull-down resistor ware connected in series with ground on the output pin of both
switches. The switch on pin 4 will control direction, the switch on pin 5 will turn the motor on
and off. [3]

3. Two LEDs were connected to the two switches in series as an indicator of whether current passes
through the switches when they are turned on. The Red LED is connected to the power switch
and the Green LED is connected to the direction switch.

4. A potentiometer was placed on the breadboard and it’s pins were connected: one pin to 5V,
center pin to Analogue input A0 of the Arduino and the last pin to the ground. Potentiometer
can vary the input current, this variation is sensed by the Arduino and then control Pulse Width
Modulation (PWM). PWM allows us to vary the rotational speed of the motor shaft.

5. The H-bridge was placed on centre of the breadboard so that both side of the breadboard is
connected (figure 8) . Pin 1 of the H-bridge is connected to digital pin 9 on the Arduino. This
is the enable pin on the H-bridge. When it receives 5V, it turns the motor on, when it receives
0V, it turns the motor off. We used this pin to PWM the H-bridge, and adjust the speed of the
motor. [3]

6. Pin 2 on the H-bridge was connected to digital pin 3 on the Arduino and pin 7 to digital pin
2. These are the pins we used to communicate with the H-bridge, telling it which direction to
spin. If pin 3 is LOW and pin 2 is HIGH, the motor will spin in one direction. If pin 2 is LOW
and pin 3 is HIGH, the motor will spin in the opposite direction. If both the pins are HIGH or
LOW at the same time, the motor will stop spinning. [3]

12
Figure 7: Circuit Schematic for Project-2
[3]

7. The H-bridge gets its power from pin 16, so it was plugged into 5V on Arduino. Pins 4 and 5
both were connected to the ground. [3]

8. Motor was attached to pins 3 and 6 on the H-bridge. These two pins will switch on and off
depending on the signals sent to pins 2 and 7. [3]

9. The battery connector should be plugged without the battery, to the other power rails on the
breadboard. As the other power rails is shorted, we plugged it on the component rail and used
that rail as the power rail. Ground from the Arduino was connected to the battery’s ground.
Pin 8 of the H-bridge was connected to the battery power. This is the pin that the H-bridge
powers the motor from. [3]

4.5 Arduino Code


The code for project 2 is provided in Appendix 2. It is similar to the code provided in the project
manual.

4.6 Observation
In this project we use 2 digital inputs and one analog input. All the outputs from the Arduino board
goes to the different pins of the H-Bridge.

When the power switch is pressed, the red LED lights up and the shaft of motor starts to rotate
in a direction depending on the motor’s connection. When the direction switch is pressed then the
green LED lights up and the motor changes its direction of rotation. We used 2 more LED between
the H-bridge and motor. These LED indicates if the motor is rotating in different direction. The
repeated pressing of the switch will repeatedly change the direction of the motor’s rotation and light
up different LEDs. By rotating potentiometer’s regulator, we are able to vary the speed of the motor

13
Figure 8: Experimental Layout of the circuit

for both direction. Finally, if we press the power switch again, it turns off the motor.

With the help of the Arduino Serial Plotter function in Arduino IDE, a graph is plotted using serial
data from out Arduino to computer in real time. The X axis indicates time and the Y axis indicates
the magnitude of the output.When the switch is pressed, the Arduino Board sends output signal which
is depicted by the blue line in the graph.
Figure 9(a) Shows that output current rises steadily at first then falls steadily. Figure 9(b) Shows
the steady increase of output current. Figure 9(c) shows us the steady decline of the output current.
This change in output current in all three cases are due to varying the current flow through the
potentiometer. It is safe to say that there is a proportional relationship between the current flowing
through the potentiometer and the PWM output. Thus controlling the output,can control the the
motor shaft’s rotational speed.

4.7 Discussion
1. The potentiometer provided with the Arduino kit didn’t fit perfectly on the breadboard. It
was loose. As a result, the speed was changing but not uniformly for the same rotation of the
potentiometer regulator.

2. The push-pull switch is a better option than the momentary switches we used. It will simplify
the programs also.

3. The H-bridges was placed very carefully on the centre of the breadboard. If the both switchs
on one side of the H-bridge is on, it creates a short circuit which may burn the H-bridge and
damage Arduino board.

4. It is very important to make sure not to have battery 9V and Arduino 5V power lines in same
connection.

14
(a) Rise and Fall of Output

(b) Steady Rise of Output

(c) Steady Fall of Output

Figure 9: Output Graph for Project 2 using Arduino Serial Plotter function

15
5 Project 3 (Voluntary Project)
5.1 Objective
The objective of this project is to control the rotation of a servo motor within the range of 0 to 180
degrees with the aid of two switches.

5.2 Necessary Components


Arduino UNO, Breadboard, Servo Motor, 2 Switches, Diode, LED, Resistors (10 Kilo-ohm), wires

5.3 Experimental Planning


A Servomotor requires three connection, power, ground and a signal. Two switches are used to obtain
the input signals from the operator which will be processed by the Arduino to provide precise control
of the servo motor arm. A unique header file “¡Servo.h¿” is used so that Arduino can control the servo
motor. And a variable “pos” is declared whose value will decide the position of the servo motors arm.
The two switches “b1” and “b2” are used as digital inputs to the Arduino which means that Arduino
sees the inputs only as HIGH or LOW. Initially the value of “pos” is zero, now as “b1” is pressed
the value of “pos” increases by 10 every 50 milliseconds. In this way the servo motor arm can rotate
to maximum 180 degrees and then it will stop as it cannot move physically beyond that point. Now
now as “b2” is pressed the value of “pos” decreases by 10 every 50 milliseconds. In this way the servo
motor arm can rotate to minimum zero degrees and then it will stop as it cannot move physically
beyond that point.

5.4 Experimental Circuit Setup


1. At first, power and ground were connected to the breadboard through the Arduino.

2. Two momentary switchs were placed on the board, connecting one side to power and the other
sides to pin 7 and 4 on the Arduino. We also added a 10-kilo ohm pull-down resistors to ground
on the output pins of the switches.

3. Two LEDs were connected to the two switches in series as an indicator of whether current passes
through the switches when they are turned on.

4. After that, the power and ground chords of the servomotor were connected through the bread-
board and at last, the signal chord was connected to pin 3 of the Arduino as it supports PWM.

5. We did not connect battery in this project, the servo motor can function with the 5V power
from the Arduino board.

5.5 Arduino Code


The code for project 3 is provided in Appendix 3.

16
Figure 10: Experimental Layout of the circuit

5.6 Observation
This is a very basic but necessary servomotor controlling Projects. The green LED lights up when
the left switch is pressed, showing that it is working. Arduino receives an input signal via pin 7 and it
allows the servo arm to rotate in clockwise direction. Similarly, By pressing the other switch, red LED
lights up and Arduino receives an input signal via pin 4. The servo arm rotate in other(anti-clockwise)
direction.

5.7 Discussion
1. “Delay()” function decides how smooth the rotation of the motor will be. More delay means
less smoothness.

2. Different types of rotation can be achieved using a servo motor. For precision physical movement,
this project is a stepping stone.

3. With a help of a LCD and potentiometer, we can control the angle of rotation. The LCD will
show the angle and controlling the potentiometer, we can achieve desired angle.

6 Conclusion
According to all the observation discussion, it can be said that both project 1, 2 and 3 are a complete
success. The software and the hardware synced together and performed as mentioned in the manual.
Project 1 is a very simple but sufficient exercise to get familiarized with the world of arduino projects.
Project 2 was more difficult than project 1 and demanded a better understanding of the programming

17
language as well as hardware. Project 3 was a beginner level project for servomotors but with this
simple project one can understand how a robotic arm can be controlled precisely with Arduino and
servomotor.

7 References
1. Introduction to the Arduino Board. Retrieved from https://www.arduino.cc/en/
Guide/Board?from=Tutorial.ArduinoBoard [Accessed: 01 Nov, 2018]

2. Controlling a Stepper Motor With an Arduino. Retrieved from https://www.instructables.


com/id/Controlling-a-Stepper-Motor-with-an-Arduino/[Accessed: 04 Nov, 2018]

3. Arduino, Arduino Projects Book. Torino, Italy, 2015

4. MCG 5184, Mechatronics Laboratory Manual, edited by Theja Ram Pingali, Ot-
tawa, 2017

5. C. McManis, ”H-Bridge Theory and amp; Practice — Chuck’s Robotics Note-


book.” Retrieved from http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/
[Accessed: 07 Nov, 2018]

6. Ben, ”What is an Arduino? - learn.sparkfun.com.” Retrieved from https://learn.


sparkfun.com/tutorials/what-is-an-arduino [Accessed: 01 Nov, 2018]

7. Components. Retrieved from https://store.arduino.cc/usa/components [Accessed:


05 Nov, 2018]

8 Appendices
8.1 Appendix 1 : Code for Project 1
const int switchPin = 2;
const int motorPin = 9;
int switchState = 0;
void setup() {
pinMode(motorPin,OUTPUT);
pinMode(switchPin,INPUT);
}
void loop() {
switchState = digitalRead(switchPin);
if(switchState==HIGH)
{digitalWrite(motorPin,HIGH); }
else
{ digitalWrite(motorPin,LOW);}
}

18
8.2 Appendix 2 : Code for Project 2
const int controlPin1 = 2; //Connected to pin 7 on the H-Bridge
const int controlPin2 = 3; //Connected to pin 2 on the H-Bridge
const int enablePin = 9; //Connected to pin 1 on the H-Bridge
const int directionSwitchPin = 4; //Connected to switch for direction
const int onOffSwitchStateSwitchPin = 5; //Connected to switch for turning the motor on and off
const int potPin = A0; //Connected to potentimeter’s output. Create some variables to hold values from input
int onOffSwitchState = 0; //Current state of the On/Off switch
int previousOnOffSwitchState = 0; //Previous position of the direction switch
int directionSwitchState = 0; // Current state of the direction switch
int previousDirectionSwitchState = 0; //Previous state of the direction switch
int motorEnabled = 0; //Enables the motor on/off int motorSpeed = 0; // Speed of the motor int motorDirection
= 1; //Current direction of the motor void setup()
{//Initialize the inputs and outputs
pinMode(directionSwitchPin, INPUT);
pinMode(onOffSwitchStateSwitchPin, INPUT);
pinMode(controlPin1, OUTPUT);
pinMode(controlPin2, OUTPUT);
pinMode(enablePin, OUTPUT);
//Pull the enable pin LOW to start
digitalWrite(enablePin, LOW);}
void loop()
{
//Read the value of the ON/OFF Switch
onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin);
delay(1);
//Read the direction switch
directionSwitchState = digitalRead(directionSwitchPin);
//Read the value of the potentiometer and divide by 4 to get //a value that can be used for PWM
motorSpeed = analogRead(potPin)/4;
//if the ON/OFF button changed state since the last loop()
if (onOffSwitchState != previousOnOffSwitchState)
{
//Change the value of motorEnabled if pressed
if (onOffSwitchState == HIGH)
{motorEnabled = !motorEnabled;}
}
//if the direction button changed state since the last loop()
if (directionSwitchState != previousDirectionSwitchState)
{ //Change the value of motorDirection if pressed
if (directionSwitchState == HIGH)
{motorDirection = !motorDirection;}
}
//Change the direction of motor spins //by controlling the pins on the H-Bridge
if (motorDirection == 1)
{digitalWrite(controlPin1, HIGH);
digitalWrite(controlPin2, LOW);}
else
/ digitalWrite(controlPin1, LOW);
digitalWrite(controlPin2, HIGH);/

19
//if the motor is supposed to be On
if (motorEnabled == 1)
/ //PWM the enable pin to vary the speed
analogWrite(enablePin, motorSpeed);/
else
///if the motor is not supposed to be ON, turn it off
analogWrite(enablePin, 0);/
//Save the current ON/OFF switch state as the previous
previousDirectionSwitchState = directionSwitchState;
//Save the current switch state as the previous
previousOnOffSwitchState = onOffSwitchState;
}
}

8.3 Appendix 3: Code for Project 3


include Servo.h
Servo servo1;
int pos=0;
int b1=7;
int b2=4;
void setup()
{
servo1.attach(3);
pinMode(b1, INPUT);
pinMode(b2, INPUT);
}
void loop()
{
if(digitalRead(b1)==HIGH)
{
pos=pos+10;
servo1.write(pos);
delay(50); }
if(digitalRead(b2)==HIGH )
{
pos=pos-10;
servo1.write(pos);
delay(50);
}
}

20

View publication stats

You might also like