Sie sind auf Seite 1von 68

Scan to download

Voice-cum-Gesture
controlled Robot
with arm motion

TEAM

ANSHU KATARIA (1613501)

JITENDER KUMAR (1613627)

RAJAT SARDANA (1613641)

SALIL BATABYAL (1613526)

SUKRITI HANS (1613447)

TANYA VERMA (1613731)


Certificate
This is to certify the work embodied in this Project entitled “Making a voice and gesture control
robot” has been satisfactorily completed by the students of final year M.Sc. Ms. Anshu Karatia,
Mr. Jitender Kumar, Mr. Rajat Sardna, Ms. Sukriti Hans, Mr. Salil Batabyal, Ms. Tanya Verma. The
work was carried out under the supervision and guidance of the undersigned in the Department
of Physics and Astrophysics, University of Delhi for the partial fulfillment of the requirement of
degree of Master of Physics during the academic year 2017-2018.

Prof. Vinay Gupta Prof. Amithabha Mukherjee Prof. K. Srinivas

Prof. Nivedita Deo Dr. Manjula


ABSTRACT
In the project titled “Designing a voice and gesture control robot” we have tried to build a robot
which can perform actions like going forward, backward, left, right, and to grip(hold) and drop an
object. The robot can be controlled either by voice or by gesture. To do this we have designed a
vehicle and attached an arm. We have designed in such a way that the robotic car is used for
translation motion. For movements like grip and drop of an object we will use the arm i.e. the
claw attached in the front of the vehicle.

Here we have used Bluetooth module to transmitting the command from source end to receiver
end. One motor driver has been used to control the two wheels of the vehicle while other two are
free moving.

An android application named “Arduino Bluetooth control” is used. All the commands are given
through this application. Although we have designed another android app which is functioning
well as per the requirement.
Table of Contents
1. INTRODUCTION ...............................................................................................................................
1.1. MOTIVATION .................................................................................................................................... 1
1.2. SCOPE OF THE PROJECT ..................................................................................................................... 2
1.3. SOFTWARE AND HARDWARE USED................................................................................................... 3
1.4. METHODOLOGY ................................................................................................................................. 4
2. FINDING COMPONENTS ...................................................................................................................
2.1. DC MOTOR ....................................................................................................................................... 5
2.2. SERVO MOTOR ............................................................................................................................... 12
2.3. MOTOR DRIVER .............................................................................................................................. 17
2.4. BLUETOOTH MODULE HC-05 ......................................................................................................... 22
2.5. ARDUINO ........................................................................................................................................ 26
3. SOFTWARE ......................................................................................................................................
3.1. ARDUINO IDE ................................................................................................................................. 28
3.2. SIMULATION .................................................................................................................................. 31
3.3. ANDROID APP DEVELOPMENT ....................................................................................................... 33
4. CONCLUSION AND POSSIBLE EXTENSION...................................................................................... 46
APPENDIX A ..................................................................................................................................... 47
APPENDIX B ..................................................................................................................................... 50
APPENDIX C ..................................................................................................................................... 54
BIBLIOGRAPHY................................................................................................................................. 57
foÌq r INTRODUCTION

INTRODUCTION
MOTIVATION
With the advent of 21st century the role of electronics has become an integral part of our life,
electronics is being used from a very small electrical switch to very complicated electronics
equipment like supercomputer.

With the rapid growth in technological advancement, our life has become much easier ever than
before because we are using the electronics equipment and we have become very dependent on
it. Robot is one such electronics advancement which has changed our view about machines.
Basically, robot is a combination of many electrical and electronics components which are
assembled in such way so that they can perform a specific user required or predefined task(s).

In the era of globalization robot is extensively used in industries, transportation, and agriculture,
and in many more places to count. In last two decades robotic advancement is lead to stage that
nowadays robots are also used in homes, offices in many countries.

Keeping in mind the possible uses of robot we the “Vidyut group” has decided to make a robot
which can be controlled by voice and gesture so as to do some specific basic tasks like moving
backward and forward, going left and right etc. Our motivation to build a robot lies in the fact
that through this project we will be able to learn how to use a microcontroller and get to know
how the interface of high level language works. Also, through this project we will learn how to
write a code for a microcontroller like Arduino to do a prefixed task besides interfacing the
different components like Bluetooth module, motor driver etc.

1
foÌq r INTRODUCTION

SCOPE OF THE PROJECT


As we have discussed about the versatility and availability of robots in many places its very true
that a robot which can be controlled by voice and command through a mobile application can be
fit into many applications which can be ranged from industry to home.

This robot can be used by a paralyzed person who cannot move but can give commands through
voice. The above-mentioned robot can be used by any person for task like bringing an item from
a place and dropping it into another place.

