university of nevada las vegaseelabs.faculty.unlv.edu/docs/guides/mechatronics_tutorial.pdf ·...
TRANSCRIPT
University of Nevada Las Vegas
Mechatronics Tutorial
(version 1)
By
Makram Abd El Qader
Charbel azzi
Jonathan Burgos
Nirup Nirvan
30 June 2009
Mechatranocis Tutorial
1. Introduction
2. Motivation
3. Learning Objectives
4. Safety Issues
5. machine shop and Tools
6. Project phase
6.1 Phase one- Fully controlled mini-car with infrared sensing on board.
6.2 Phase two- Phase One plus ultrasonic and temperature sensors on board.
6.3 Phase three- Phase One, Phase Two plus wireless controlled mini-car
7. Mechanical Design & Implementation
7.1 Project Components
7.1.1 Gear Box kit
7.1.2 Dc Motors
7.1.3 Tires
7.1.4 Plat Form Holder
7.2 Implementation
7.2.1 Gear Box DesigN
7.2.2 Setting the tires up
7.2.3 Connecting the Motors
8. Electrical Design & Implementation
8.1 Project Components
8.1.1 Microcontroller
8.1.1.1 General Background
8.1.1.2 Why do we use a Microcontroller?
8.1.1.3 Why using Adruino Microcontroller?
8.1.1.4 Applications
8.1.1.5 Programming examples
8.1.2 Motor Driver
8.1.3 RC Battery
8.1.4 Sensors
8.1.4.1 Infrared Sensor
8.1.4.2 Temperature Sensor
8.1.4.3 Ultrasonic Sensor
8.1.5 PCB-Printed Circuitry Board
8.2 Implementation
8.2.1 Driver Connections
8.2.2 Sensors Connections
8.2.3 Programming the microcontroller using Adruino software( c++ based)
9. Mechatronics Final Design
10. Cost
11. Conclusion
12. Sponsors
13. Acknowledgments
14. References
1. Introduction
Mechatronics is the synergistic combination of mechanical engineering, electronic
engineering, control engineering, systems design engineering, and computer engineering
to create useful products. One of the purposes of this interdisciplinary engineering field is
the study of automata from an engineering perspective and serves the purposes of
controlling advanced hybrid electro mechanical systems. The word itself is a combination
of 'Mechanics' and 'Electronics'. The importance of multi-disciplinary engineering
projects has increased along with the accelerated rate of technological advancement
industry-wide. Because all areas of technology are advancing, effective design of a single
product often requires close integration of a wide range of disciplines. Microprocessors
and sensors have become pervasive within many engineering products, and mechanical
engineers will often interface with electrical engineers or select and implement electronic
components themselves.
The mechatronics design project has specifically been selected as it is multi-disciplinary
and is based on microprocessor. The project encompasses multiple sub-disciplines of
engineering and computer science.
· Mechanical structure
· Dynamics
· Motor performance
· Motor Driver performance
· Sensor performance
· Control Algorithm
· Real-time software implementation
2. Motivation
This project is intended for hands-on education and training for undergraduate
engineering students. The structure of the project allows instructors to use material in a
modular fashion. Additional modular projects can be easily built around this project to
teach students asynchronously at freshman, sophomore, junior, or senior levels. This
project covers fundamental topics from electrical engineering, computer engineering and
mechanical engineering.
3. Learning Objectives
Student will learn:
1. To analyze and design a DC circuits ( power, capacitors, resistors, and
wiring)
2. To understand sensors, their applications and implemetation ( infrared
sensor, temperature sensor, ultrasonic sensor)
3. To use and implement microcontrollers (Adruino development board with
ATMEGA 328) and programming- Control algorithm- Real-time software
4. To use soldering of electrical components on PCB (soldering tools and
hands on experience)
5. To understand power consumption by electrical device (RC batteries and
charging concept)
6. To incorporate DC motors and motor driver- H bridge in the design for
specific application ( DC motors functions and specifications)
7. To use electrical testing equipments such as (voltmeter, oscilloscope,
function generator, and power supply etc…..)
8. To familiarize oneself with gear box kit and its assembly.
9. To understand and use gear ratio, Power train selection (belt, gear, etc.),
Bearings and shafts
10. To familiarize oneself Get familiar to use solid works software for
mechanical design
11. To design strength issues in mechanical design.
4. Safety issues
All the students must attend a safety seminar offered by the Mendenhall lab instructor.
5. Machine shop and Tools
Students are required to do their research and project assembly in the laboratory space
assigned for this project under the supervision of the lab instructor. Students will have
access to the machine shop and electronic shop associated with Mendenhall center.
The machine shop is located in room #TBE B200 and the electronic shop in room #
TBE B. Students must undergo an equipment usage and safety seminar for the
machinery shop and the electronic shop before getting access.
6. Project phase
The project is designed in a a modular fashion with three phases.
6.1 Phase one- Fully controlled mini-car with infrared sensing on board.
Using an infrared sensor would have many different applications on
our mini car. For example we could program it in way that it
Would avoid encountered walls (as we will see in the microcontroller
Section ).
6.2 Phase two- Phase One plus ultrasonic and temperature sensors on board.
In this phase and for more sensor precision we implemented an
ultrasonic sensor that will allow us to have a bigger range. Moreover
we introduced temperature sensor around our car. The temperature
sensor are not only for getting the room temperature, but we also used the
for another application. For example, our mini car would be able to follow
the heat.
6.3 Phase three- Phase One, Phase Two plus wireless controlled mini-car
In the previous phases we were uploading the program into our
microcontroller in order to control our car. Now we will be able to control
our car wirelessly.
7. Mechanical Design
7.1 project components
7.1.1 Gearbox and torque explanation
Parts to the gearbox
Fig.1. Gearbox parts & DC Motors
1- 2 DC motors
2- 2 wheels and 2 tires
3- 4 axles shaft
4- 8 gears
5- 2 nuts with fit screws
6- 4 screws
7- 2 washers
8- 2 plastic sides pieces and 1 middle piece (gear box covers)
Gear box and motors
First thing is to understand how a gearbox works. In order to rotate gears we need
a torque. What’s Torque?
Fig.2. Torque and forces
Torque: measure of a force's tendency to produce rotation When the force is applied at
a farther distance from the center of rotation, it is easier to produce rotation. Torque is
the product of the force and the distance from the point application of the force and the
center of rotation. (Note: the force and the length ‘vector” is perpendicular to each
other). From the figure: Fλ1>F λ2
Why We Need Gearsbox?
Fig.3. Gearbox fully assembled
DC motors have high speed but no torque. For example if we use the DC motors
and directly connect to the wheels. The wheels will not have enough power to move up a
hill or even on flat floor because of the friction force to overcome is greater > than torque
that the DC motor produces.
Fig.4. Tires
Fig.5.inside the gearbox
Use gears so that the low torque and high speed at the motor shaft is transferred to wheel
as high torque/low speed. The high torque at the wheel can counter the ground friction so
that now the wheels move when they are put on the ground.
Fig.6. Greater the voltage applied to the motor, higher its angular speed.
7.1.2 Dc Motors
Motors come in many sizes and types, but their basic function is the same. Motors of all
types serve to convert electrical energy into mechanical energy. They can be found in
VCR's, elevators, CD players, toys, robots, watches, automobiles, subway trains, fans,
space ships, air conditioners, refrigerators, and many other places. D.C. motors as shown
in Fig.7 are motors that run on Direct Current from a battery or D.C. power supply.
Direct Current is the term used to describe electricity at a constant voltage. A.C. motors
run on alternating Current, which oscillates with a fixed cycle between a positive and
negative value. Electrical outlets provide A.C. power. When a battery or D.C. power
supply is connected between a D.C. motor's electrical leads, the motor converts electrical
energy to mechanical work as the output shaft turns.
Fig.7. Dc Motor
Dc Motors functioning is characterized by Lorentz Force Law:
F = I x B
Where:
F = force on wire
I = current
B = magnetic field
Which work on the concept of the Right hand rule:
Index finger along I,
Middle finger along B,
Thumb along F
The physics behind the Dc Motors is shown in the figure below:
Fig.8. Dc Motor function
N S
In order to effectively design with D.C. motors, it is necessary to understand their
characteristic curves. For every motor, there is a specific Torque/Speed curve and Power
curve as shown in Fig 9.
.
Fig.9. Dc motor Torque/Speed curve and Power curve
The graph above shows a torque/speed curve of a typical D.C. motor. Note that torque is
inversely proportional to the speed of the output shaft. In other words, there is a tradeoff
between how much torque a motor delivers, and how fast the output shaft spins. Motor
characteristics are frequently given as two points on this graph:
The stall torque, , represents the point on the graph at which the torque is a
maximum, but the shaft is not rotating.
The no load speed, , is the maximum output speed of the motor (when no
torque is applied to the output shaft).
The curve is then approximated by connecting these two points with a line, whose
equation can be written in terms of torque or angular velocity as equations 3) and 4):
Dc Motors will be studies further more in EE340 power and transmition lines class.
7.1.3 Plat Form Holder
We designed a plate of width 2.23 inches, and of length 6.5 inches (the length of the plate
could be as much as you need to place all the components that you need). We placed the
batteries, the circuit board and the microcontroller on top of the plate and the gear box at
the bottom. We made two whole of 1/8 of an inch in order to fix the gear box to the
bottom of the plate. Since we’re still in the testing phase we used a double sided metal
scotch to place the components on the plate instead of screwing them.
7.2 Mechanical Design Implementation
7.2.1 Gearbox design and assembly
Step 1
Fig.10.gears
1. Set the gears up like figure 10 above connected with the middle plastic piece.
2. Place the nut with the fit screw on the gear with shape of nut and then tighten it
the shaft as fig 11 Make sure you place a bearing/washer in slot where the axle is
inserted to the plastic piece.
3. Insert the 2 screws. Don’t over tighten screws.
4. Place the DC motor in slot like the figure below.
5. Repeat step 1 for other side.
Fig.11. gears and motor
Step 2
1. Attach the wheels to the end of the shaft. Refer to figure 10 below.
Fig.12. geras, motor and wheeels
8. Electrical Design
8.1 Project components
8.1.1 Microcontroller:
8.1.1.1General background:
A microcontroller is a small computer on a single integrated circuit, where
micro stands for small and controller means that this single chip is able to
control external devices. Microcontroller is similar to a personal computer
(PC). They both have a central processing unit (CPU), where the entire
math, the logic, and the data-moving are done. The only two differences is
that first the microcontroller is a single chip that contain the memory and
the I/O (input/output like keyboards, monitors, speakers, etc...), while in a
complete computer the memory and the I/O are not on a single-chip.
Second, the memory and interface (e.g. I/O) in a microcontroller are p
limited comparing to a complete computer.
8.1.1.1Why as designers we use a microcontroller?
We use a microcontroller in order to:
Input information from different external devices (e.g. sensors,
keyboards)
Analyze these inputs and use them in set of actions according to our
need.
Use the output mechanisms on the Microcontroller to do something
useful(e.g. run and turn off a motor)
8.1.1.2Why using an Adruino microcontroller?
Most microcontrollers could be only used with windows while the
Adruino software runs n Macintosh OSX, and Linux operating
systems.
Adruino is simpler than other microcontrollers to be programmed by
beginners, and yet flexible for advanced users. The Adruino Software
could be extended by advanced programmers, and can be expanded
through the C++ libraries.
8.1.1.3Applications:
Microcontrollers in general have many applications. Any project or object
that requires memory, and control system could be an application for any
microcontroller.
For example:
Wall avoiding robot, it avoids a wall when encountered. Avoiding the
wall could be by moving in different direction when a wall
encountered or even by turning around it.
Know how the weather is like outside. This could be done by
connecting our microcontroller to a humidity and temperature sensors
that are placed outside.
RC Car Controlled Via the Web: Strap on a standard Linksys router to
an RC car and you can wirelessly control it through the web from up to
1640 feet away.
8.1.1.4Programming examples:
a- Download the Adruino software from http://arduino.cc/en/Main/Software
The figure below shows the Adruino microcontroller that we’re using.
Fig.12. Adruino microcontroller Board
b- Work with some simple examples :
Digital I/O (e.g. blinking LED’s with, without delays, and controlling)
Analog I/O (use a potentiometer to control the blinking of an LED and
calibration for analog sensor readings)
8.1.2Motor driver
An H-bridge is an electronic circuit which enables a voltage to be applied across a load in
either direction. These circuits are often used in robotics and other applications to allow
DC motors to run forwards and backwards. H-bridges are available as integrated circuits,
or can be built from discrete components. Fig.13 illistrates the motor driver functions.
Fig.13. Structure of an H-bridge
This configuration is called an H-Bridge due to its shape. Let's say that the motor runs
forward when its + terminal is connected to Motor V+ and its - terminal is connected to
ground. It will run in reverse when the opposite is true. Turn on switch A and switch D
and the motor will run forward. Turn on switch B and switch C and it will run in reverse.
The following table shows all of the possibilities. A 1 means a switch is on, and a 0
means it's off:
A B C D State A B C D State
0 0 0 0 Off 1 0 0 0 Off
0 0 0 1 Off 1 0 0 1 Forward
0 0 1 0 Off 1 0 1 0 SHORT!!
0 0 1 1 Brake 1 0 1 1 SHORT!!
0 1 0 0 Off 1 1 0 0 Brake
0 1 0 1 SHORT!! 1 1 0 1 SHORT!!
0 1 1 0 Reverse 1 1 1 0 SHORT!!
0 1 1 1 SHORT!! 1 1 1 1 SHORT!!
Table.1. H- bridge truth table
In our project we will be using the L293D IC motor driver as shown in Fig.14. The
L293D is quadruple high-current half-H drivers. The L293D is designed to provide bidirectional
drive currents of up to 600-mA at voltages from 4.5 V to 36 V. The device is designed to drive
inductive loads such as relays, solenoids, dc and bipolar stepping motors.
Fig.14. L293D IC chip
8.1.3 RC Battery:
Fig.15. RC battety
8.1.4 Sensors:
A sensor is a device that measures a physical quantity and converts it into a signal which
can be read by an observer or by an instrument. A good sensor obeys the following rules:
Is sensitive to the measured property
Is insensitive to any other property
Does not influence the measured property
Ideal sensors are designed to be linear. The output signal of such a sensor is linearly
proportional to the value of the measured property. The sensitivity is then defined as the
ratio between output signal and measured property. For example, if a sensor measures
temperature and has a voltage output, the sensitivity is a constant with the unit [V/K]; this
sensor is linear because the ratio is constant at all points of measurement. There is a wild
vairety of sensors that could be used for many application, such as temperatue sensors,
infrared sensors, ultrasonic sensors,optical sensors, chemical and biological sensors,etc.. .
8.1.4.1Infrared sensor
Infrared sensor is an electronic device that measures infrared (IR) light radiating from
objects in its field of view. Because it does not emit any energy, its often mistakenly
called a Passive Infrared Sensor. PIR sensors are often used in the construction of PIR-
based motion detectors (see below). Apparent motion is detected when an infrared source
with one temperature, such as a human, passes in front of an infrared source with another
temperature, such as a wall. All objects emit what is known as black body radiation. It is
usually infrared radiation that is invisible to the human eye but can be detected by
electronic devices designed for such a purpose. The term passive in this instance means
that the PIR device does not emit an infrared beam but merely passively accepts
incoming infrared radiation.
In this project we will be using the following infrared sensor:
Part Number: R146-GP2D120
Price: $12.50
Weight: 0.04 lbs
This sensor takes a continuous distance reading and returns a corresponding analog
voltage with a range of 4cm (1.6") to 30cm (12").
Fig.16 infrared sensor
Absolute Maximum Ratings
Parameter Symbol Rating Unit Remarks
Supply Voltage VCC -0.3 to +7 V
Output Terminal Voltage VO -0.3 to VCC+0.3 V
Operating Temp. Topr -10 to +60 °C
Storage Temp. Tstg -40 to +70 °C
Operating Supply Voltage
Parameter Symbol Rating Unit Remark
Operating Supply Voltage VCC 4.5 to 5.5 V
Electro-Optical Characteristics
Parameter Symbol Conditions Min. Typ. Max. Unit
Measuring distance
range delta L *1 4 - 30 cm
Output Terminal
Voltage VO L = 30 cm *1 0.25 0.4 0.55 V
Output voltage
difference
delta
VO
Output change at L change (30 cm
-> 4 cm) *1 1.95 2.25 2.25 V
Average supply
current Icc L = 30 cm, *1 - 33 50 mA
L: Distance to reflected object *1 Using reflected object: White paper (Made by Kodak Co. Ltd. gray cards
R-27, white face, reflective ratio: 90%)
8.1.4.2 Temperature sensor
Thermistors are inexpensive, easily-obtainable temperature sensors. They are easy to use
and adaptable. Circuits with thermistors can have reasonable outout voltages - not the
millivolt outputs thermocouples have. Because of these qualities, thermistors are widely
used for simple temperature measurements. They're not used for high temperatures, but
in the temperature ranges where they work they are widely used.
Thermistors are temperature sensitive resistors. All resistors vary with temperature, but
thermistors are constructed of semiconductor material with a resistivity that is especially
sensitive to temperature. However, unlike most other resistive devices, the resistance of a
thermistor decreases with increasing temperature. That's due to the properties of the
semiconductor material that the thermistor is made from. For some, that may be
counterintuitive, but it is correct. Here is a graph of resistance as a function of
temperature for a typical thermistor. Notice how the resistance drops from 100 kW, to a
very small value in a range around room temperature. Not only is the resistance change
in the opposite direction from what you expect, but the magnitude of the percentage
resistance change is substantial.
Fig.17. resistant – Temperature relation
In this lesson you will examine some of the characteristics of thermistors and the
circuits they are used in.
Why Use Thermistors To Measure Temperature?
o They are inexpensive, rugged and reliable.
o They respond quickly
In this project we will be using the LM34CZ Temperature Sensor which
produces an output voltage proportional to the current measured temperature. The
LM34CZ comes in a TO-92 plastic package and has range of -40F to +230F.
Fig.18. LM34CZ Temp. sensor
8.1.4.3Ultrasonic sensor
Ultrasonic sensors or transducers when they both send and receive work on a principle
similar to radar or sonar which evaluate attributes of a target by interpreting the echoes
from radio or sound waves respectively. Ultrasonic sensors generate high frequency
sound waves and evaluate the echo which is received back by the sensor. Sensors
calculate the time interval between sending the signal and receiving the echo to determine
the distance to an object as shown in fig.19.
Fig.19.ultrasonic sensor wave sketch
In this project we will be using the PING Ultrasonic Sensor fig.20 which provides a very
low-cost and easy method of distance measurement. This sensor is perfect for any
number of applications that require you to perform measurements between moving or
stationary objects. Naturally, robotics applications are very popular but you'll also find
this product to be useful in security systems or as an infrared replacement if so desired.
You will definitely appreciate the activity status LED and the economic use of just 1 I/O
pin.
Fig.20. PING Ultrasonic Sensor
PING)))™ Sensor Features
The PING))) has only has 3 connections, which include Vdd, Vss, and 1 I/O pin.
The 3-pin header makes it easy to connect using a servo extension cable, no
soldering required.
Several sample codes are available using the Ping))) sensor.
Key Specifications:
Range - 2cm to 3m (~.75" to 10')
Supply Voltage: 5V +/-10% (Absolute: Minimum 4.5V, Maximum 6V)
Supply Current: 30 mA typ; 35 mA max
3-pin interface (power, ground, signal)
20 mA power consumption
Narrow acceptance angle
Simple pulse in / pulse out communication
Indicator LED shows measurement in progress
Input Trigger - positive TTL pulse, 2 µs min, 5 µs typ.
Echo Pulse - positive TTL pulse, 115 µs to 18.5 ms
Echo Hold-off - 750 µs from fall of Trigger pulse
Burst Frequency - 40 kHz for 200 µs
Size - 22 mm H x 46 mm W x 16 mm D (0.85 in x 1.8 in x 0.6 in)
To learn more about the sensor application and schematics you can check out the
documentation from the following website http://www.parallax.com/.
8.1.5 PCB-Printed Circuitry Board
A printed circuit board, or PCB, is used to mechanically support and electrically connect
electronic components using conductive pathways, or traces, etched from copper sheets
laminated onto a non-conductive substrate as shown in fig 21.
Fig.21. PCB
In designing PCB the student must have full knowledge with Ultimatum software, which
is a tool to help generate a PCB schematic and final design of project circuit. However in
the current project we will be using a complete PCB that will fit all our circuitry
components as shown in fig22.
Fig.22. PCB ready for usage
In the time of PCB usage, student must have taken an introduction and safety seminar
on soldering of integrated circuit-IC components as mention in section 3.
8.2 electrical Design Implementation
8.2.1 Driver Connection
Connecting the microcontroller to the driver and run the motors:
As we mentioned before the microcontroller is usually helpful when we
receive some kind of inputs from externals devices and then outputs some
actions according to these inputs. However, now we don’t need any inputs
to the microcontroller since at this phase we’re only concerned about
turning on the motors.
In this phase we will send a signal from the microcontroller to the driver that will
turn one or the two motors on depending on our code.
In order to do that, we need to first to take care of the electrical part before start
programming it. Therefore, we connected pin 2 and pin 7 of the driver to the
digital pins of the Adruino 7 & 8 respectively, and pin 15 and 10 of the driver to
the digital pins 2 and 4 respectively (fig23 ). Notice that so far we connected the
microcontroller to the driver but not yet to the motor. In order to do that we will
connect pin 3 and 6 of the driver to the motor A, and pin 14 and 11 to the motor B
(fig 23).
Fig.23. the figure above is a simple motor driver circuit using the L293D
Motor driver
Like any driver the L293D need a power and a ground. As we see in fig23 the
pins 1, 8, 9 and 16 are the power pins, and 4, 5, 12, and 13 are the ground.
Remark: We could’ve used any digital pins of the Adruino to be connected to the
right signal pins of the driver (to pin 2 & 7 and to pin 15 & 10) but we have to be
careful to change the code later on.
8.2.2 Sensors Connections:
In section 7.2.2 a. we didn’t really have any external input devices that would
control our output, but now we added a front sensor that would help us avoid any
wall collisions.
The sensor that we’re using is an infrared sensor (IR) as we discussed in previous
sections. This sensor has a ground, power, and data pins. Therefore we will
connect the ground and the power sensor pins to the microcontroller power and
ground pins. Since the sensor data output is an analog output we will connect it to
one of the analog pins of our microcontroller as we see in fig24.
Fig.24. sensor pin connection
8.2.3Programming the microcontroller using Adruino software( c++ )
Programming the microcontroller in order to run the motors without any sensor inputs
decision: The example below is a program sample on how to run the robot in forward and
backward directions.
int rightPin1 = 4;
int rightPin2 = 2;
int leftPin1 = 8;
int leftPin2 = 7;
void setup()
{
pinMode(rightPin1, OUTPUT); // pinMode: is used to configure a
specified
pinMode(rightPin2, OUTPUT); //pin to behave as an input or ouput
pinMode(leftPin1, OUTPUT);
pinMode(leftPin2, OUTPUT);
// for more details about the functions visit
//http://www.arduino.cc/playground/uploads/Main/arduino_notebook_v1-
1.pdf
}
void loop()
{
// Digital write function output either HIGH or LOW.
//In other word turns on or off a specified digital pin.
// Each motor has 2 pins. The 2 pins control the direction of the motor.
//If one set high and the other low the motor would turn clockwise.
// If we reverse the motor would turn in counter clockwise.
// Therefore in order to go forward we need both motor to run
simultaneously in //clockwise direction, whereas to go backward we need
both motor to run in a counter //clockwise direction.
// go backward
digitalWrite(rightPin1, HIGH);
digitalWrite(rightPin2, LOW);
digitalWrite(leftPin1, HIGH);
digitalWrite(leftPin2, LOW);
delay(5000);
digitalWrite(rightPin1, LOW);
digitalWrite(rightPin2, LOW);
digitalWrite(leftPin1, LOW);
digitalWrite(leftPin2, LOW);
delay(5000);
//go forward
digitalWrite(rightPin1, LOW);
digitalWrite(rightPin2, HIGH);
digitalWrite(leftPin1, LOW);
digitalWrite(leftPin2, HIGH);
delay(5000);
}
a- Programming the microcontroller in order to run the motors
according to the sensor inputs:
This code will show us how we can control our motors depending
on the input values from the sensors to the microcontroller.
*/ this program will avoid the entire encountered wall. When the robots
encounter a wall it would turn left and then move forward.
For more details about the build in functions and syntax visit.
http://www.arduino.cc/playground/uploads/Main/arduino_notebook_v1-
1.pdf
*/
int rightpin1 = 4;
int rightpin2 = 2;
int leftpin1 = 8;
int leftpin2 = 7;
int sensor = 1;
int val = 0;
int LED = 13;
void setup()
{
Serial.begin(9600); //serial. begin opens serial port and sets the
pinMode(rightpin1, OUTPUT); //baud for serial data transmission.
pinMode(rightpin2, OUTPUT);
pinMode(leftpin1, OUTPUT);
pinMode(leftpin2, OUTPUT);
pinMode(sensor, INPUT); // Here we defined the analog pin 1 (sensor
pin)
pinMode(LED, OUTPUT); // as input since we’re inputting to the
microcontroller
} // the values captured by the sensor
void loop()
{
val = analogRead(sensor); // analogRead would read a 10 bit analogue
value that
delay(1000) //ranged from 0-1023;
while ( val < 550 )
{
// As along as the value captured by sensor is less than 550, the
LED would stay //off, and the motor would go forward
digitalWrite(LED, LOW);
digitalWrite(rightpin1, HIGH);
digitalWrite(rightpin2, LOW);
digitalWrite(leftpin1, HIGH);
digitalWrite(leftpin2, LOW);
/*reading the value from the sensor inside the while loop is essential
because it would let us exit the loop if the value read is greater than 550
otherwise we will be stuck in an infinite loop. */
val = analogRead(sensor);
Serial.print("sensor_value:"); // will print the value read by sensor to
the monitor
Serial.print(val, DEC);
delay(500);
}
// when the captured value of the sensor is bigger than 550 (means
we’re //getting closer to a wall the robot will turn right, stop, and
then go back to the //top of the Loop() function.
digitalWrite(rightpin1, HIGH);
digitalWrite(rightpin2, LOW);
digitalWrite(leftpin1, LOW);
digitalWrite(leftpin2, LOW);
delay(500);
digitalWrite(rightpin1, LOW);
digitalWrite(rightpin2, LOW);
digitalWrite(leftpin1, LOW);
digitalWrite(leftpin2, LOW);
digitalWrite(LED, HIGH);
delay(1000);
}
mechatronics final design:
Fig.25. Top view
Fig.26. bottom View
Fig.27.Driver connection to microcontroller
Fig.28. Front View - infrared sensor on board
Cost:
List of parts:
S.no Product Name Vendor/
Manufacturer
Stock
Number
Price
($)
Quantity
1. Tamiya Twin Motor
Gearbox
Hobby Engineering H02055-01F 11.99 1
2. Off-Road Tire Set (2)
from Tamiya
Hobby Engineering H02033-01C 3.99 1
3. Ball Caster (Set of 2)
from Tamiya
Hobby Engineering H02016-01H 6.99 1
4. L293D Dual H-Bridge Hobby Engineering H01384-01N 3.25 4
5. Arduino Starter Pack Adafruit Industries ********* 65.00 1
6. RC battery 1