KEMBAR78
User Guide | PDF | Arduino | Servomechanism
0% found this document useful (0 votes)
12 views35 pages

User Guide

SunRobotics Technologies offers a Master Level kit for Arduino, aimed at providing hardware support and software services for makers and electronic enthusiasts. The kit includes various components and lessons to help users understand Arduino and create projects like line-following and obstacle-avoiding robots. The document details the installation of the Arduino IDE, the features of the Arduino Uno R3 board, and the components needed for building a line-following robot.

Uploaded by

rakesh8singh10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views35 pages

User Guide

SunRobotics Technologies offers a Master Level kit for Arduino, aimed at providing hardware support and software services for makers and electronic enthusiasts. The kit includes various components and lessons to help users understand Arduino and create projects like line-following and obstacle-avoiding robots. The document details the installation of the Arduino IDE, the features of the Arduino Uno R3 board, and the components needed for building a line-following robot.

Uploaded by

rakesh8singh10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

SunRobotics Technologies

C-301, Sumel Business Park 6, Dudheshwar Road, Shahibaug


Ahmedabad, 380004, Gujarat, India
Ph no: 9558827732: support@sunrobotics.in

Preface
Sun Robotics is a technical service team of open source software and hardware.Dedicated to applying
the Internet and the latest industrial technology in open source area, we strive to provide best hardware
support and software service for general makers and electronic enthusiasts around the world. We aim
to create infinite possibilities with sharing. No matter what field you are in, we can lead you into the
electronic world and bring your ideas into reality.

This is Master Level kit for Arduino. Some common electronic components and sensors are included.
Through the learning, you will get a better understanding of Arduino, and be able to make fascinating
works based on Arduino.
Contents
 Getting Started with Arduino
 Installing Arduino IDE and using the Uno R3 board
 About Arduino Uno R3 board
 Lesson- 1 Line Following Robot
 Lesson- 2 Obstacle Avoiding Robot
 Lesson- 3 Obstacle Detecting Robot Using IR Sensor
 Lesson- 4 Bluetooth Operated Robot

Web: www.sunrobotics.in
1
Email:support@sunrobotics.in
Getting Started with Arduino
What is an Arduino?

Arduino is an open-source physical computing platform designed to make experimenting with


electronics more fun and intuitive. Arduino has its own unique, simplified programming language, a vast
support network, and thousands of potential uses, making it the perfect platform for both beginner and
advanced DIY enthusiasts. www.arduino.cc

A Computer for the Physical World:

The friendly blue board in your hand (or on your desk) is the Arduino. In some ways you could think of
Arduino as the child of traditional desktop and laptop computers. At its roots, the Arduino is essentially
a small portable computer. It is capable of taking inputs (such as the push of a button or a reading from
a light sensor) and interpreting that information to control various outputs (like a blinking LED light or
an electric motor). That's where the term "physical computing" is born - an Arduino is capable of taking
the world of electronics and relating it to the physical world in a real and tangible way. Trust us - this will
all make more sense soon.

Arduino UNO SMD R3

The Arduino Uno is one of several development boards based on the ATmega328. We like it
mainly because of its extensive support network and its versatility. It has 14 digital input/output pins (6
of which can be PWM outputs), 6 analog inputs, a 16 MHz crystal oscillator, a USB connection, a power
jack, an ICSP header, and a reset button. Don’t worry, you’ll learn about all these later.

Installing Arduino IDE and Using Uno R3 board

STEP-1: Download the Arduino IDE (Integrated Development Environment)

Access the Internet:


