Ebook Arduino Uno R3 DIY Module
Ebook Arduino Uno R3 DIY Module
DIY MODULE
EMBEDDED ROBOTIC
TUAN ROZILAAZAWANI BINTI TUAN MAT
HASYIREEN BINTI ABDUL HALIM
DR. KHAIRUNNISA BINTI A RAHMAN
ARDUINO UNO R3
DIY MODULE
EMBEDDED ROBOTIC
0
First Publication: July 2024
©Copyright 2024
Editor
Tuan Rozilaazawani binti Tuan Mat
Graphic Designer
Shamsul bin Mazalan
Published by:
Petrochemical Engineering Department,
Politeknik Tun Syed Nasir Syed Ismail,
Hab Pendidikan Tinggi Pagoh,
KM1 Jalan Panchor
84600 Panchor, Muar, Johor, Malaysia
1
PREFACE
In the name of Allah, the Most Gracious, the Most Merciful, we extend our
heartfelt gratitude to Him for granting us enlightenment, truth, and knowledge. With
utmost respect, we acknowledge Prophet Muhammad S.A.W. for guiding us along
the righteous path. We are deeply thankful to Allah S.W.T. for providing us the
strength to write this book, and we pray that He continues to grant us the ability to
serve our community, particularly in the field of robotics.
The book comprises six practical tasks: Introduction to Arduino Editor and
Proteus Software, Basic Robotic Programming in C, Arduino UNO R3
Microcontroller, Robotic Controller Programming in C, Mobile Robot Design, and
Sumo Robot Design. Each task provides a theoretical overview followed by hands-on
activities to reinforce basic concepts. Additionally, each practical task is
supplemented with questions and answers to facilitate learning.
By the end of these practical tasks and exercises, you will be able to
comprehend robot positioning, identification, and communication in mobile robot
control as per standard robotic regulations. You will also learn to apply sensors and
actuators, manage robot identification and communication, and design Sumo robots
using land mobile robot principles.
2
AUTHOR
3
CONTENT
4
1.0 Introduction
For instance, in the year 2020, the DGI40122 Embedded Robotic Course has been
launched with the latest revised syllabus in Malaysian Polytechnic by the Ministry of
Higher Education's Department of Polytechnic and Community College. The course
teaches students at the basic and intermediate levels how to combine mobile robots and
embedded systems.
Despite the fact that PBL is commonly used in embedded robotics, it is demonstrated
that there is still a lack of suitable guidance on the intended approach for the creation of
practical work processes that take this into consideration, especially for the Malaysian
polytechnic. Furthermore, it was observed that there was a lack of diverse types of
practical work series that best provided a more complete understanding of assessment
towards the applicability of embedded robotic teaching methods (Jawaid et al., 2020).
The implications will result in practical pedagogy only focused on one means of
communication for electrical and instrumentation engineering students without displaying
the interconnection between user experience and soft skills development. The effective
teaching of practical work series for embedded robotics, on the other hand, necessarily
involves interaction with particular technological goal-setting pertaining to programming
and hardware, for instance, using the Arduino microcontroller, C programming
5
development for embedded robotics, and project design experience.
Thus, the initiatives for the development of practical work procedures must be taken in a
planned manner. The Embedded Robotics DGI140122 was chosen to illustrate this
conceptual analysis because it provides a novel, systematic assessment technique for
combining these two types of methods. This practical work series was created with the use of
an Arduino microcontroller, a land mobile robot, the Arduino Editor, and the Proteus
software.
There are three structured combinations: (1) dealing with embedded systems, to
evaluate students’ cognitive skills such as programming and application of the C
language; (2) sensors and actuators, a psychomotor assessment to observe results and
gain judgements from embedded systems design; and (3) mobile robot design, a mix of
psychomotor and cognitive abilities to observe results and acquire judgments from
embedded systems design. Jawaid et al., (2020) supported that a successful course
design strategy of PBL in teaching engineering content to the learners was of the utmost
importance in the robotic field.
Engineering students can receive good benefits from PBL because it gives hands-on,
real-world experience that helps comprehend technical ideas and concepts better. By
assigning tasks that lead to the development of a final product in terms of design, model,
device, program coding, and simulation, PBL gives direction and encourages self-directed
and active learning (Larson et al., 2020).
6
2.0 Practical Task Overview
You must be familiar with this manual in order to complete the exercises given within. With all
these exercises, you will learn about:
i. Introduction to Arduino Editor and Proteus Software
ii. Basic Robotic Programming in C
iii. Arduino UNO R3 Microcontroller
iv. Robotic Controller Programming in C
v. Mobile Robot Design
vi. Sumo Robot Design
Upon completion of these laboratory and exercises, you will be able to determine the concept
of robot positioning, identification and communication in mobile robot control according to
standard robot organization regulation; manipulates the application of sensor and actuator,
robot identification and communication during practical work based on land mobile robot
design; and organize mini competition among themselves to compete using land mobile
robot.
"Uno" means one in Italian and was chosen to mark the release of Arduino
Software (IDE) 1.0. The Uno board and version 1.0 of Arduino Software (IDE) were
the reference versions of Arduino, now evolved to newer releases. The Uno board
is the first in a series of USB Arduino boards, and the reference model for the
Arduino platform; for an extensive list of current, past or outdated boards see the
Arduino index of boards.
7
Summary
Microcontroller ATmega328
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limits) 6-20V
Digital I/O Pins 14 (of which 6 provide PWM output) : 0-13
Analog Input Pins 6 (A0-A5)
DC Current per I/O Pin 40mA
DC Current for 3.3V Pin 50mA
Flash Memory 32KB (ATmega328) of which 0.5KB used by bootloader
SRAM 2KB (ATmega328)
EEPROM 1KB (ATmega328)
Clock Speed 16MHz
Figure 1 shows the Arduino Uno Board. For more information please refer to the datasheet.
The data sheet can be found at [Link]
8
4.0 Hardware and Software Preparation
This Arduino UNO R3 DIY Module Embedded Robotic covers the basic concept and
application of microcontroller systems based on the Arduino Uno R3. Users will learn
software and hardware development on Arduino development system such as Arduino
Software (IDE) and understand how to do interfacing with external devices using suitable
internal chip features. Users are also exposed to the new Microcontroller Unit (MCU)
simulation software such as Proteus.
Hardware Setup
The basic hardware in this teaching kit are Arduino Uno R3, computer/laptop and USB cable.
Basic hardware connection to a computer/laptop as shown in Figure 2.
Computer/Laptop
Arduino Uno
USB Cable
9
Arduino Software (IDE)
The open-source Arduino Software (IDE) makes it easy to write code and upload it to the
board. This software can be used with any Arduino board. Arduino is an open-source
physical computing platform based on a simple I/O board and a development environment
that implements the Processing/Wiring language. Arduino can be used to develop stand-
alone interactive objects or can be connected to software on your computer (e.g. Flash,
Processing and MaxMSP). The boards can be assembled by hand or purchased
preassembled; the open-source IDE can be downloaded for free at [Link]
Figure 3: Arduino
Active development of the Arduino software is hosted by GitHub. This organisation contains
the official Arduino tools (IDE, CLI...), documentation and cores. See @arduino-libraries for
the official libraries or [Link]
10
Proteus 7/8 Professional
Proteus is simulator software which is capable to simulate any circuit and scenario. Mainly, it
is best for microcontrollers. Proteus professional design combines the ISIS schematic
capture and ARES PCB layout programs to provide a powerful, integrated and easy to use
tools suite for education and professional PCB Design.
The Proteus Professional are software for automated design of electronic circuits. The
package is a system of circuit simulation, based on the models of electronic components in
SPICE. A distinctive feature of the package Proteus Professional is the possibility of
modelling of the programmable devices: microcontrollers, microprocessors, DSP and others.
11
5.0 Hardware Specification
Table 1 shows the hardware specification for Arduino UNO R3 DIY Kit.
No Components Quantity
1 Arduino UNO R3 1
2 2WD Smart Robot Car Chassis 1
3 Ultrasonic Sensor HC-SR04 1
4 Auto-calibration Line Sensor 1
5 Bluetooth Module HC-05 1
6 Dual H-Bridge Driver L293D 1
7 LiPO Rechargeable Battery 11.1V 2200mAh 1
8 Multi-Function LiPO Balance Charger 1
9 Arduino Editor 1
10 Proteus Software 1
11 Computer/Laptop 1
12
7.0 DIY Kit Operational Procedure
i. Prepare all the equipment and material use such as Arduino UNO R3, input-output
(I/O) components, robot mobile and USB cable.
ii. Plug one end of the USB cable into the USB Arduino board. Plug the other end into a
USB port on your PC.
iii. The lights indicator on the Arduino board will turn on. It shows that the equipment is in
good condition.
iv. Open Arduino Editor workspace window. Select menu Tools – Board: “Arduino UNO”
– Select Arduino UNO.
v. Then, select menu File – Preferences – menu Settings – checked box “Show verbose
output during: √ compilation – then OK.
vi. Follow the next procedure to complete the practical work.
13
PRACTICAL TASK
14
[CONTENT OF PRACTICAL TASK]
15
PRACTICAL TASK 1
LEARNING OBJECTIVES:
Students will be able to;
1. Perform an installation of Proteus software and Arduino Editor.
2. Write a C program that will run on the Arduino Uno.
3. Assembles a C program to define input and output programming.
4. Make an observation on the output of C program using Proteus.
EQUIPMENTS:
1. Arduino IDE Installer
2. Proteus Installer
3. Computer
THEORY:
ARDUINO UNO
"Uno" means one in Italian and was chosen to mark the release of Arduino
Software (IDE) 1.0. The Uno board and version 1.0 of Arduino Software (IDE)
were the reference versions of Arduino, now evolved to newer releases. The Uno
board is the first in a series of USB Arduino boards, and the reference model for
the Arduino platform; for an extensive list of current, past or outdated boards see
the Arduino index of boards.
16
Figure 1 : Arduino Uno Board
PROTEUS
Proteus Professional is a software which can be used to draw schematics, PCB layout,
code and even simulate the schematic. It is developed by Labcenter Electronic Ltd.
ISIS has wide range of components in its library. It has sources, signal generators,
measurement and analysis tools like oscilloscope, voltmeter, ammeter etc., probes for real
time monitoring of the parameters of the circuit, switches, displays, loads like motors and
lamps, discrete components like resistors, capacitors, inductors, transformers, digital and
analog Integrated circuits, semi-conductor switches, relays, microcontrollers, processors,
sensors etc.
17
PROCEDURES A
1. Follow all the instructions in Proteus Installation Note file in your Installer Folder.
2. Finish the installation.
3. Create a Proteus desktop shortcut.
18
Figure 2 : Folder Options for Show Hidden Files
19
QUESTIONS & ANSWERS
Proteus 7/8 Professional is a software which can be used to draw schematics, PCB
layout, code and even simulate the schematic.
The open-source Arduino Software (IDE) makes it easy to write code and upload it to
the board. This software can be used with any Arduino board.
20
PRACTICAL TASK 2
LEARNING OBJECTIVES:
Students will be able to;
1. Write a C program for the Delay subroutine and language subroutines.
2. Assembles a C program to define analog and digital input output.
3. Sketch a schematic circuit of LED Blink, Seven Segment and LCD Display using
Proteus.
4. Make an observation on the output of C program using Proteus.
EQUIPMENTS:
1. Arduino Editor
2. Proteus Software
3. Computer
THEORY:
ARDUINO EDITOR
The open-source Arduino Software (IDE) makes it easy to write code and upload it to the
board. It runs on Windows, Mac OS X, and Linux. The environment is written in Java and
based on Processing and other open-source software.
This software can be used with any Arduino board. The Arduino Web Editor allows you to
write code, save it to the cloud and upload sketches to any Arduino board and Intel®-
based platforms from your web browser after installing a simple plug-in.
21
Figure 1 : Arduino Editor
PROTEUS
Proteus 7 Professional is a software which can be used to draw schematics, PCB layout,
code and even simulate the schematic. It is developed by Labcenter Electronic Ltd.
ISIS has wide range of components in its library. It has sources, signal generators,
measurement and analysis tools like oscilloscope, voltmeter, ammeter etc., probes for real
time monitoring of the parameters of the circuit, switches, displays, loads like motors and
lamps, discrete components like resistors, capacitors, inductors, transformers, digital and
analog Integrated circuits, semi-conductor switches, relays, microcontrollers, processors,
sensors etc.
SEVEN-SEGMENT DISPLAY
The seven elements of the display can be lit in different combinations to represent
the arabic numerals. Often the seven segments are arranged in anoblique (slanted)
arrangement, which aids readability. In most applications, the seven segments are of
nearly uniform shape and size (usually elongated hexagons, though trapezoids and
22
rectangles can also be used), though in the case of adding machines, the vertical
segments are longer and more oddly shaped at the ends in an effort to further enhance
readability. The numerals 6, 7 and 9 may be represented by two or more different glyphs
on seven-segment displays. The seven segments are arranged as a rectangle of two
vertical segments on each side with one horizontal segment on the top, middle, and
bottom. Additionally, the seventh segment bisects the rectangle horizontally. There are
also fourteen-segment displays and sixteen-segment displays (for full alphanumerics);
however, these have mostly been replaced by dot-matrix displays. The segments of a 7-
segment display are referred to by the letters A to G, where the optional DP decimal
point (an "eighth segment") is used for the display of non-integer numbers.
In a simple LED package, typically all of the cathodes (negative terminals) or all of
the anodes (positive terminals) of the segment LEDs are connected and brought out to a
common pin; this is referred to as a "common cathode" or "common anode" device. Hence
a 7 segment plus decimal point package will only require nine pins (though commercial
products typically contain more pins, and/or spaces where pins would go, in order to match
standard IC sockets. For example, all the anodes of the A segments of each digit position
would be connected together and to a driver pin, while the cathodes of all segments for
each digit would be connected. To operate any particular segment of any digit, the
controlling integrated circuit would turn on the cathode driver for the selected digit, and the
anode drivers for the desired segments; then after a short blanking interval the next digit
would be selected and new segments lit, in a sequential fashion. In this manner an eight
digit display with seven segments and a decimal point would require only 8 cathode drivers
and 8 anode drivers, instead of sixty-four drivers and IC pins. A single byte can encode the
full state of a 7-segment-display. The most popular bit encodings are gfedcba and abcdefg,
where each letter represents a particular segment in the display. In
the gfedcba representation, a byte value of 0x06 would (in a common-anode circuit) turn on
segments 'c' and 'b', which would display a '1'.
23
Basically there are two types of 7-Segment displays:
1. Common Cathode where all the segments share the same Cathode.
2. Common Anode where all the segments share the same Anode.
Common Anode is order to turn ON a segment the corresponding pin must be set to 0.
And to turn it OFF if set to 1. Whereas Common Cathode is order to turn ON a segment the
corresponding pin must be set to 1. And to turn it OFF if set to 0. Figure 2 and 3 shown
truth table for Seven Segment decoder outputs.
24
LCD Display
The 2x16 character LCD offers character display for embedded system. It can be used to
display numerical information, text message and also special symbol. We can control a
LCD using either 8 pins (8-bit interface) or 4 pins (4-bit interface), depending on the I/O
pins that we have.
PROCEDURES
void setup ( ) {
// initialize digital pin LED_13 as an output.
pinMode (13, OUTPUT);
}
25
ii. Seven Segment Source Code
26
void six() { void eight() {
digitalWrite(2,HIGH); digitalWrite(2,HIGH);
digitalWrite(3,LOW); digitalWrite(3,HIGH);
digitalWrite(4,HIGH); digitalWrite(4,HIGH);
digitalWrite(5,HIGH); digitalWrite(5,HIGH);
digitalWrite(6,HIGH); digitalWrite(6,HIGH);
digitalWrite(7,HIGH); digitalWrite(7,HIGH);
digitalWrite(8,HIGH); digitalWrite(8,HIGH);
delay (1000); delay (1000);
} }
void seven() { void nine() {
digitalWrite(2,HIGH); digitalWrite(2,HIGH);
digitalWrite(3,HIGH); digitalWrite(3,HIGH);
digitalWrite(4,HIGH); digitalWrite(4,HIGH);
digitalWrite(5,LOW); digitalWrite(5,HIGH);
digitalWrite(6,LOW); digitalWrite(6,LOW);
digitalWrite(7,LOW); digitalWrite(7,HIGH);
digitalWrite(8,LOW); digitalWrite(8,HIGH);
delay (1000); delay (1000);
} }
void setup ( ) {
// set up the LCD's number of columns and rows:
[Link] (16, 2);
// Print a message to the LCD.
[Link] ("Embedded Robotic");
}
void loop ( ) {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
[Link] (0, 1);
// print the number of seconds since reset:
[Link](millis ( ) / 1000);
}
27
B. Sketches Schematic Circuits
28
Figure 7 : Seven Segment Schematic Circuits
29
RESULTS
1. LED BLINK
2. SEVEN SEGMENT
3. LCD DISPLAY
LCD display “Embedded Robotic” and at the second row, it wil display counting number
start from 0 to infinity.
void setup ( ) {
// initialize digital pin LED_BUILTIN as an output.
pinMode (13, OUTPUT);
pinMode (10, OUTPUT);
}
30
2. Write a source code to display number 9 to 0 on seven segment.
void setup() {
// put your setup code here, to run once:
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
nine();
eight();
seven();
six();
five();
four();
three();
two();
one();
zero();
}
void zero() {
digitalWrite(2,HIGH);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
delay (1000);
}
void one() {
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
delay (1000);
}
…………………..
31
3. Write a source code to display TWO lines message on LCD display.
void setup ( ) {
// set up the LCD's number of columns and rows:
[Link] (16, 2);
// Print a message to the LCD.
[Link] ("Embedded Robotic");
[Link] (2,1);
[Link] (“PTSN Hebat”);
}
void loop ( ) {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
[Link] (0, 1);
// print the number of seconds since reset:
[Link](millis ( ) / 1000);
}
32
PRACTICAL TASK 3
LEARNING OBJECTIVES:
Students will be able to;
1. Assembles a C program to control DC motors, LM35, LDR and ultrasonic sensor.
2. Sketch a schematic circuit of Arduino Uno using Proteus.
3. Make an observation on the output of C program using Proteus.
EQUIPMENTS:
1. Arduino Editor
2. Proteus Software
3. Computer
THEORY:
LDR sensors
An LDR is a component that has a (variable) resistance that changes with the light intensity
that falls upon it. This allows them to be used in light sensing circuits. Light Dependent
Resistors (LDR) are also called photoresistors. They are made of high resistance
semiconductor material.
33
Ultrasonic Sensor
An ultrasonic sensor is an instrument that measures the distance to an object using
ultrasonic sound waves. An ultrasonic sensor uses a transducer to send and receive
ultrasonic pulses that relay back information about an object's proximity.
34
A. DC MOTOR
void setup ( ) {
// put your setup code here, to run once:
void loop ( ) {
// put your main code here, to run repeatedly:
analogWrite (9,val);
analogWrite (10,0);
delay (10);
}
35
B. LM35
int val;
int tempPin = 1;
void setup() {
// use a for loop to initialize each pin as an output:
pinMode (12, OUTPUT);
pinMode (13, OUTPUT);
[Link] (9600);
}
void loop() {
// loop from the lowest pin to the highest:
val = analogRead (tempPin);
float mv = (val/1024.0) *5000;
float cel = mv/10;
if (cel<30)
{
digitalWrite (12,HIGH);
digitalWrite (13,LOW);
}
else {
digitalWrite (13,HIGH);
digitalWrite (12,LOW);
}
delay (500);
}
36
Figure 3 : LM35 Schematic Diagram
void setup ( ) {
// use a for loop to initialize each pin as an output:
pinMode (10, OUTPUT);
[Link] (9600);
}
if (sensorValue<15)
{
digitalWrite (10,HIGH);
}
else
{
digitalWrite (10,LOW);
}
delay (1); //delay in between reads for stability
}
37
Figure 4 : LDR With Torch Schematic Diagram
int timer = 100; //the higher the number, the slower the timing
void setup() {
// use a for loop to initialize each pin as an output:
for (int thisPin = 2; thisPin < 8; thisPin++) {
pinMode (thisPin, OUTPUT); }
}
38
Figure 5 : LED Knight Rider Schematic Diagram
RESULTS
1. DC MOTOR
2. LM35
Green LED will ON if the temperature less than 30°C and red LED will ON if the
temperature more than 31°C.
Green LED turn ON when the sensor value less than 15 and turn OFF if the sensor
value more than 15.
The LED will turn ON start from D4, D5, D6, D3, D2, D1 and back to D4 continously.
39
QUESTIONS & ANSWERS
2. if (cel<30)……..else……..
if statements test whether a certain condition has been reached, such as an analog
value being above a certain number and executes any statements inside the
bracket if the statement is TRUE. If FALSE, the program skips over the statement.
3. [Link] (9600);
Open serial port and sets the baud rate for serial data transmission. The typical
baud rate for communicating with the computer is 9600 although other speeda are
supported.
40
PRACTICAL TASK 4
LEARNING OBJECTIVES:
Students will be able to;
1. Assembles a C program to control DC motors.
2. Complete the hardware installation of robot base with two DC motors.
3. Build a C program to control DC motor directions forward and reverse.
4. Make an observations of program C on DC motors.
EQUIPMENTS / COMPONENTS:
1. ARDUINO UNO Board
2. DC motors
3. L298 (Dual full-bridge driver)
THEORY:
Let’s start with how actually DC motor runs. Direction control of a DC motor is very simple, just
reverse the polarity to make it reverse rotation. Mean to say that every DC motor has two
terminals out. When we apply DC voltage with proper current to a motor, it rotates in a
particular direction but when we reverse the connection of voltage between two
terminals, motor rotates in another direction.
It is a special circuit which allows motor rotation in both directions. From four terminals of a
H bridge you can control the direction of a DC motor. Depending on current & power
requirements, we can make our own H bridge using transistors/MOSFETs but it will be
41
better to demonstrate the working, if we use some ready-made IC such as L298, it’s a
dual full-bridge driver.
PROCEDURE
PART A
1. Open the Proteus software, select the following part from library
a. Arduino Uno R3
b. L298, dual full-bridge driver
c. Motor, simple DC motor model
2. Create new project, use naming profile <PW4_X>, with X indicate your group
number.
3. Drag all component into schematic layout, and use your own creativity for
component arrangement and pin connection. Use below schematic
diagram for guideline.
4. Save your project.
42
Figure 3 : DC Motors Schematic Diagram
PART B
1. Open the Arduino software. Click on the ‘File’ menu and select ‘Preferences’.
Click on the checkbox like below.
43
//declaration
#define motorA 8 //motor A enable pin connect to pin 8
#define motorB 3 //motor B enable pin connect to pin 3
void setup () {
// put your setup code here, to run once:
pinMode (1, OUTPUT); //make pin as output
pinMode (2, OUTPUT);
pinMode (motorB, OUTPUT);
pinMode (motorA, OUTPUT);
pinMode (9, OUTPUT);
pinMode (10, OUTPUT); }
void loop () {
// put your main code here, to run repeatedly:
//rotate motorA CW
digitalWrite (motorA, HIGH); //enable pin for motorA
digitalWrite (9, HIGH); //change both signal to change rotation
digitalWrite (10, LOW);
PART C
1. Double click the Arduino Uno R3 component in Proteus to invoke the ‘Edit
Component’ window. On part ‘Program Files’, point it to your hex file location on
PART B, then click ‘OK’.
2. On the lower left side of your schematic layout, click the play button to start
the simulation. Observe the output.
44
QUESTIONS & ANSWERS
//declaration
#define motorA 8 //motor A enable pin connect to pin 8
#define motorB 3 //motor B enable pin connect to pin 3
void setup () {
// put your setup code here, to run once:
pinMode (1, OUTPUT); //make pin as output
pinMode (2, OUTPUT);
pinMode (motorB, OUTPUT);
pinMode (motorA, OUTPUT);
pinMode (9, OUTPUT);
pinMode (10, OUTPUT); }
void loop () {
// put your main code here, to run repeatedly:
//rotate motorA CW
digitalWrite (motorA, HIGH); //enable pin for motorA
digitalWrite (9, HIGH); //change both signal to change rotation
digitalWrite (10, LOW);
2. Sketch and simulate a code to make motor A and motor B to rotate CW for 1
second and rotate CCW for 1 second. Make it run on infinity looping.
//declaration
#define motorA 8 //motor A enable pin connect to pin 8
#define motorB 3 //motor B enable pin connect to pin 3
void setup () {
// put your setup code here, to run once:
pinMode (1, OUTPUT); //make pin as output
pinMode (2, OUTPUT);
pinMode (motorB, OUTPUT);
pinMode (motorA, OUTPUT);
pinMode (9, OUTPUT);
45
pinMode (10, OUTPUT); }
void loop () {
// put your main code here, to run repeatedly:
//rotate motorA CW
digitalWrite (motorA, HIGH); //enable pin for motorA
digitalWrite (9, HIGH); //change both signal to change rotation
digitalWrite (10, LOW);
digitalWrite (motorB, HIGH); //enable pin for motorB
digitalWrite (1, HIGH); //change both signal to change rotation
digitalWrite (2, LOW);
3. Sketch a program to make robot spin CW for 5 seconds, Stop 1 second and
then spin CCW for 5 seconds and completely stop.
//declaration
#define motorA 8 //motor A enable pin connect to pin 8
#define motorB 3 //motor B enable pin connect to pin 3
void setup () {
// put your setup code here, to run once:
pinMode (1, OUTPUT); //make pin as output
pinMode (2, OUTPUT);
pinMode (motorB, OUTPUT);
pinMode (motorA, OUTPUT);
pinMode (9, OUTPUT);
pinMode (10, OUTPUT); }
void loop () {
// put your main code here, to run repeatedly:
//rotate motorA CW
digitalWrite (motorA, HIGH); //enable pin for motorA
digitalWrite (9, HIGH); //change both signal to change rotation
digitalWrite (10, LOW);
//rotate motorB CW
digitalWrite (motorB, HIGH); //enable pin for motorB
digitalWrite (1, HIGH); //change both signal to change rotation
digitalWrite (2, LOW);
delay (5000); //delay 5 second
46
digitalWrite (motorA, LOW); //stop motorA
digitalWrite (motorB, LOW); // stop motorB
delay (1000); //delay 1 second
47
PRACTICAL TASK 5
LEARNING OBJECTIVES:
Students will be able to;
1. Assembles a C program to control DC motors and sensors.
2. Complete the hardware installation of Line Follower Robot (LFR).
3. Perform an application of LFR using DC motors, ultrasonic sensor and line sensor.
4. Make an observation on the movement of LFR.
EQUIPMENTS / COMPONENTS:
1. ARDUINO UNO Board a n d DC motors with L298 (Dual full-bridge driver)
2. HC-SR04 ultrasonic sensor
THEORY:
The human ear can hear sound frequency around 20Hz and 20KHz, and ultrasonic
is the sound wave beyond the human ability of 20KHz.
As ultrasonic spread velocity is 340 m/s in the air, based on the timer record t, we can
calculate the distance (s) between the obstacle and transmitter, namely: s = 340*t/2,
which is so called time difference distance measurement principle.
48
Ultrasonic Application Technology is the thing which developed in recent decades.
With the ultrasonic advance, and the electronic technology development, especially
as high-power semiconductor device technology matures, the application of ultrasonic
has become increasingly widespread:
i. Ultrasonic measurement of distance, depth and thickness;
ii. Ultrasonic testing;
iii. Ultrasound imaging;
iv. Ultrasonic machining, such as polishing, drilling;
v. Ultrasonic cleaning;
vi. Ultrasonic welding;
PROCEDURE
PART A
1. Open the Proteus software, select the following part from library
a. Arduino Uno R3
b. LM016L, 16x2 LCD display
c. SRF04, ultrasonic sensor
2. Create new project, use naming profile as PW5_X, with X indicate your
group number.
3. Drag all component into schematic layout, and use your own creativity
for component arrangement and pin connection. Use below schematic
diagram for guideline.
4. Save your project.
49
PART B
1. Open the Arduino editor.
2. Write the following code and save it using the same naming profile as before.
NewPing sonar (TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum
//distance. Built-in function wihtin newping library
LiquidCrystal lcd ( 12, 13, 8, 9, 10, 11); // for lcd display. Initialize the library with the numbers of
//the interface pins
void loop ( ) {
delay (50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest
//delay between pings
// (note: line 1 is the second row, since counting begins with 0):
[Link] (0, 1); // set the cursor to column 0, line 1
3. Compile the code and find the hex file location. If any error occurs, solve the error
until it fixes.
50
PART C
1. Double click the Arduino Uno R3 component in Proteus to invoke the ‘Edit
Component’ window. On part ‘Program Files’, point it to your hex file location on
PART B, then click ‘OK’.
2. On the lower left side of your schematic layout, click the play button to start the
simulation. Observe the output.
//ultrasonic sensor & actuator/motor control using L298 (dual full-bridge motor drivers)
//
//Example NewPing library sketch that does ping about 20 times per second and lcd display
//library
//
#include <NewPing.h> //ultrasonic library
#include<LiquidCrystal.h> //lcd display library
void setup () {
//set up the LCD's number of columns and rows:
51
[Link] (16, 2);
//Print a message to the LCD.
[Link] ("Ultrasonic Sensor");
}
void loop () {
delay (50); //Wait 50ms between pings (about 20pings/sec). 29ms should be the shortest
//delay between pings
// set the cursor to column 0, line 1
//(note:line1is the second row, since counting begins with 0):
[Link] (0, 1);
[Link] ("Ping: ");
[Link] (sonar.ping_cm());
// Send ping, get distance in cm and print result (0=outside set distance range)
[Link] ("cm");
}
52
PRACTICAL TASK 6
LEARNING OBJECTIVES:
Students will be able to;
1. Complete the hardware installation of Land Mobile Robot (LMR) using DC motors
and Bluetooth module.
2. Perform an application of Robot Sumo using LMR and Bluetooth module.
3. Organizes a Robot Sumo Competition.
EQUIPMENTS / COMPONENTS:
1. ARDUINO UNO Board
2. DC motors with L298 (Dual full-bridge driver)
3. HC-SR04 ultrasonic sensor
4. Differential drive mobile robot
PROCEDURE
1. With help from the previous practical work, built an obstacle avoidance
differential drive mobile robot.
2. Student must use ultrasonic sensor as the detector for obstacle.
3. Set the limit range of 15 cm between mobile robot and obstacle. Mobile robot will
turn right about 90 degrees before moving straight again.
4. Upload your code into mobile robot and observe the output.
HINTS
1. Use every knowledge from previous practical work.
2. Divide your code into smaller section (create user define function) for more
convenient and easy to troubleshoot.
3. Optimize the use of built-in delay function to make the mobile robot turn
approximately 90 degrees.
4. There is no right or wrong in programming IF you can achieve your objective, the
difference is only about efficiency, optimization and how you manage your
resource.
53
QUESTIONS & ANSWER
Suggest how to make the mobile robot to move smoothly. Describe your solution in detail.
void setup() {
void loop(){
if([Link]() > 0)
state = [Link]();
if(state=='A')
forward();
if(state=='B')
reverse();
if(state=='C')
turnLeft();
if(state=='D')
turnRight();
if(state=='E')
stopRobot();
if(state=='F')
spinCW();
if(state=='G')
spinCCW();
}
54
void forward()
{
[Link]("Forward");
analogWrite(EN1, 255); // Run in full speed
analogWrite(EN2, 255); // Run in full speed
digitalWrite(IN1, HIGH); // right motor forward
digitalWrite(IN2, LOW); //
digitalWrite(IN3, LOW); // left motor forward
digitalWrite(IN4, HIGH); //
}
void reverse()
{
[Link]("reverse");
analogWrite(EN1, 255); // Run in full speed
analogWrite(EN2, 255); // Run in full speed
digitalWrite(IN1, LOW); // right motor reverse
digitalWrite(IN2, HIGH); //
digitalWrite(IN3, HIGH); // left motor reverse
digitalWrite(IN4, LOW); //
void turnLeft()
{
[Link]("Turn Left");
analogWrite(EN1, 255); // Run in full speed
analogWrite(EN2, 255); // Run in full speed
digitalWrite(IN1, HIGH); // right motor forward
digitalWrite(IN2, LOW); //
digitalWrite(IN3, LOW); // left motor stop
digitalWrite(IN4, LOW); //
void turnRight()
{
[Link]("Turn Right");
analogWrite(EN1, 255); // Run in full speed
analogWrite(EN2, 255); // Run in full speed
digitalWrite(IN1, LOW); // right motor stop
digitalWrite(IN2, LOW); //
digitalWrite(IN3, LOW); // left motor forward
digitalWrite(IN4, HIGH); //
void stopRobot()
{
[Link]("stop");
analogWrite(EN1, 255); // Run in full speed
analogWrite(EN2, 255); // Run in full speed
digitalWrite(IN1, LOW); // right motor stop
digitalWrite(IN2, LOW); //
55
digitalWrite(IN3, LOW); // left motor stop
digitalWrite(IN4, LOW); //
void spinCW()
{
[Link]("spinCW");
analogWrite(EN1, 255); // Run in full speed
analogWrite(EN2, 255); // Run in full speed
digitalWrite(IN1, HIGH); // right motor reverse
digitalWrite(IN2, LOW); //
digitalWrite(IN3, LOW); // left motor forward
digitalWrite(IN4, HIGH); //
}
void spinCCW()
{
[Link]("spinCCW");
analogWrite(EN1, 255); // Run in full speed
analogWrite(EN2, 255); // Run in full speed
digitalWrite(IN1, LOW); // right motor forward
digitalWrite(IN2, HIGH); //
digitalWrite(IN3, HIGH); // left motor reverse
digitalWrite(IN4, LOW); //
}
56
REFERENCES
57