Overall the scope of any electronic item depends upon factor like robustness and cost, so far, we
have successfully able to manage to build the same at a very low cost i.e. below `2000.

2
foÌq r INTRODUCTION

SOFTWARE AND HARDWARE USED


Since through this project we are intend to learn the interfacing of software with hardware, so
we have used software, high level language and different hardware, the list is as follows.

At first, we have used an online platform called Tinkercad for designing purpose, we have used
this platform for simulation purpose also.

Hardware Used:
• Bluetooth module
• Motor driver
• Arduino Mega
• Android smartphone

Software Used:
• Arduino IDE

A detailed overview of the above-mentioned list will be discussed later in this report.

3
foÌq r INTRODUCTION

METHODOLOGY
1. Designing of the vehicle:
➢ The basic structure of the vehicle was designed on a platform of wooden board with
four tyres attached to it, giving it the feel of a small toy car.
➢ Robotic arm was fixed to the above structure with a claw attached to it for grabbing,
picking and dropping the objects.
2. DC motors are connected to the tyres of the robotic car for ensuring the translational
motion of the vehicle including the forward, backward, right and left turns.
3. Two SG-90 servo motors are connected to the robotic arm for ensuring the movements of
the arm including the rotation of the arm and claw at precise angles.
4. A motor driver IC L293D is used for driving the dc motors of two tyres, with the other two
left as freely moving.
5. An Android application named ‘Arduino Bluetooth Control’ equipped with ARDUINO IDE
software which is used for programme coding making sure the translational and rotational
motions of the robotic car and arm respectively.
6. HC-05 Bluetooth Module is used as an interface in between the android mobile and Arduino
board to control and communicate with the board.

POINTS TO REMEMBER:

1. One motor driver IC should be used to drive two dc motors (at max).
2. Use precautionary measures while soldering the motor wires to the robotic car, the robotic
body should not be damaged.
3. Ensuring to drive only two back tyres to resist the complexities.

4
foÌq r FINDING COMPONENTS

FINDING COMPONENTS
1. DC MOTOR
DC Motor is a device that converts DC electrical energy to a mechanical energy.

This DC or direct current motor works on the principal, when a current carrying conductor is
placed in a magnetic field; it experiences a torque and has a tendency to move. This is known as
motoring action.

Fig. 2.1

CONSTRUCTION OF DC MOTORS:

• The very basic construction of a DC motor contains a current carrying armature which is
connected to the supply end through commutator segments and brushes.
• The armature is placed in between north south poles of a permanent or an
electromagnet.
• As soon as we supply direct current in the armature, a mechanical force acts on it due to
the electromagnetic effect of the magnet.

CHARACTERISTICS OF DC MOTOR:

• There are two electrical elements of a DC motor, the field windings and the armature. The
armature windings are made up of current carrying conductors that terminate at
a commutator.

5
foÌq r FINDING COMPONENTS

• DC voltage is applied to the armature windings through carbon brushes which ride on the
commutator. In small DC motors, permanent magnets can be used for the stator.
However, in large motors used in industrial applications the stator is an electromagnet.
• When voltage is applied to stator windings an electromagnet with north and south poles
is established. The resultant magnetic field is static (non-rotational).

The field of DC motors can be:

1. Permanent magnet (Permanent magnet stator),


2. Electromagnets connected in series (Wound stator),
3. Shunt (Wound stator), or
4. Compound (Wound stator).

1. PERMANENT MAGNET MOTORS

Fig. 2.2: Permanent Magnet Motor

The permanent magnet motor uses a magnet to supply field flux. Permanent magnet DC
motors have excellent starting torque capability with good speed regulation. A
disadvantage of permanent magnet DC motors is they are limited to the amount of load
they can drive. These motors can be found on low horsepower applications.

Another disadvantage is that torque is usually limited to 150% of rated torque to


prevent demagnetization of the permanent magnets.

6
foÌq r FINDING COMPONENTS

2. SERIES MOTORS

Fig. 2.3: Series DC motor

In a series DC motor, the field is connected in series with the armature. The field is wound
with a few turns of large wire because it must carry the full armature current.

A characteristic of series motors is the motor develops a large amount of starting torque.
However, speed varies widely between no load and full load. Series motors cannot be
used where a constant speed is required under varying loads.

Additionally, the speed of a series motor with no load increases to the point where the
motor can become damaged. Some load must always be connected to a series-connected
motor.

Series-connected motors generally are not suitable for use on most variable speed drive
applications.

It is a variable speed motor. The speed is low at high Page on torque at light or no load;
the motor speed attains dangerously high speed. The motor has a high starting torque.
(Elevators, electric traction)

Industrial Uses:

• Electric traction
• Cranes
• Elevators
• Air compressor
• Vacuum cleaner
• Hair drier
• Sewing machine

7
foÌq r FINDING COMPONENTS

3. SHUNT MOTORS

Fig. 2.4: DC Shunt Motor

In a shunt motor the field is connected in parallel (shunt) with the armature windings.
The shunt-connected motor offers good speed regulation. The field winding can be
separately excited or connected to the same source as the armature.

An advantage to a separately excited shunt field is the ability of a variable speed drive
to provide independent control of the armature and field.

The shunt-connected motor offers simplified control for reversing. This is especially
beneficial in regenerative drives.

It is a constant speed motor. Where the speed is required to remain almost constant
from no load to full load. Where the load has to be driven at a number of speeds and
any one of which is nearly constant.

Industrial use:

• Lathes
• Drills
• Boring mills
• Shapers
• Spinning and weaving machines.

8
foÌq r FINDING COMPONENTS

4. COMPOUND MOTORS

Fig. 2.5: Compound DC motor

Compound motors have a field connected in series with the armature and a separately
excited shunt field. The series field provides better starting torque and the shunt field
provides better speed regulation.

However, the series field can cause control problems in variable speed drive
applications and is generally not used in four quadrant drives.

Differential compound motors are rarely used because of its poor torque characteristics.

Industrial uses:
• Presses Shears
• Reciprocating machine.

WORKING OF DC MOTORS:

1. The key to producing motion is positioning the electromagnet within the magnetic field
of the permanent magnet (its field runs from its north to south poles). The armature
experiences a force described by the left-hand rule.
2. This interplay of magnetic fields and moving charged particles (the electrons in the
current) results in the torque (depicted by the green arrows) that makes the armature
spin.
3. A single, 180-degree turn is all we would get out of this motor if it weren't for the split-
ring commutator — the circular metal device split into halves (shown here in red and
blue) that connects the armature to the circuit.
4. Electricity flows from the positive terminal of the battery through the circuit, passes
through a copper brush to the commutator, then to the armature.

9
foÌq r FINDING COMPONENTS

5. But this flow is reversed midway through every full rotation, because of the two gaps in
the commutator.
6. For the first half of every rotation, current flows into the armature via the blue portion of
the commutator, causing current to flow in a specific direction (indicated by the black
arrows).
7. For the second half of the rotation, though, electricity enters through the red half of the
commutator, causing current to flow into and through the armature in the opposite
direction.
This constant reversal essentially turns the battery's DC power supply into alternating current,
allowing the armature to experience torque in the right direction at the right time to keep it
spinning.
Why DC gear motor used in robot Motor control circuit?
• Safe operation: The low voltage supply provides a level of safety that complies with
machine requirements, “Safety of household and similar electrical appliances”.
• Simple and cost-effective speed.
• Good efficiency.
• Low level of unwanted noise.
• DC MOTOR concept is where gears reduce the speed of the vehicle but increase its torque
is known as gear reduction. DC motor is assembled with multiple gear setups.
• Speed control over a wide range.

Speed of motor is counted in terms of rotations of the soft per minute is called RPM. RPM means
Revolution per Minute. The setup assembles helps to increasing the torque and reduces the
motor speed. All microcontroller-based Robots this type of DC motor can be used.

HOW TO SELECT DC MOTOR?


For light weight robot required low power plastic gear DC motor.

MOTOR USED FOR OUR PROJECT:


HOBBY MOTOR also called BO motor.

Fig. 2.6

10
foÌq r FINDING COMPONENTS

It works well for basic things like making a fan or spinning something pretty fast without much
resistance.

The motor has a normal operating voltage range of 3.0 to 9.0V DC but can handle a max load of
up to 12.0V DC and a no-load speed of 6600±10% RPM (@1.0V DC, 110mA).

Hobby Geared DC BO Motors at right angle are used for creating low cost robotic learning
platform.

SPECIFICATION:

• Weight: 31.00gm
• RPM: 100
• Operating voltage: 3-9V
• Numbers of motors used: 2
Fig. 2.7

11
foÌq r FINDING COMPONENTS

2. SERVO MOTOR
A servomotor is a rotary actuator or linear actuator that allows for precise control of 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.

The servo motor is most commonly used for high technology devices in the industrial application
like automation technology. It is a self-contained electrical device, that rotate parts of a machine
with high efficiency and great precision. The output shaft of this motor can be moved to a
particular angle. Servo motors are mainly used in home electronics, toys, cars, airplanes, etc.

TYPES OF SERVO MOTOR

Servo motors are classified into different types based on their application, such as AC servo
motor, DC servo motor, brushless DC servo motor, positional rotation, continuous rotation and
linear servo motor etc. Typical servo motors comprise of three wires namely, power control and
ground. The shape and size of these motors depend on their applications. RC servo motor is the
most common type of servo motor used in hobby applications, robotics due to their simplicity,
affordability and reliability of control by microprocessors.

1. DC SERVO MOTOR

The motor which is used as a DC servo motor generally have a separate DC source in the field
of winding & armature winding. The control can be archived either by controlling the
armature current or field current. Field control includes some particular advantages over
armature control. In the same way armature control includes some advantages over field
control. Based on the applications the control should be applied to the DC servo motor. DC
servo motor provides very accurate and also fast respond to start or stop command signals
due to the low armature inductive reactance. DC servo motors are used in similar equipment
and computerized numerically controlled machines.

2. AC SERVO MOTOR

AC servo motor is an AC motor that includes encoder is used with controllers for giving closed
loop control and feedback. This motor can be placed to high accuracy and also controlled
precisely as compulsory for the applications. Frequently these motors have higher designs of
tolerance or better bearings and some simple designs also use higher voltages in order to
accomplish greater torque. Applications of motor mainly involve in automation, robotics, CNC
machinery, and other applications a high level of precision and needful versatility.

12
foÌq r FINDING COMPONENTS

3. POSITIONAL ROTATION SERVO MOTOR

Positional rotation servo motor is a most common type of servo motor. The shaft’s o/p
rotates in about 180º. It includes physical stops located in the gear mechanism to stop turning
outside these limits to guard the rotation sensor. These common servos involve in radio-
controlled water, radio-controlled cars, aircraft, robots, toys and many other applications.

4. CONTINUOUS ROTATION SERVO MOTOR

Continuous rotation servo motor is quite related to the common positional rotation servo
motor, but it can go in any direction indefinitely. The control signal, rather than set the static
position of the servo, is understood as the speed and direction of rotation. The range of
potential commands sources the servo to rotate clockwise or anticlockwise as preferred, at
changing speed, depending on the command signal. This type of motor is used in a radar dish
if you are riding one on a robot or you can use one as a drive motor on a mobile robot.

5. LINEAR SERVO MOTOR

Linear servo motor is also similar the positional rotation servo motor is discussed above, but
with an extra gear to alter the o/p from circular to back-and-forth. These servo motors are
not simple to find, but sometimes you can find them at hobby stores where they are used as
actuators in higher model airplanes.

SERVO MOTOR WORKING

The servo motor is actually an assembly of four things: a normal DC motor, a gear reduction unit,
a position-sensing device and a control circuit. The DC motor is connected with a gear mechanism
which provides feedback to a position sensor which is mostly a potentiometer. From the gear
box, the output of the motor is delivered via servo spline to the servo arm. For standard servo
motors, the gear is normally made up of plastic whereas for high power servos, the gear is made
up of metal.

A servo motor consists of three wires- a black wire connected to ground, a white/yellow wire
connected to control unit and a red wire connected to power supply.

The function of the servo motor is to receive a control signal that represents a desired output
position of the servo shaft and apply power to its DC motor until its shaft turns to that position.

It uses the position sensing device to figure out the rotational position of the shaft, so it knows
which way the motor must turn to move the shaft to the instructed position. The shaft commonly
does not rotate freely around similar to a DC motor, however rather can just turn 200 degrees.

13
foÌq r FINDING COMPONENTS

From the position of the rotor, a rotating magnetic field is created to efficiently generate toque.
Current flows in the winding to create a rotating magnetic field. The shaft transmits the motor
output power. The load is driven through the transfer mechanism. A high-function rare earth or
other permanent magnet is positioned externally to the shaft. The optical encoder always
watches the number of rotations and the position of the shaft.

The Servo Motor basically consists of a DC Motor, a Gear system, a position sensor and a control
circuit. The DC motors get powered from a battery and run at high speed and low torque. The
Gear and shaft assembly connected to the DC motors lower this speed into sufficient speed and
higher torque. The position sensor senses the position of the shaft from its definite position and
feeds the information to the control circuit. The control circuit accordingly decodes the signals
from the position sensor and compares the actual position of the motors with the desired
position and accordingly controls the direction of rotation of the DC motor to get the required
position. The Servo Motor generally requires DC supply of 4.8V to 6 V.

APPLICATIONS OF SERVO MOTOR

The servo motor is small and efficient, but serious to use in some applications like precise position
control. This motor is controlled by a pulse width modulator signal. The applications of servo
motors mainly involve in computers, robotics, toys, CD/DVD players, etc. These motors are
extensively used in those applications where a particular task is to be done frequently in an exact
manner.

• The servo motor is used in robotics to activate movements, giving the arm to its precise
angle.
• The Servo motor is used to start, move and stop conveyor belts carrying the product along
with many stages. For instance, product labeling, bottling and packaging
• The servo motor is built into the camera to correct a lens of the camera to improve out of
focus images.
• The servo motor is used in robotic vehicle to control the robot wheels, producing plenty
torque to move, start and stop the vehicle and control its speed.
• The servo motor is used in solar tracking system to correct the angle of the panel so that
each solar panel stays to face the sun.
• The Servo motor is used in metal forming and cutting machines to provide specific motion
control for milling machines
• The Servo motor is used in Textiles to control spinning and weaving machines, knitting
machines and looms
• The Servo motor is used in automatic door openers to control the door in public places like
supermarkets, hospitals and theatres

14
foÌq r FINDING COMPONENTS

Fig. 2.8

WIRE CONFIGURATION

Wire Color Description


Brown Ground wire connected to the ground of system
Red Powers the motor typically +5V is used
Orange PWM signal is given in through this wire to drive the
motor
Table 2.1

TOWERPRO SG-90 FEATURES

• Operating Voltage is +5V typically


• Torque: 2.5kg/cm
• Operating speed is 0.1s/60°
• Gear Type: Plastic
• Rotation: 0°-180°
• Weight of motor: 9gm
• Package includes gear horns and screws

HOW TO USE A SERVO MOTOR

As we know there are three wires coming out of this motor. To make this motor rotate, we have
to power the motor with +5V using the Red and Brown wire and send PWM signals to the Orange
color wire. Hence, we need something that could generate PWM signals to make this motor work,
this something could be anything like a 555 Timer or other Microcontroller platforms like
Arduino, PIC, ARM or even a microprocessor like Raspberry Pie.

15
foÌq r FINDING COMPONENTS

Fig. 2.9

From the picture we can understand that the PWM signal produced should have a frequency of
50Hz that is the PWM period should be 20ms. Out of which the On-Time can vary from 1ms to
2ms. So, when the on-time is 1ms the motor will be in 0° and when 1.5ms the motor will be 90°,
similarly when it is 2ms it will be 180°. So, by varying the on-time from 1ms to 2ms the motor can
be controlled from 0° to 180°.

APPLICATIONS OF SG-90

• Used as actuators in many robots like Biped Robot, Hexapod, robotic arm etc.
• Commonly used for steering system in RC toys
• Robots where position control is required without feedback
• Less weight hence used in multi DOF robots like humanoid robots

ALTERNATIVES FOR SG-90


MG90S Metal Gear, MG995 High Torque Metal Gear, VTS-08A Analog Servo.

SPECIFICATION:

• Weight: 9gm
• Operating voltage: 4.8-6V
• NUMBERS OF MOTORS USED = 2

Fig. 2.10

16
foÌq r FINDING COMPONENTS

3. MOTOR DRIVER
A motor driver is a little current amplifier; the function of motor drivers is to take a low-current
control signal and then turn it into a higher-current signal that can drive a motor. A motor driver
is just a set of high power switches that can handle the high-power draw of a motor but can be
controlled with almost no effort from the microcontroller.

NEED FOR MOTOR DRIVER CIRCUITS/ICS

• Arduino is not designed to produce high current which is needed to drive the motor.
• Motor will pull the current it wants and this current it wants and this current will generate
heat and damage the Arduino.
• Motor acts like a slingshot and at the time of run it create an electromagnetic field which will
be released into the Arduino and damage it.

Not only in the case of controllers, while connecting motors with 555 timer ICs or 74 series ICs;
they also cannot provide the large current required by the motor. If direct connection is given,
there might be a chance of damage to the IC.

There are several types of motor driver are like motor driver IC (integrated circuit), bipolar
stepper motor driver, H bridge motor driver, servo motor driver, DC motor driver, brushless
motor driver or for any circuit that may require a motor driver.

APPLICATIONS FOR MOTOR DRIVERS:

Motor drivers can be found in a wide array of applications including:

• Relay and solenoid switching


• Stepping motor
• LED and incandescent displays
• Automotive applications
• Audio-visual equipment
• PC Peripherals
• Car audios
• Car navigation systems

17
foÌq r FINDING COMPONENTS

MAJOR COMPONENTS IN MOTOR DRIVES

• For DC Motors:
The major motor drive components for DC motors are: a controller, a motor driver IC or a
motor driver circuit, the desired DC motor being used, power supply unit and the necessary
connections to the motor.

1. Controller: The controller can be a microprocessor or a microcontroller.

2. Motor Driver IC or Motor Driver Circuits: They are basically current amplifiers which
accept the low current signal from the controller and convert it into a high current signal
which helps to drive the motor.

3. Motor: Motor is defined as an electric or mechanic device that can create a motion. While
interfacing with the controller; some of the motors like DC motor, stepper motor and
brushless dc motor may require a driver IC or driver circuit. DC motor is a type of motor
that can convert DC into a mechanical power. In a brushless DC motor, it consists of a DC
power source, an inverter producing an AC signal to drive the motor. While stepper motor
is a brushless DC electric motor that converts electrical pulses into discrete mechanical
motions.
4. Power Supply Unit: Provides the required power to the motor drive.

• For Servo Motor:

Servo motor is a type of actuator device that consists of a motor and a sensor to control
velocity, acceleration etc. The major motor drive components for a servo motor are a
controller, power supply unit, servo motor and the necessary connections with the motor.

Fig. 2.11

18
foÌq r FINDING COMPONENTS

DC MOTOR DRIVER CIRCUITS

Motor Driver circuits are current amplifiers. They act as a bridge between the controller and the
motor in a motor drive. Motor drivers are made from discrete components which are integrated
inside an IC. The input to the motor driver IC or motor driver circuit is a low current signal. The
function of the circuit is to convert the low current signal to a high current signal. This high current
signal is then given to the motor. The motor can be a brushless DC motor, brushed DC motor,
stepper motor, other DC motors etc.

FEATURES

• High level functionality.


• Better performance.
• Provides high voltage.
• Provides high current drive.
• Includes protection schemes to prevent the failure of motors due to any faults.

DC MOTOR DRIVER USING IC-L293D

L293D is a dual H bridge motor driver IC. The name H Bridge is used because of the diagrammatic
representation of the circuit.

Usually the H bridge circuit contains 4 switches S1, S2, S3 and S4. These switches can be relays,
or P channel and N channel BJTs, MOSFETs, or they can be N channel MOSFETs only.

This 16-pin motor driver IC can drive the motors in anti-clockwise and clockwise direction. The
connection of the DC motors to L293D IC is given below.

Fig. 2.12

19
foÌq r FINDING COMPONENTS

The L293D is a 16 pin IC, with eight pins, on each side, dedicated to the controlling of a motor.
There are 2 INPUT pins, 2 OUTPUT pins and 1 ENABLE pin for each motor.

PIN NO. - PIN CHARACTERISTICS

• 1 - Enable 1-2, when this is HIGH the left part of the IC will work and when it is low the left
part won’t work.
• 2 - INPUT 1, when this pin is HIGH the current will flow though output 1
• 3 - OUTPUT 1, this pin should be connected to one of the terminals of motor
• 4,5 - GND, ground pins
• 6 - OUTPUT 2, this pin should be connected to one of the terminals of motor
• 7 - INPUT 2, when this pin is HIGH the current will flow though output 2
• 8 - VCC2, this is the voltage which will be supplied to the motor.
• 16 - VCC1, this is the power source to the IC. So, this pin should be supplied with 5 V
• 15 - INPUT 4, when this pin is HIGH the current will flow though output 4
• 14 - OUTPUT 4, this pin should be connected to one of the terminals of motor
• 13,12 - GND, ground pins
• 11 - OUTPUT 3, this pin should be connected to one of the terminals of motor
• 10 - INPUT 3, when this pin is HIGH the current will flow though output 3
• 9 - Enable 3-4, when this is HIGH the right part of the IC will work and when it is low the right
part won’t work.

The motor driver IC deals with heavy currents. Due to so much current flow the IC gets heated.
So, we need a heat sink to reduce the heating. Therefore, there are 4 ground pins. When we
solder the pins on PCB, we get a huge metallic area between the grounds where the heat can be
released. The DC motor is an inductive load. So, it develops a back EMF when supplied by a
voltage. There can be fluctuations of voltage while using the motor say when suddenly we take
a reverse while the motor was moving in some direction. At this point the fluctuation in voltage
is quite high and this can damage the IC. Thus, we use four capacitors that help to dampen the
extreme variation in current.

20
foÌq r FINDING COMPONENTS

Fig. 2.13

OPERATION OF L293D CONTROLLING TWO DC MOTORS

• Enable pins should be connected to +5V for the motor driver to start its operation. If these
pins are connected to GND then the motors will stop its operation. Enable 1, 2 drives the H
bridge circuit on the left side while the Enable 3, 4 drives the H Bridge on the right side.
• Consider the motor placed at the left (to pin 3 and 6). The operation is described in the table
below. Its enable pin is Pin1. Input pins are pin2 and pin7.

Pin1 Pin2 Pin7 Action of Motor


+5 volt 0 volt 0 volt Stop
+5 volt 0 volt +5 volt Clockwise
+5 volt +5 volt 0 volt Anti-clockwise
+5 volt +5 volt +5 volt Stop
0 volt - - -
Table 2.2

• The same operation takes place while controlling the motor placed at the right side (pin11
and 14). Here the enable pin will be pin9; input pins are pin 10 and 15.

21
foÌq r FINDING COMPONENTS

4. BLUETOOTH MODULE HC-05


Bluetooth is a wireless technology standard for exchanging data over short distances from fixed
and mobile devices and building personal area networks (PANs). Bluetooth is a standard wire-
replacement communications protocol primarily designed for low-power consumption, with a
short range based on low-cost transceiver microchips in each device. Bluetooth is a replacement
for cabling in a variety of personally carried applications in any setting, and also works for fixed
location applications such as smart energy functionality in the home (thermostats, etc.).

HC‐05 module is an easy to use Bluetooth SPP (Serial Port Protocol) module designed for
transparent wireless serial connection setup. The HC-05 Bluetooth Module can be used in a
Master or Slave configuration, making it a great solution for wireless communication. This serial
port bluetooth module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps
Modulation with complete 2.4GHz radio transceiver and baseband. It uses CSR Bluecore 04‐
External single chip Rluetooth system with CMOS technology and with AFH (Adaptive Frequency
Hopping Feature).

The Bluetooth module HC-05 is a MASTER/SLAVE module. By default, the factory setting is SLAVE.
The Role of the module (Master or Slave) can be configured only by AT COMMANDS. The slave
modules cannot initiate a connection to another Bluetooth device, but can accept connections.
Master module can initiate a connection to other devices. The user can use it simply for a serial
port replacement to establish connection between MCU and GPS, PC to your embedded project,
etc.

HARDWARE FEATURES

• Typical ‐80dBm sensitivity.


• Up to +4dBm RF transmit power.
• 3.3 to 5 V I/O.
• PIO (Programmable Input/Output) control.
• UART interface with programmable baud rate.
• With integrated antenna.
• With edge connector.

22
foÌq r FINDING COMPONENTS

Fig. 2.14

SOFTWARE FEATURES

• Slave default Baud rate: 9600, Data bits:8, Stop bit:1, Parity: No parity.
• Auto‐connect to the last device on power as default.
• Permit pairing device to connect as default.
• Auto‐pairing PINCODE:”1234” as default.

PIN DESCRIPTION

The HC-05 Bluetooth Module has 6pins. They are as follows:

• ENABLE: When enable is pulled LOW, the module is disabled which means the module will
not turn on and it fails to communicate. When enable is left open or connected to 3.3V, the
module is enabled i.e, the module remains on and communication also takes place.
• Vcc: Supply Voltage 3.3V to 5V
• GND: Ground pin

24
foÌq r FINDING COMPONENTS

• TXD & RXD: These two pins act as an UART interface for communication
• STATE: It acts as a status indicator. When the module is not connected to / paired with any
other bluetooth device signal goes Low. At this low state, the led flashes continuously which
denotes that the module is not paired with another device. When this module is connected
to/paired with any other bluetooth device the signal goes High. At this high state, the led
blinks with a constant delay say for example 2s delay which indicates that the module is
paired.
• BUTTON SWITCH: This is used to switch the module into AT command mode. To enable AT
command mode, press the button switch for a second. With the help of AT commands, the
user can change the parameters of this module but only when the module is not paired with
any other BT device. If the module is connected to any other bluetooth device, it starts to
communicate with that device and fails to work in AT command mode.

HOW TO CONNECT HC05 BLUETOOTH MODULE WITH ARDUINO?

HARDWARE AND SOFTWARE REQUIRED

• HC-05 Bluetooth Module


• Arduino Uno
• Arduino IDE(1.0.6V)

HARDWARE CONNECTIONS

As we know that Vcc and Gnd of the module goes to Vcc and Gnd of Arduino. The TXD pin goes
to RXD pin of Arduino and RXD pin goes to TXD pin of Arduino i.e. (digital pin 0 and 1). The user
can use the on-board LED. But here, LED is connected to digital pin 12 externally for betterment
of the process.

Fig. 2.15

24
foÌq r FINDING COMPONENTS

PROGRAM FOR HC-05 BLUETOOTH MODULE

The program given below is the HC-05 bluetooth module program. This process is quite different
from others since we are going to use android mobile to control and communicate with Arduino.
Here the bluetooth module acts as an interface between our mobile and Arduino board. Before
getting into the execution process, follow the given procedure:

• First of all, the user should install an application called Arduino Bluetooth Control from the
playstore which is a free application.
• After installation, pair the bluetooth module to your mobile as like connecting one device to
other using bluetooth. The default pairing code is 1234.
• Upload the given program to the Arduino Uno board. After uploading the code, unplug the
USB from the Arduino.
• Now use external power adapter to power the Uno board.
• The Bluetooth SPP PRO has three types of communication mode. Here Byte stream mode is
used to communicate. So, select that mode and give the input as 1, as soon as the input has
given the led will turn on and for 0 led will turn off.

25
foÌq r FINDING COMPONENTS

5. ARDUINO
Arduino is an open source prototyping platform based on easy-to-use hardware and software.
Arduino boards are able to read inputs –light on a sensor, a finger on a button, or a twitter
message – and turn it into an output –activating a motor, turning on an LED, publishing something
online. You can tell your board what to do by sending a set of instructions to the microcontrollers
on the board. To do so you use the Arduino programming language (based on wiring), and the
Arduino software IDE (Integrated Development Environment), based on processing.

It is an open source microcontroller which can be easily programmed, erased and reprogrammed
at any instant of time. Introduced in 2005 the Arduino platform was designed to provide an
inexpensive and easy way for hobbyists, students and professionals to create devices that
interact with their environment using sensors and actuators. Based on simple microcontroller
boards, it is an open source computing platform that is used for constructing and programming
electronic devices. It is also capable of acting as a mini computer just like other microcontrollers
by taking inputs and controlling the outputs for a variety of electronics devices.

Arduino was born at the Ivrea Interaction Design Institute as an easy tool for fast prototyping,
aimed at students without a background in electronics and programming. As soon as it reached
a wider community, the Arduino board started changing to adapt to new needs and challenges,
differentiating its offer from simple 8-bit boards to products for IoT applications, variable, 3D
printing, and embedded environments. All Arduino boards are completely open source,
empowering users to build them independently and eventually adapt them to their particular
needs.

Built up with the 8-bit Atmel AVR microcontroller's that are manufactured by Atmel or a 32-bit
Atmel ARM, these microcontrollers can be programmed easily using the C or C++ language in the
Arduino IDE. Unlike the other microcontroller boards in India, the Arduino boards entered the
electronic market only a couple of years ago and were restricted to small scale projects only.
People associated with electronics are now gradually coming up and accepting the role of
Arduino for their own projects. This development board can also be used to burn (upload) a new
code to the board by simply using a USB cable to upload. The Arduino IDE provides a simplified
integrated platform which can run on regular personal computers and allows users to write
programs for Arduino using C or C++.

Thanks to its simple and accessible user experience, Arduino has been used in thousands of
different projects and applications. The Arduino software is easy-to-use for beginners, yet flexible
enough for advanced users. It runs on Mac, Windows, Linux. Teachers and students use it to build
low cost scientific instruments, to prove chemistry and physics principles, or to get started with

26
foÌq r FINDING COMPONENTS

programming and robotics. Designers and architects build interactive prototypes, musicians and
artists use it for installations and to experiment with new musical instruments. Makers, of course,
use it to build many of the projects exhibited at the Maker Faire, for example. Arduino is a key
tool to learn new things. Anyone –children, hobbyists, artists, programmers –can start tinkering
just following the step by step instructions of a kit or sharing ideas online with other members of
the Arduino community.

NEED FOR ARDUINO

1. Active User Community: A group of people using a similar product can hold posted
message conversations and share their experiences or solve the problems of the other
users in the communities with their own experiences.
“If you start charging for everything, everything dies very quickly.” says Banzi, Arduino
Cofounder.
2. Growth of Arduino: Arduino was developed with intent to provide an economical and
trouble-free way for hobbyists, students and professionals to build devices that interact
with their situation using sensors and actuators. This makes it perfect for newcomers to
get started quickly.
3. Inexpensive Hardware: Since Arduino is an open source platform the software is not
purchased and only the cost of buying the board or its parts is incurred, thus making it
very cheap. The hardware designs are also available online for free from its official
website.
4. Arduino Board as a Programmer: To make Arduino board function easy and also making
it available everywhere these boards come with a USB cable for power requirements as
well as functioning as a programmer.
5. Multi-platform Environment: The Arduino IDE is capable of running on a number of
platforms including Microsoft, Linux and Mac OS X making the user community even
larger.

27
foÌq r SOFTWARE

SOFTWARE
1. ARDUINO IDE
The program code written for Arduino is known as a sketch. The software used for developing
such sketches for an Arduino is commonly known as the Arduino IDE. This IDE contains the
following parts in it:

• Text editor: This is where the simplified code can be written using a simplified version of C++
programming language.
• Message area: It displays error and also gives a feedback on saving and exporting the code.
• Text: The console displays text output by the Arduino environment including complete error
messages and other information
• Console Toolbar: This toolbar contains various buttons like Verify, Upload, New, Open, Save
and Serial Monitor. On the bottom right hand corner of the window there displays the
Development Board and the Serial Port in use.

FEATURES OF ARDUINO IDE

• The project file or the sketches for a project are saved with the file extension.ino.
• Features such as cut / copy / paste are supported in this IDE.
• There also is a facility for finding a particular word and replacing it with another by pressing
the Ctrl + F buttons on the keyboard
• The most basic part or the skeleton of all Arduino code will have two functions.

PROGRAMMING BASICS

Now we’ll discuss about the programming techniques of Arduino sketch in the Arduino IDE. There
are two main parts every sketch will always have, they are:

1. Void setup (): This is the first routine that begins when the Arduino starts functioning. This
function is executed only once throughout the entire program functioning.
The setup function contains the initialization of every pin we intend use in our project for
input or output. Here is an example of how it should be written:

1. void setup() {
2. pinmode(pin, INPUT);
3. pinmode(pin, OUTPUT);
4. }

Here the pin is the no. of the pin that is to be defined. INPUT / OUPUT correspond to the
mode in which the pin is to be used.

28
foÌq r SOFTWARE

A portion of the code explaining this further:

1. void setup() {
2. // sets the pins as outputs:
3. pinMode(motor1Pin1, OUTPUT);
4. pinMode(motor1Pin2, OUTPUT);
5. pinMode(motor2Pin1, OUTPUT);
6. pinMode(motor2Pin2, OUTPUT);
7. myservo1.attach(6);
8. myservo2.attach(7);
9. // initialize serial communication at 9600 bits per second:
10. Serial.begin(9600);
11. digitalWrite(motor1Pin1, LOW);
12. digitalWrite(motor1Pin2, LOW);
13. digitalWrite(motor2Pin1, LOW);
14. digitalWrite(motor2Pin2, LOW);
15. myservo2.write(pos);
16. myservo1.write(pos1);
17. }

It also contains the initialization of the Serial Monitor. A serial monitor is used to know the
data that are being sent serially to any peripheral device.

2. Void loop (): This function is the next important function in the Sketch. It consists of that part
of the code that needs to be continuously executed unlike the part of the code written in the
setup function. An example of a void loop is as follows:

1. void loop() {
2. digitalWrite(pin, HIGH);
3. }

Here digitalWrite is a function that writes a high or a low value to a digital pin. If the pin has
been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding
value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.
Similarly, if there is a need for delay in the sketch then there is another function that creates
a delay in the execution of the code

1. delay(1000); //delay for a second

This creates a delay in the execution of the program for the time period specified (in
milliseconds).

A portion of the code as an example:

1. void loop() {
2. //if some date is sent, reads it and saves in state
3. if(Serial.available() > 0){
4. state = Serial.read();
5. flag=0;
6. }

29
foÌq r SOFTWARE

7. // if the state is '1' the DC motor will go forward


8. if (state == '1') {
9. digitalWrite(motor1Pin1, HIGH);
10. digitalWrite(motor1Pin2, HIGH);
11. digitalWrite(motor2Pin1, LOW);
12. digitalWrite(motor2Pin2, LOW);
13. Serial.println(state);
14. if(flag == 0){
15. Serial.println("Go Forward!");
16. flag=1;
17. }
18. delay(100);
19. state=10;
20. }
21. }

30
foÌq r SOFTWARE

2. SIMULATION
Before proceeding with the project, we tried a simulation for the same. Initially we were trying
to interface all the DC motors with only one motor driver IC (L293D). The circuit of which looked
something like this (except for the Arduino UNO as we’re using Arduino Mega):

Fig. 3.1 Code in Appendix A.

Run the simulation


on your phone.

31
foÌq r SOFTWARE

Everything seemed to be working fine, but when we executed this circuit in lab, things started
getting ugly. The servos started malfunctioning. They were not working as per our desire and
creating nuisance with the circuit. We tried tweaking the code but all in vain. After a few weeks
of this, we started seeking help from the world.

Finally, one of us got positive reply from a Facebook group, and we done the necessary
changes. In whole, we discovered that we’ll be needing two motor driver ICs to power four
motors. Also, we’ve not connected pin 8 of motor driver IC to anything, which we realized is
required to supply power to the motor.

After which the final circuit was like this:

Fig. 3.2 Code in Appendix B.

Run the simulation


on your phone.

32
foÌq r SOFTWARE

3. Android app development using MIT app inventor


App Inventor for Android is an open-source web application originally provided by Google, and
now maintained by the Massachusetts Institute of Technology (MIT).

It allows newcomers to computer programming to create software applications for the Android
operating system (OS). It uses a graphical interface, very similar to Scratch and the StarLogo TNG
user interface, which allows users to drag-and-drop visual objects to create an application that
can run on Android devices.

Here we will discuss how to make an android app using step wise approach and then we will
provide the block diagram the designer diagram to make the required app used in our project.

INTRODUCTION:

33
foÌq r SOFTWARE

GETTING STARTED WITH MIT APP INVENTOR 2:

Step 1: Create a Gmail account (if you haven’t one)

Step 2: Use an existing Gmail account or school-based Google account to log in to


ai2.appinventor.mit.edu

34
foÌq r SOFTWARE

Step 3: Choose a google account if you have more than one

Step 4: Login to MIT app inventor

35
foÌq r SOFTWARE

Step 5: Start a new project

Step 6: Give a name to the project

36
foÌq r SOFTWARE

Step 7: Open the Workspace (as soon as you name the project and click ok, it will open a window
same as given below)

37
foÌq r SOFTWARE

DESIGNING AN APP:

Step 1: Choose “a level” from the palette options given at the extreme left and name it.

Step 2: Choose a table arrangement and also choose number of rows and columns.

38
foÌq r SOFTWARE

After we choose the size we need to add text box and write the corresponding information i.e.
left right, forward etc. To do so, at first go to palette and choose button option, and drag it into
the table arrangement area. Similarly, by following the above method we can draw other two
tables one for microphone other for grab and drop option (point to be noted here is that, in the
last two case the number of rows and column are different i.e. 1×1 and 1×2 respectively).

Step 3: Choose the clock, Bluetooth client and speech recognizer option from list sensor option.
But since these items are non-visible so they are shown at the bottom of the designer screen. For
Bluetooth use the option connectivity and the blutoothclient1 from there.

38
foÌq r SOFTWARE

Step 4: We can name the app, and we have added a background image s for that we can use
the options given in the main screen, finally our designer page will look like the below image.

39
foÌq r SOFTWARE

WRITING THE ALGORITHM USING THE BLOCKS OPTION:

When we will click the blocks option given on the extreme right a window will appear like the
one given below.

Step 1: Choose list picker from extreme left side and choose the before picking option and then
set list picker element option as shown below.

40
foÌq r SOFTWARE

Step 2: Select Bluetoothclient1 and choose call connect address, after that go to listpicker 1 and
select “selection”.

41
foÌq r SOFTWARE

Step 3: Select button 1 and choose “when button 1 click”, after that go to Bluetoothclient1 and
select call option from the menu. After this go to text option and select text box.

41
foÌq r SOFTWARE

Similar approached has been used for designing the blocks of other buttons.

42
foÌq r SOFTWARE

Step 4: Select clock and then choose “timer”, after that go to control given in the left-hand side
and select "if then “option. After that go to Bluetoothclient1 and select the desired button
after all this select the color to indicate either the device is connected or not with Bluetooth.

43
foÌq r SOFTWARE

The final block for step 5 will look like one shown below

Step 6: Go to SpeechRecognizer 1 and select “after getting text” (we have already mentioned
the way for selection button 6 to get the speech from the user i.e. using button 6 we get the
speech using the mic of our phone, to design the block we have followed the approach of step
2).
The final block for this segment is shown.

44
foÌq r SOFTWARE

Step 7: The final block diagram is shown below.

45
foÌq r SOFTWARE

The designer page is shown below

Try the app


This will be screen of our android app.

45
foÌq r CONCLUSION AND POSSIBLE EXTENSION

CONCLUSION AND POSSIBLE EXTENSION


Through a very learning process, we have completed the project within given time frame to its
best.

There are many possible extensions that can be added in this project i.e. robot.

We have listed some of the prominent changes that can be done

• Adding using a Wi-Fi module instead of a Bluetooth module so as to increase the range
i.e. distance of the robot up to which it can take a command.
• Instead of using 4 wheels 3 wheels can be used.
• More number of predefined tasks can be added beside what we have done, like rolling,
jumping etc.
• For a perfect and elegant movements of front wheel, which is used for left right
movements a differential rotator can used.

46
foÌq r APPENDIX A

Appendix A
Code used while we were trying to drive all the four DC motors with one motor driver IC
(Simulation on page 31)

1. #include<Servo.h>
2.
3. Servo myservo1; // pin 10 ARM_1 UP/DOWN
4. Servo myservo2; // pin 5 CLAW
5. int motor1Pin1 = 2; // pin 2 on L293D IC (Forward Right) (3)
6. int motor1Pin2 = 3; // pin 7 on L293D IC (Forward Left) (6)
7. int motor2Pin1 = 4; // pin 10 on L293D IC (Backward Left)(11)
8. int motor2Pin2 = 5; // pin 15 on L293D IC (Backward Right)(14)
9. int state;
10. int flag=0; //makes sure that the serial only prints once the state
11. int pos = 0;
12. int pos1 = 35;
13.
14. void setup() {
15. // sets the pins as outputs:
16. pinMode(motor1Pin1, OUTPUT);
17. pinMode(motor1Pin2, OUTPUT);
18. pinMode(motor2Pin1, OUTPUT);
19. pinMode(motor2Pin2, OUTPUT);
20. myservo1.attach(6);
21. myservo2.attach(7);
22. // initialize serial communication at 9600 bits per second:
23. Serial.begin(9600);
24. digitalWrite(motor1Pin1, LOW);
25. digitalWrite(motor1Pin2, LOW);
26. digitalWrite(motor2Pin1, LOW);
27. digitalWrite(motor2Pin2, LOW);
28. myservo2.write(pos);
29. myservo1.write(pos1);
30. }
31.
32. void loop() {
33. //if some date is sent, reads it and saves in state
34. if(Serial.available() > 0){
35. state = Serial.read();
36. flag=0;
37. }
38. // if the state is '1' the DC motor will go forward
39. if (state == '1') {
40. digitalWrite(motor1Pin1, HIGH);
41. digitalWrite(motor1Pin2, HIGH);
42. digitalWrite(motor2Pin1, LOW);
43. digitalWrite(motor2Pin2, LOW);
44. Serial.println(state);
45. if(flag == 0){
46. Serial.println("Go Forward!");
47. flag=1;
48. }
49. delay(100);
50. state=10;
51. }
52. // if the state is '2' the motor will Reverse

47
foÌq r APPENDIX A

53. else if (state == '2') {


54. digitalWrite(motor1Pin1, LOW);
55. digitalWrite(motor1Pin2, LOW);
56. digitalWrite(motor2Pin1, HIGH);
57. digitalWrite(motor2Pin2, HIGH);
58. Serial.println(state);
59. if(flag == 0){
60. Serial.println("Reverse!");
61. flag=1;
62. }
63. delay(100);
64. state=3;
65. }
66. // if the state is '3' the motor will turn right
67. else if (state == '3') {
68. digitalWrite(motor1Pin1, LOW);
69. digitalWrite(motor1Pin2, LOW);
70. digitalWrite(motor2Pin1, LOW);
71. digitalWrite(motor2Pin2, HIGH);
72. Serial.println(state);
73. if(flag == 0){
74. Serial.println("Turn RIGHT");
75. flag=1;
76. }
77. delay(100);
78. state=3;
79. }
80. // if the state is '4' the motor will turn left
81. else if (state == '4') {
82. digitalWrite(motor1Pin1, LOW);
83. digitalWrite(motor1Pin2, LOW);
84. digitalWrite(motor2Pin1, HIGH);
85. digitalWrite(motor2Pin2, LOW);
86. Serial.println(state);
87. if(flag == 0){
88. Serial.println("Turn LEFT");
89. flag=1;
90. }
91. delay(100);
92. state=3;
93. }
94. // if state is '5' the motor will Stop
95. else if (state == '5') {
96. digitalWrite(motor1Pin1, LOW);
97. digitalWrite(motor1Pin2, LOW);
98. digitalWrite(motor2Pin1, LOW);
99. digitalWrite(motor2Pin2, LOW);
100. Serial.println(state);
101. if(flag == 0){
102. Serial.println("STOP!");
103. flag=1;
104. }
105. delay(100);
106. state=3;
107. }
108. // if state is '6' Arm will move up
109. else if (state == '6') {
110. myservo1.write(pos1 -= 10);
111. Serial.println(state);
112. Serial.println(pos1);
113. if(flag == 0){

48
foÌq r APPENDIX A

114. Serial.println("Arm UP");


115. flag=1;
116. }
117. delay(100);
118. state=3;
119. }
120. // if state is '7' Arm will move down
121. else if (state == '7') {
122. myservo1.write(pos1 += 10);
123. Serial.println(state);
124. Serial.println(pos1);
125. if(flag == 0){
126. Serial.println("Arm DOWN");
127. flag=1;
128. }
129. delay(100);
130. state=3;
131. }
132. // if state is '8' Claw will grab
133. else if (state == '8') {
134. myservo2.write(pos -= 15);
135. Serial.println(state);
136. Serial.println(pos);
137. if(flag == 0){
138. Serial.println("Claw GRAB");
139. flag=1;
140. }
141. delay(100);
142. state=3;
143. }
144. // if state is '9' Claw will drop
145. else if (state == '9') {
146. myservo2.write(pos += 15);
147. Serial.println(state);
148. Serial.println(pos1);
149. if(flag == 0){
150. Serial.println("Claw Drop");
151. flag=1;
152. }
153. delay(100);
154. state=3;
155. }
156. }

49
foÌq r APPENDIX B

Appendix B
Try run after we made corrections. (Simulation on page 32)

1. #include<Servo.h>
2.
3. Servo myservo1; // pin 10 ARM_1 UP/DOWN
4. Servo myservo2; // pin 5 CLAW
5. int motor1Pin1 = 2; // pin 2 on L293D IC (Forward Left) (3)
6. int motor1Pin2 = 3; // pin 7 on L293D IC (6)
7. int motor2Pin1 = 4; // pin 10 on L293D IC (11)
8. int motor2Pin2 = 5; // pin 15 on L293D IC (Forward Right) (14)
9. int motor3Pin1 = 6; // pin 2 on L293D IC (Backward Left) (3)
10. int motor3Pin2 = 7; // pin 7 on L293D IC (6)
11. int motor4Pin1 = 8; // pin 10 on L293D IC (11)
12. int motor4Pin2 = 9; // pin 15 on L293D IC (Backward Right) (14)
13. int state;
14. int flag=0; //makes sure that the serial only prints once the state
15. int pos = 0;
16. int pos1 = 35;
17.
18. void setup() {
19. // sets the pins as outputs:
20. pinMode(motor1Pin1, OUTPUT);
21. pinMode(motor1Pin2, OUTPUT);
22. pinMode(motor2Pin1, OUTPUT);
23. pinMode(motor2Pin2, OUTPUT);
24. pinMode(motor3Pin1, OUTPUT);
25. pinMode(motor3Pin2, OUTPUT);
26. pinMode(motor4Pin1, OUTPUT);
27. pinMode(motor4Pin2, OUTPUT);
28. myservo1.attach(10);
29. myservo2.attach(11);
30. // initialize serial communication at 9600 bits per second:
31. Serial.begin(9600);
32. digitalWrite(motor1Pin1, LOW);
33. digitalWrite(motor1Pin2, LOW);
34. digitalWrite(motor2Pin1, LOW);
35. digitalWrite(motor2Pin2, LOW);
36. digitalWrite(motor3Pin1, LOW);
37. digitalWrite(motor3Pin2, LOW);
38. digitalWrite(motor4Pin1, LOW);
39. digitalWrite(motor4Pin2, LOW);
40. myservo2.write(pos);
41. myservo1.write(pos1);
42. }
43.
44. void loop() {
45. //if some date is sent, reads it and saves in state
46. if(Serial.available() > 0){
47. state = Serial.read();
48. flag=0;
49. }
50. // if the state is '1' the DC motor will go forward
51. if (state == '1') {
52. digitalWrite(motor1Pin1, HIGH);
53. digitalWrite(motor1Pin2, LOW);

50
foÌq r APPENDIX B

54. digitalWrite(motor2Pin1, HIGH);

50
foÌq r APPENDIX B

55. digitalWrite(motor2Pin2, LOW);


56. digitalWrite(motor3Pin1, HIGH);
57. digitalWrite(motor3Pin2, LOW);
58. digitalWrite(motor4Pin1, HIGH);
59. digitalWrite(motor4Pin2, LOW);
60. Serial.println(state);
61. if(flag == 0){
62. Serial.println("Go Forward!");
63. flag=1;
64. }
65. delay(100);
66. state=3;
67. }
68. // if the state is '2' the motor will Reverse
69. else if (state == '2') {
70. digitalWrite(motor1Pin1, LOW);
71. digitalWrite(motor1Pin2, HIGH);
72. digitalWrite(motor2Pin1, LOW);
73. digitalWrite(motor2Pin2, HIGH);
74. digitalWrite(motor3Pin1, LOW);
75. digitalWrite(motor3Pin2, HIGH);
76. digitalWrite(motor4Pin1, LOW);
77. digitalWrite(motor4Pin2, HIGH);
78. Serial.println(state);
79. if(flag == 0){
80. Serial.println("Reverse!");
81. flag=1;
82. }
83. delay(100);
84. state=3;
85. }
86. // if the state is '3' the motor will turn right
87. else if (state == '3') {
88. digitalWrite(motor1Pin1, LOW);
89. digitalWrite(motor1Pin2, LOW);
90. digitalWrite(motor2Pin1, HIGH);
91. digitalWrite(motor2Pin2, LOW);
92. digitalWrite(motor3Pin1, HIGH);
93. digitalWrite(motor3Pin2, LOW);
94. digitalWrite(motor4Pin1, HIGH);
95. digitalWrite(motor4Pin2, LOW);
96. Serial.println(state);
97. if(flag == 0){
98. Serial.println("Turn RIGHT");
99. flag=1;
100. }
101. delay(100);
102. state=3;
103. }
104. // if the state is '4' the motor will turn left
105. else if (state == '4') {
106. digitalWrite(motor1Pin1, HIGH);
107. digitalWrite(motor1Pin2, LOW);
108. digitalWrite(motor2Pin1, LOW);
109. digitalWrite(motor2Pin2, LOW);
110. digitalWrite(motor3Pin1, HIGH);
111. digitalWrite(motor3Pin2, LOW);
112. digitalWrite(motor4Pin1, HIGH);
113. digitalWrite(motor4Pin2, LOW);
114. Serial.println(state);
115. if(flag == 0){

51
foÌq r APPENDIX B

116. Serial.println("Turn LEFT");


117. flag=1;
118. }
119. delay(100);
120. state=3;
121. }
122. // if state is '5' the motor will Stop
123. else if (state == '5') {
124. digitalWrite(motor1Pin1, LOW);
125. digitalWrite(motor1Pin2, LOW);
126. digitalWrite(motor2Pin1, LOW);
127. digitalWrite(motor2Pin2, LOW);
128. digitalWrite(motor3Pin1, LOW);
129. digitalWrite(motor3Pin2, LOW);
130. digitalWrite(motor4Pin1, LOW);
131. digitalWrite(motor4Pin2, LOW);
132. Serial.println(state);
133. if(flag == 0){
134. Serial.println("STOP!");
135. flag=1;
136. }
137. delay(100);
138. state=3;
139. }
140. // if state is '6' Arm will move up
141. else if (state == '6') {
142. myservo1.write(pos1 -= 10);
143. Serial.println(state);
144. Serial.println(pos1);
145. if(flag == 0){
146. Serial.println("Arm UP");
147. flag=1;
148. }
149. delay(100);
150. state=3;
151. }
152. // if state is '7' Arm will move down
153. else if (state == '7') {
154. myservo1.write(pos1 += 10);
155. Serial.println(state);
156. Serial.println(pos1);
157. if(flag == 0){
158. Serial.println("Arm DOWN");
159. flag=1;
160. }
161. delay(100);
162. state=3;
163. }
164. // if state is '8' Claw will grab
165. else if (state == '8') {
166. myservo2.write(pos -= 15);
167. Serial.println(state);
168. Serial.println(pos);
169. if(flag == 0){
170. Serial.println("Claw GRAB");
171. flag=1;
172. }
173. delay(100);
174. state=3;
175. }
176. // if state is '9' Claw will drop

52
foÌq r APPENDIX B

177. else if (state == '9') {


178. myservo2.write(pos += 15);
179. Serial.println(state);
180. Serial.println(pos1);
181. if(flag == 0){
182. Serial.println("Claw Drop");
183. flag=1;
184. }
185. delay(100);
186. state=3;
187. }
188. }

53
foÌq r APPENDIX C

Appendix C
Circuit and code used in experiment.

The circuit we’ve used is quite similar to this one except for the connections of Bluetooth
module which is explained earlier.

1. #include<Servo.h>
2.
3. Servo myservo1; // pin 10 ARM_1 UP/DOWN
4. Servo myservo2; // pin 11 CLAW
5. int motor1Pin1 = 2; // pin 2 on L293D IC1 (Forward Left Red) (3)
6. int motor1Pin2 = 3; // pin 7 on L293D IC1 (Forward Left Black) (6)
7. int motor2Pin1 = 4; // pin 10 on L293D IC1 (Forward Right Red) (11)
8. int motor2Pin2 = 5; // pin 15 on L293D IC1 (Forward Right Black) (14))
9. int led1 = 6; //Forward Left
10. int led2 = 7; //Forward Right
11. int led3 = 8; //Back Left
12. int led4 = 9; //Back Right
13. int state;
14. int flag=0; //makes sure that the serial only prints once the state
15. int stateStop=0;
16. int pos = 25;
17. int pos1 = 0;
18.
19. void setup() {
20. // sets the pins as outputs:
21. pinMode(motor1Pin1, OUTPUT);
22. pinMode(motor1Pin2, OUTPUT);
23. pinMode(motor2Pin1, OUTPUT);
24. pinMode(motor2Pin2, OUTPUT);

54
foÌq r APPENDIX C

25. pinMode(led1, OUTPUT);


26. pinMode(led2, OUTPUT);
27. pinMode(led3, OUTPUT);
28. pinMode(led4, OUTPUT);
29. myservo1.attach(10);
30. myservo2.attach(11);
31. Serial.begin(9600); // initialize serial communication at 9600 bits per second:
32. digitalWrite(motor1Pin1, LOW);
33. digitalWrite(motor1Pin2, LOW);
34. digitalWrite(motor2Pin1, LOW);
35. digitalWrite(motor2Pin2, LOW);
36. myservo1.write(pos1);
37. myservo2.write(pos);
38. }
39.
40. void loop() {
41. //if some date is sent, reads it and saves in state
42. if(Serial.available() > 0){
43. state = Serial.read();
44. flag=0;
45. }
46. // if the state is '1' the DC motor will go forward
47. if (state == '1') {
48. digitalWrite(motor1Pin1, HIGH);
49. digitalWrite(motor1Pin2, LOW);
50. digitalWrite(motor2Pin1, HIGH);
51. digitalWrite(motor2Pin2, LOW);
52. digitalWrite(led1, HIGH);
53. digitalWrite(led2, HIGH);
54. digitalWrite(led3, LOW);

54
foÌq r APPENDIX C

55. digitalWrite(led4, LOW);


56. Serial.println(state);
57. if(flag == 0){
58. Serial.println("Go Forward!");
59. flag=1;
60.
61. }
62. delay(100);
63. state=3;
64. stateStop=1;
65. }
66. // if the state is '2' the motor will Reverse
67. else if (state == '2') {
68. digitalWrite(motor1Pin1, LOW);
69. digitalWrite(motor1Pin2, HIGH);
70. digitalWrite(motor2Pin1, LOW);
71. digitalWrite(motor2Pin2, HIGH);
72. digitalWrite(led1, LOW);
73. digitalWrite(led2, LOW);
74. digitalWrite(led3, HIGH);
75. digitalWrite(led4, HIGH);
76. Serial.println(state);
77. if(flag == 0){
78. Serial.println("Reverse!");
79. flag=1;
80. }
81. delay(100);
82. state=3;
83. stateStop=1;
84. }
85. // if the state is '3' the motor will turn right
86. else if (state == '3') {
87. digitalWrite(motor1Pin1, LOW);
88. digitalWrite(motor1Pin2, LOW);
89. digitalWrite(motor2Pin1, HIGH);
90. digitalWrite(motor2Pin2, LOW);
91. digitalWrite(led1, LOW);
92. digitalWrite(led2, HIGH);
93. digitalWrite(led3, LOW);
94. digitalWrite(led4, HIGH);
95. Serial.println(state);
96. if(flag == 0){
97. Serial.println("Turn RIGHT");
98. flag=1;
99. }
100. delay(100);
101. state=3;
102. stateStop=1;
103. }
104. // if the state is '4' the motor will turn left
105. else if (state == '4') {
106. digitalWrite(motor1Pin1, HIGH);
107. digitalWrite(motor1Pin2, LOW);
108. digitalWrite(motor2Pin1, LOW);
109. digitalWrite(motor2Pin2, LOW);
110. digitalWrite(led1, HIGH);
111. digitalWrite(led2, LOW);
112. digitalWrite(led3, HIGH);
113. digitalWrite(led4, LOW);
114. Serial.println(state);
115. if(flag == 0){

55
foÌq r APPENDIX C

116. Serial.println("Turn LEFT");


117. flag=1;
118. }
119. delay(100);
120. state=3;
121. stateStop=1;
122. }
123. // if state is '5' the motor will Stop
124. else if (state == '5') {
125. digitalWrite(motor1Pin1, LOW);
126. digitalWrite(motor1Pin2, LOW);
127. digitalWrite(motor2Pin1, LOW);
128. digitalWrite(motor2Pin2, LOW);
129. digitalWrite(led1, HIGH);
130. digitalWrite(led2, HIGH);
131. digitalWrite(led3, HIGH);
132. digitalWrite(led4, HIGH);
133. delay(1000);
134. digitalWrite(led1, LOW);
135. digitalWrite(led2, LOW);
136. digitalWrite(led3, LOW);
137. digitalWrite(led4, LOW);
138. Serial.println(state);
139. //if(flag == 0){
140. Serial.println("STOP!");
141. // flag=1;
142. // }
143. delay(1000);
144. // state=3;
145. // stateStop=1;
146. }
147. // if state is '6' Arm will move up
148. else if (state =='6') {
149. myservo1.write(pos1 -= 10);
150. Serial.println(state);
151. Serial.println(pos1);
152. if(flag == 0){
153. Serial.println("Arm UP");
154. flag=1;
155. }
156. delay(100);
157. state=3;
158. stateStop=1;
159. }
160. // if state is '7' Arm will move down
161. else if (state == '7') {
162. myservo1.write(pos1 += 10);
163. Serial.println(state);
164. Serial.println(pos1);
165. if(flag == 0){
166. Serial.println("Arm DOWN");
167. flag=1;
168. }
169. delay(100);
170. state=3;
171. stateStop=1;
172. }
173. // if state is '8' Claw will grab
174. else if (state == '8') {
175. myservo2.write(pos -= 15);
176. Serial.println(state);

56
foÌq r APPENDIX C

177. Serial.println(pos);
178. if(flag == 0){
179. Serial.println("Claw GRAB");
180. flag=1;
181. }
182. delay(100);
183. state=3;
184. stateStop=1;
185. }
186. // if state is '9' Claw will drop
187. else if (state == '9') {
188. myservo2.write(pos += 15);
189. Serial.println(state);
190. Serial.println(pos1);
191. if(flag == 0){
192. Serial.println("Claw Drop");
193. flag=1;
194. }
195. delay(100);
196. state=3;
197. stateStop=1;
198. }
199. stateStop=0;
200. }

56
foÌq r BIBLIOGRAPHY

BIBLIOGRAPHY
1. http://www.instructables.com
2. https://www.arduino.cc/en/Main/Software
3. https://www.tinkercad.com
4. http://ai2.appinventor.mit.edu/
5. Arduino Bluetooth Control (Google Play)
6. https://www.facebook.com/
7. http://www.planetb.ca/syntax-highlight-word
8. https://www.unitag.io/qrcode
9. https://drive.google.com
10. https://www.scribd.com/

57

Das könnte Ihnen auch gefallen