In order to get your Arduino up and running, you'll need to download some software first from
www.arduino.cc (it's free!). This software, known as the Arduino IDE, will allow you to program the
Arduino to do exactly what you want. It’s like a word processor for writing programs. With an internet-
capable computer, open up your favorite browser and type in the following URL into the address bar:

www.arduino.cc/en/Main/Software

Web: www.sunrobotics.in
2
Email:support@sunrobotics.in
For different operating system platforms, the way of using Arduino IDE is different. Please refer to the following
links: Windows User:http://www.arduino.cc/en/Guide/Windows MacOSX
User:http://www.arduino.cc/en/Guide/MacOSX Linux
User:http://playground.arduino.cc/Learning/Linux For more detailed information about
Arduino IDE, please refer to the following link: http://www.arduino.cc/en/Guide/HomePage

Web: www.sunrobotics.in
3
Email:support@sunrobotics.in
STEP-2: Connect your Arduino Uno to your Computer:

Use the USB cable provided in the kit to connect the Arduino to one of your computer’s USB inputs.

STEP-3: Install Drivers

Depending on your computer’s operating system, you will need to follow specific instructions. Please go
to the URLs below for specific instructions on how to install the drivers onto your Arduino Uno.
Windows Installation Process:
Go to the web address below to access the instructions for installations on a Windows-based computer.

http://arduino.cc/en/Guide/Windows

Macintosh OS X Installation Process:


Macs do not require you to install drivers. Enter the following URL if you have questions.
Otherwise proceed to next page.

http://arduino.cc/en/Guide/MacOSX
Linux: 32 bit / 64 bit, Installation Process Go to the web address below to access the instructions for
installations on a Linux-based computer.

http://www.arduino.cc/playground/Learning/Linux

STEP-4: Open the Arduino IDE


Open the Arduino IDE software on your computer. Poke around and get to know the interface. We aren’t
going to code right away, this is just an introduction. The step is to set your IDE to identify your Arduino
Uno.

Web: www.sunrobotics.in
4
Email:support@sunrobotics.in
GUI (Graphical User Interface)
Verify
Checks your code for errors compiling it.
Upload
Compiles your code and uploads it to the configured board. See uploading below for
Details .Note: If you are using an external programmer with your board, you can hold
Down the "shift" key on your computer when using this icon. The text will change to
"Upload using Programmer" New Creates a new sketch.
Open
Presents a menu of all the sketches in your sketchbook. Clicking one will open it within
The current window overwriting its content. Note: due to a bug in Java, this menu
Doesn’t scroll; if you need to open a sketch late in the list, use the File | Sketch book
Menu instead.
Save
Saves your sketch.
Serial Monitor
Opens the serial monitor.

Web: www.sunrobotics.in
5
Email:support@sunrobotics.in
STEP-5: Select your board: Arduino Uno

STEP-6: Select your Serial Device

Windows: Select the serial device of the Arduino board from the Tools | Serial Port menu. This is
likely to be com3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To
find out, you can disconnect your Arduino board and re-open the menu; the entry that disappears
should be the Arduino board. Reconnect the board and select that serial port.

Web: www.sunrobotics.in
6
Email:support@sunrobotics.in
Mac OS: Select the serial device of the Arduino board from the Tools > Serial Port menu. On
the Mac, this should be something with /dev/tty.usbmodem (for the Uno or Mega 2560) or
/dev/tty.usbserial (for older boards) in it.
Linux: http://playground.arduino.cc/Learning/Linux

About Arduino Uno R3 board


What's on the board?
There are many varieties of Arduino boards that can be used for different purposes. Some
boards look a bit different from the one below, but most Arduino have the majority of these
components in common:

Power (USB / Barrel Jack)


Every Arduino board needs a way to be connected to a power source. The Arduino UNO can
be powered from a USB cable coming from your computer or a wall power supply that is
terminated in a barrel jack. In the picture above the USB connection is labeled (1) and the
barrel jack is labeled (2).

NOTE: Do NOT use a power supply greater than 20 Volts as you will overpower (and thereby
destroy) your Arduino. The recommended voltage for most Arduino models is between 6 and
12 Volts.
Pins (5V, 3.3V, GND, Analog, Digital, PWM, AREF)

The pins on your Arduino are the places where you connect wires to construct a circuit
(probably in conjuction with a breadboard and some wire. They usually have black plastic
‘headers’ that allow you to just plug a wire right into the board. The Arduino has several
different kinds of pins, each of which is labeled on the board and used for different functions.

 GND (3): Short for ‘Ground’. There are several GND pins on the Arduino, any of which can
be used to ground your circuit.
 5V (4) & 3.3V (5): As you might guess, the 5V pin supplies 5 volts of power, and the 3.3V
pin supplies 3.3 volts of power. Most of the simple components used with the Arduino
run happily off of 5 or 3.3 volts.
Web: www.sunrobotics.in
7
Email:support@sunrobotics.in
 Analog (6): The area of pins under the ‘Analog In’ label (A0 through A5 on the UNO) are
Analog In pins. These pins can read the signal from an analog sensor (like a
temperature sensor) and convert it into a digital value that we can read.
 Digital (7): Across from the analog pins are the digital pins (0 through 13 on the UNO).
These pins can be used for both digital input (like telling if a button is pushed) and
digital output (like powering an LED).
 PWM (8): You may have noticed the tilde (~) next to some of the digital pins (3, 5, 6, 9, 10,
and 11 on the UNO). These pins act as normal digital pins, but can also be used for
something called Pulse-Width Modulation (PWM). We have a tutorial on PWM, but
for now, think of these pins as being able to simulate analog output (like fading an LED
in and out).
 AREF (9): Stands for Analog Reference. Most of the time you can leave this pin alone. It is
sometimes used to set an external reference voltage (between 0 and 5 Volts) as the
upper limit for the analog input pins.

Reset Button
Just like the original Nintendo, the Arduino has a reset button (10). Pushing it will temporarily
connect the reset pin to ground and restart any code that is loaded on the Arduino. This can
be very useful if your code doesn’t repeat, but you want to test it multiple times. Unlike the
original Nintendo however, blowing on the Arduino doesn’t usually fix any problems.

Power LED Indicator


Just beneath and to the right of the word “UNO” on your circuit board, there’s a tiny LED next
to the word ‘ON’ (11). This LED should light up whenever you plug your Arduino into a power
source. If this light doesn’t turn on, there’s a good chance something is wrong. Time to re-
check your circuit!

TX RX LEDs
TX is short for transmit, RX is short for receive. These markings appear quite a bit in electronics
to indicate the pins responsible for serial communication. In our case, there are two places
on the Arduino UNO where TX and RX appear – once by digital pins 0 and 1, and a second
time next to the TX and RX indicator LEDs (12). These LEDs will give us some nice visual
indications whenever our Arduino is receiving or transmitting data (like when we’re loading a
new program onto the board).

Main IC
The black thing with all the metal legs is an IC, or Integrated Circuit (13). Think of it as the
brains of our Arduino. The main IC on the Arduino is slightly different from board type to
board type, but is usually from the ATmega line of IC’s from the ATMEL company. This can be
important, as you may need to know the IC type (along with your board type) before loading
up a new program from the Arduino software. This information can usually be found in writing
on the top side of the IC. If you want to know more about the difference between various IC’s,
reading the datasheets is often a good idea.

Voltage Regulator
The voltage regulator (14) is not actually something you can (or should) interact with on the

Web: www.sunrobotics.in
8
Email:support@sunrobotics.in
Arduino. But it is potentially useful to know that it is there and what it’s for. The voltage
regulator does exactly what it says – it controls the amount of voltage that is let into the
Arduino board. Think of it as a kind of gatekeeper; it will turn away an extra voltage that might
harm the circuit. Of course, it has its limits, so don’t hook up your Arduino to anything greater
than 20 volts.

Web: www.sunrobotics.in
9
Email:support@sunrobotics.in
Lesson 1 – Line Following Robot
Introduction:
The IR line tracking sensor consists of analog to digital and comparator module and 5 IR Line
Array Sensor Breakout Board. The IR light emitted by the LED strikes the surface and is
reflected back to the IR photodiode. The photodiode then gives an output voltage
proportional to the reflectance of the surface (high value for light surface and low for
black/dark surface).

This line follower robot are pretty straight forward. These robots have the capability to detect
a black/dark line on a lighter surface depending on the contrast. They estimate whether the
line underneath them is shifting towards their left/right as they move over them. Based on
that estimation, they give respective signals to the motors to turn left/right so as to maintain
a steady centre with respect to the line.

These robots usually use an array of IR (Infrared) sensors in order to calculate the reflectance
of the surface beneath them. The basic criteria being that the black line will have a lesser
reflectance value (black absorbs light) than the lighter surface around it. This low value of
reflectance is the parameter used to detect the position of the line by the robot. The higher
value of reflectance will be the surface around the line. So in this linear array of IR sensors, if
the leftmost/rightmost IR sensor presents the low value for reflectance, then the black line is
towards the left/right of the robot correspondingly. The controller then compensates for this
by signalling the motor to go in the opposite direction of the line.

Components:

 1 X Arduino Uno

 1 X 5 IR Line Array Sensor

 1 X USB cable

 1 X Arduino Motor Shield

 1 X Battery For Power Supply

 Jumper Wires
Web: www.sunrobotics.in
10
Email:support@sunrobotics.in
Description:
5 IR Line Array Sensor:

This is a Five IR Sensor Array with Obstacle and Bump Sensor. A 5 IR sensor use with TCRT5000
have a compact construction where the emitting-light source and the detector are arranged
in the same direction to sense the presence of an object by using the reflective IR-beam from
the object. The operating wavelength is app. 5 cm. The detector consists of a phototransistor.
There are 5 sensors connected in an array to form a TCRT 5000 Sensor Module which can be
used effectively in different robotic applications such as, Line following robot, Shaft encoder,
and Obstacle avoidance use.

Five IR Sensor Array is one of the best sensors for line follower robot. It have five IR sensor
facing down, One IR sensor and a bump sensor (Limit Switch) facing toward front. IR sensors
are covered with casing for better precision. Sensor has mounting holes for easy fitting on
almost any project.

Arduino Motor Shield:

The Arduino Motor Shield allows your arduino to drive DC and stepper motors, relays and
solenoids. The Arduino Motor Shield is based on the L298 (datasheet), which is a dual full-
bridge driver designed to drive inductive loads such as relays, solenoids, DC and stepping
motors.

L293D shield is a driver board based on L293 IC, which can drive 4 DC motors and 2 stepper
or Servo motors at the same time.

Web: www.sunrobotics.in
11
Email:support@sunrobotics.in
Each channel of this module has the maximum current of 1.2A and doesn’t work if the voltage
is more than 25v or less than 4.5v. So be careful with choosing the proper motor according to
its nominal voltage and current. For more features of this shield let’s mention compatibility
with Arduini UNO and MEGA, electromagnetic and thermal protection of motor and
disconnecting circuit in case of unconventional voltage raise.

Arduino Motor Shield

Schematic:

Web: www.sunrobotics.in
12
Email:support@sunrobotics.in
Code:

#include <AFMotor.h>

//**********5 Channel IR Sensor Connection**********//


#define ir1 A1
#define ir2 A2
#define ir3 A3
#define ir4 A4
#define ir5 A5

//defining motors
AF_DCMotor motor1(4); // RIGHT SIDE MOTOR
AF_DCMotor motor2(3); // LEFT SIDE MOTOR

void setup() {
//setting the speed of motors
motor1.setSpeed(90);
motor2.setSpeed(90);

pinMode(ir1, INPUT);
pinMode(ir2, INPUT);
pinMode(ir3, INPUT);
pinMode(ir4, INPUT);
pinMode(ir5, INPUT);
Serial.begin(9600);
}
void loop() {
//Reading Sensor Values
int s1 = digitalRead(ir1); //Left Most Sensor
int s2 = digitalRead(ir2); //Left Sensor
int s3 = digitalRead(ir3); //Middle Sensor
int s4 = digitalRead(ir4); //Right Sensor
int s5 = digitalRead(ir5); //Right Most Sensor

//if only middle sensor detects black line


if ((s1 == 1) && (s2 == 1) && (s3 == 0) && (s4 == 1) && (s5 == 1))
{
//going forward with full speed
motor1.run(FORWARD);
motor2.run(FORWARD);
Serial.println("s3=1");
}

Web: www.sunrobotics.in
13
Email:support@sunrobotics.in
//if only left sensor detects black line
if ((s1 == 1) && (s2 == 0) && (s3 == 1) && (s4 == 1) && (s5 == 1))
{
//going right with full speed
motor1.run(FORWARD);
motor2.run(RELEASE);
Serial.println("s2=1");
}

//if only left most sensor detects black line


if ((s1 == 0) && (s2 == 1) && (s3 == 1) && (s4 == 1) && (s5 == 1))
{
//going right with full speed
motor1.run(FORWARD);
motor2.run(BACKWARD);
Serial.println("s1=1");
}

//if only right sensor detects black line


if ((s1 == 1) && (s2 == 1) && (s3 == 1) && (s4 == 0) && (s5 == 1))
{
//going left with full speed
motor1.run(RELEASE);
motor2.run(FORWARD);
Serial.println("s4=1");
}

//if only right most sensor detects black line


if ((s1 == 1) && (s2 == 1) && (s3 == 1) && (s4 == 1) && (s5 == 0))
{
//going left with full speed
motor1.run(BACKWARD);
motor2.run(FORWARD);
Serial.println("s5=1");
}

//if middle and right sensor detects black line


if ((s1 == 1) && (s2 == 1) && (s3 == 0) && (s4 == 0) && (s5 == 1))
{
//going left with full speed
motor1.run(RELEASE);
motor2.run(FORWARD);
}

Web: www.sunrobotics.in
14
Email:support@sunrobotics.in
//if middle and left sensor detects black line
if ((s1 == 1) && (s2 == 0) && (s3 == 0) && (s4 == 1) && (s5 == 1))
{
//going right with full speed
motor1.run(FORWARD);
motor2.run(RELEASE);
}

//if middle, left and left most sensor detects black line
if ((s1 == 0) && (s2 == 0) && (s3 == 0) && (s4 == 1) && (s5 == 1))
{
//going right with full speed
motor1.run(FORWARD);
motor2.run(RELEASE);
}

//if middle, right and right most sensor detects black line
if ((s1 == 1) && (s2 == 1) && (s3 == 0) && (s4 == 0) && (s5 == 0
))
{
//going left with full speed
motor1.run(RELEASE);
motor2.run(FORWARD);
}

//if all sensors are on a black line


if ((s1 == 1) && (s2 == 1) && (s3 == 1) && (s4 == 1) && (s5 == 1))
{
//stop
motor1.run(RELEASE);
motor2.run(RELEASE);
}
}

Compile the program and upload to Arduino UNO board

Web: www.sunrobotics.in
15
Email:support@sunrobotics.in
Lesson 2 – Obstacle Avoiding Robot
Introduction:

The obstacle avoiding robot will be able to avoid every obstacle in its path. It will use an
ultrasonic distance sensor and a servo motor in addition to the basic robot. The robot will
check how far the nearest obstacle is (in every direction) and then decide upon the actions to
be taken. The servo controls the direction in which the distance sensor faces and if the robot
is hindered by an obstacle, the servo will rotate the sensor in different directions. Once the
robot is convinced that a certain direction is clear of any obstacles, it will turn the robot in
that particular direction and then move in a straight line along that direction till the next
obstacle is found. If there is no way to go ahead the robot executes a full 180° turn.

Components:

 1 X Arduino UNO
 1 X Ultrasonic Sensor( HC-SR04)
 1 X Servo Motor
 1 X Arduino Motor Shield
 1 X Battery For Power Supply
 1 X USB cable
 Jumper Wires

Description:
Ultrasonic Sensor( HC-SR04):

Before going to build the robot, it is important to understand how the ultrasonic sensor works
because this sensor will have important role in detecting obstacle. The basic principle behind
the working of ultrasonic sensor is to note down the time taken by sensor to transmit
ultrasonic beams and receiving the ultrasonic beams after hitting the surface. Then further
the distance is calculated using the formula. In this project, the widely available HC-SR04
Ultrasonic Sensor is used. To use this sensor, similar approach will be followed explained
above.

Web: www.sunrobotics.in
16
Email:support@sunrobotics.in
So, the Trig pin of HC-SR04 is made high for at least 10 us. A sonic beam is transmitted with 8
pulses of 40KHz each.

The signal then hits the surface and return back and captured by the receiver Echo pin of HC-
SR04. The Echo pin had already made high at the time sending high.

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.

Web: www.sunrobotics.in
17
Email:support@sunrobotics.in
Usually a servomotor turns 90 degree in either direction hence maximum movement can be
180 degree. However a normal servo motor cannot rotate any further to a build in mechanical
stop.

We take three wires are out of a servo: positive, ground and control wire. A servo motor is
control by sending a pulse width modulated (PWM) signal through the control wire. A pulse
is sent every 20 milliseconds. Width of the pulses determine the position of the shaft.

Schematic:

Working:
Before going to working of the project, it is important to understand how the ultrasonic sensor
works. The basic principle behind the working of ultrasonic sensor is as follows:

Using an external trigger signal, the Trig pin on ultrasonic sensor is made logic high for at least
10µs. A sonic burst from the transmitter module is sent. This consists of 8 pulses of 40KHz.

Web: www.sunrobotics.in
18
Email:support@sunrobotics.in
The signals return back after hitting a surface and the receiver detects this signal. The Echo
pin is high from the time of sending the signal and receiving it. This time can be converted to
distance using appropriate calculations.

The aim of this project is to implement an obstacle avoiding robot using ultrasonic sensor and
Arduino. All the connections are made as per the circuit diagram. The working of the project
is explained below.

When the robot is powered on, both the motors of the robot will run normally and the robot
moves forward. During this time, the ultrasonic sensor continuously calculate the distance
between the robot and the reflective surface.

This information is processed by the Arduino. If the distance between the robot and the
obstacle is less than 15cm, the Robot stops and scans in left and right directions for new
distance using Servo Motor and Ultrasonic Sensor. If the distance towards the left side is more
than that of the right side, the robot will prepare for a left turn. But first, it backs up a little
bit and then activates the Left Wheel Motor in reversed in direction.

Similarly, if the right distance is more than that of the left distance, the Robot prepares right
rotation. This process continues forever and the robot keeps on moving without hitting any
obstacle.

Code:
#include <AFMotor.h>
#include <NewPing.h>
#include <Servo.h>

#define TRIG_PIN A4
#define ECHO_PIN A5
#define MAX_DISTANCE 200
#define MAX_SPEED 190 // sets speed of DC motors
#define MAX_SPEED_OFFSET 20

NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);

AF_DCMotor motor1(1, MOTOR12_1KHZ); // Left Side Motor


AF_DCMotor motor2(3, MOTOR12_1KHZ); // Right Side Motor

Servo myservo;

boolean goesForward=false;
int distance = 100;

Web: www.sunrobotics.in
19
Email:support@sunrobotics.in
int speedSet = 0;

void setup() {

myservo.attach(9);
myservo.write(115);
delay(2000);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
}

void loop() {
int distanceR = 0;
int distanceL = 0;
delay(40);

if(distance<=15)
{
moveStop();
delay(100);
moveBackward();
delay(300);
moveStop();
delay(200);
distanceR = lookRight();
delay(200);
distanceL = lookLeft();
delay(200);

if(distanceR>=distanceL)
{
turnRight();
moveStop();
}else

Web: www.sunrobotics.in
20
Email:support@sunrobotics.in
{
turnLeft();
moveStop();
}
}else
{
moveForward();
}
distance = readPing();
}

int lookRight()
{
myservo.write(50);
delay(500);
int distance = readPing();
delay(100);
myservo.write(115);
return distance;
}

int lookLeft()
{
myservo.write(170);
delay(500);
int distance = readPing();
delay(100);
myservo.write(115);
return distance;
delay(100);
}

int readPing() {
delay(70);
int cm = sonar.ping_cm();
if(cm==0)
{
cm = 250;
}
return cm;

Web: www.sunrobotics.in
21
Email:support@sunrobotics.in
}

void moveStop() {
motor1.run(RELEASE);
motor2.run(RELEASE);
}

void moveForward() {

if(!goesForward)
{
goesForward=true;
motor1.run(FORWARD);
motor2.run(FORWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly bring the speed up to
avoid loading down the batteries too quickly
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet+MAX_SPEED_OFFSET);
delay(5);
}
}
}

void moveBackward() {
goesForward=false;
motor1.run(BACKWARD);
motor2.run(BACKWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet +=2) // slowly bring the speed up to
avoid loading down the batteries too quickly
{
motor1.setSpeed(speedSet);
motor2.setSpeed(speedSet+MAX_SPEED_OFFSET);
delay(5);
}
}

void turnRight() {
motor1.run(FORWARD);
motor2.run(BACKWARD);

Web: www.sunrobotics.in
22
Email:support@sunrobotics.in
delay(300);
motor1.run(FORWARD);
motor2.run(FORWARD);
}

void turnLeft() {
motor1.run(BACKWARD);
motor2.run(FORWARD);
delay(300);
motor1.run(FORWARD);
motor2.run(FORWARD);
}

Compile the program and upload to Arduino UNO board

Web: www.sunrobotics.in
23
Email:support@sunrobotics.in
Lesson 3 – Obstacle Avoiding Using IR Sensor

Introduction:

We will learn to build an obstacle avoiding bot based on Infra-Red sensors. The primary
purpose of this bot is to traverse forward autonomously and change directions if it encounters
any significant obstacle in its path. The bot will avoid any obstacle big enough to be detected
by the Infra-Red sensor mounted on the front.
The developed robot will move in a particular direction once the infrared (IR) sensor sense a
signal while avoiding the obstacles in its path. The robot can also perform desired tasks in
unstructured environments without continuous human guidance.

Components:
 1 X Arduino Uno
 1 X Arduino Motor shield
 1 X USB cable
 2 X IR Sensors
 1 X Battery For Power Supply
 Jumper Wires

Description:

IR Sensor:

Web: www.sunrobotics.in
24
Email:support@sunrobotics.in
Pin Configuration

Pin Name Description

VCC Power Supply Input

GND Power Supply Ground

OUT Active High Output

IR Sensor Module Features


 5VDC Operating voltage
 I/O pins are 5V and 3.3V compliant
 Range: Up to 20cm
 Adjustable Sensing range
 Built-in Ambient Light Sensor
 20mA supply current
 Mounting hole

IR LED Transmitter

IR LED emits light, in the range of Infrared frequency. IR light is invisible to us as its wavelength
(700nm – 1mm) is much higher than the visible light range. IR LEDs have light emitting angle
of approx. 20-60 degree and range of approx. few centimeters to several feets, it depends
upon the type of IR transmitter and the manufacturer. Some transmitters have the range in
kilometers. IR LED white or transparent in colour, so it can give out amount of maximum light.

Photodiode Receiver

Photodiode acts as the IR receiver as its conducts when light falls on it. Photodiode is a
semiconductor which has a P-N junction, operated in Reverse Bias, means it start conducting
the current in reverse direction when Light falls on it, and the amount of current flow is
proportional to the amount of Light. This property makes it useful for IR detection.
Photodiode looks like a LED, with a black colour coating on its outer side, Black colour absorbs
the highest amount of light.

LM358 Opamp:

LM358 is an Operational Amplifier (Op-Amp) is used as voltage comparator in the IR


sensor.The comparator will compare the threshold voltage set using the preset (pin2) and the

Web: www.sunrobotics.in
25
Email:support@sunrobotics.in
photodiode’s series resistor voltage (pin3).

Photodiode’s series resistor voltage drop > Threshold voltage = Opamp output is High

Photodiode’s series resistor voltage drop < Threshold voltage = Opamp output is Low

When Opamp's output is high the LED at the Opamp output terminal turns ON (Indicating the
detection of Object).

Variable Resistor

The variable resistor used here is a preset. It is used to calibrate the distance range at which
object should be detected.

Schematic:

Code:

#include<AFMotor.h>

AF_DCMotor motor1(1); //left side motor

AF_DCMotor motor2(2); // right side motor

void setup() {

Serial.begin(9600);

motor1.setSpeed(200);

motor2.setSpeed(200);

void loop() {

Web: www.sunrobotics.in
26
Email:support@sunrobotics.in
int sR = analogRead(A0);//Right sensor

int sL = analogRead(A2);//Left sensor

int sM = analogRead(A5);//Middle sensor

if(sR>600 && sL>600 && sM>600)//In the event of no obstacle being detected by any of
the sensors

motor1.run(FORWARD);

motor2.run(FORWARD);

else if(sR<600 && sL>600)//If the right sensor is near an obstacle

motor1.run(BACKWARD);//First move back for 1 second

motor2.run(BACKWARD);

delay(1000);

motor1.run(FORWARD);//Then turn left for 1.5 seconds

motor2.run(RELEASE);

delay(1500);

else if(sR>600 && sL<600)//If the left sensor is near an obstacle

motor1.run(BACKWARD);//First move back for 1 second

motor2.run(BACKWARD);

delay(1000);

motor2.run(FORWARD);//Then turn right for 1.5 seconds

motor1.run(RELEASE);

delay(1500);

else if(sM<600)//If the middle sensor is near an obstacle

Web: www.sunrobotics.in
27
Email:support@sunrobotics.in
{

motor1.run(BACKWARD);//First move back for 2 seconds

motor2.run(BACKWARD);

delay(2000);

motor2.run(FORWARD);//Then turn right(arbitrary,you could go left too)

motor1.run(RELEASE);//For 1.5 seconds

delay(1500);

else//If its none of the above,just move backwards for 2 seconds

motor1.run(BACKWARD);

motor2.run(BACKWARD);

delay(2000);

delay(100);

Compile the program and upload to Arduino UNO board

Web: www.sunrobotics.in
28
Email:support@sunrobotics.in
Lesson 4 – Bluetooth Operated Robot

Introduction:

In this project, we will learn how to make Wireless Bluetooth Controlled Robot Car Using
Arduino. The robotic car can be controlled wirelessly via a Smartphone. The smartphone has
an Android app through which the user can send commands directly to Robot. The robot can
move forward, backward, left and right and can also be stopped.
The Arduino’s Bluetooth controlled robot car is interfaced with a Bluetooth module HC-05 or
HC-06. We can give specific voice commands to the robot through an Android app installed
on the phone. At the receiving side, a Bluetooth transceiver module receives the commands
and forwards them to the Arduino and thus the robotic car is controlled.

Components:

 1 X Arduino Uno
 1 X Arduino motor shield
 1 X USB Cable
 1 X Bluetooth module (HC-05)
 1 X Battery for power supply
 Jumper Wires

Bluetooth Module:

HC Bluetooth module consists two things one is Bluetooth serial interface module and a
Bluetooth adaptor. Bluetooth serial module is used for converting serial port to Bluetooth.

How to operate Bluetooth module?

You can directly use the Bluetooth module after purchasing from market, because there is no
need to change any setting of Bluetooth module. Default baud rate of new Bluetooth module
is 9600 bps. You just need to connect rx and tx to controller or serial converter and give 5 volt
dc regulated power supply to module.
Web: www.sunrobotics.in
29
Email:support@sunrobotics.in
Bluetooth module has two modes one is master mode and second one is slave mode. User
can set either mode by using some AT commands. Even user can set module’s setting by using
AT command. Here is some commands uses are given:
First of all user need to enter AT mode with 38400 bps baud rate by pressing EN button at
Bluetooth module or by giving HIGH level at EN pin.
Note: all commands should ends with \r\n (0x0d and 0x0a) or ENTER KEY from keyboard.
After it if you send AT to module then module will respond with OK.
AT → Test Command
AT+ROLE=0 → Slave Mode select
AT+ROLE=1 → Master Mode select
AT+NAME=xyz → Set Bluetooth Name
AT+PSWD=xyz → Set Password
AT+UART=<value1>, <value2>, <value3> → set Baud rate
Eg. AT+UART=9600

Pin Description of accelerometer


1. STATE → Open
2. Rx → Serial receiving pin
3. Tx → Serial transmitting pin
4. GND → ground
5. Vcc → +5volt dc
6. EN → to enter in AT mode

Block Diagram:
The block diagram of Arduino Wireless Voice Controlled Robot is given below.

The Arduino Wireless Voice Controlled Robot consists of a transmitter and a receiver section.
The transmitter end consists of Smartphone Bluetooth and the Android app installed on it.
Similarly, the Receiver section has Arduino board as a processor, HC-05 Bluetooth Module as
a wireless communication module, L293D for driving motors and pair of DC geared as a part

Web: www.sunrobotics.in
30
Email:support@sunrobotics.in
for moving robot.

Bluetooth controlled car moves according to button touched in the android Bluetooth mobile
app. To run this project first we need to download Bluetooth app form Google play store. We
can use any Bluetooth app that supporting or can send data.

Schematic:

Code:

//*** 1- Documentation
//This program is used to control a robot car using a app that communicates with Arduino trough a
bluetooth module

#include <AFMotor.h>
#include <SoftwareSerial.h>
SoftwareSerial robotBT(A3,A4);//Rx and Tx configured using software robotBT..NOTE->Do not use
A5. It won't work.

//creates two objects to control the terminal 3 and 4 of motor shield


AF_DCMotor motor1(3); //left side motor
AF_DCMotor motor2(4); //right side motor

char command;

void setup()
{
robotBT.begin(9600); //Set the baud rate to your Bluetooth module.
Serial.begin(9600);
}

Web: www.sunrobotics.in
31
Email:support@sunrobotics.in
void loop(){
if(robotBT.available() > 0){
command = robotBT.read();
//Change pin mode only if new command is different from previous.
Serial.println(command);
switch(command){
case 'F':
forward();
break;
case 'B':
backward();
break;
case 'L':
left();
break;
case 'R':
right();
break;
}
}
}

void forward()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor clockwise
}

void backward()
{
motor1.setSpeed(255);
motor1.run(BACKWARD); //rotate the motor counterclockwise
motor2.setSpeed(255);
motor2.run(BACKWARD); //rotate the motor counterclockwise
}

void left()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(0);
motor2.run(RELEASE); //turn motor2 off

Web: www.sunrobotics.in
32
Email:support@sunrobotics.in
}

void right()
{
motor1.setSpeed(0);
motor1.run(RELEASE); //turn motor1 off
motor2.setSpeed(255); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor clockwise
}

void Stop()
{
motor1.setSpeed(0);
motor2.run(RELEASE); //turn motor1 off
motor2.setSpeed(0);
motor2.run(RELEASE); //turn motor2 off
}

Compile the program and upload to Arduino UNO board

Web: www.sunrobotics.in
33
Email:support@sunrobotics.in

You might also like