1. ARDUINO EMBEDDED
SYSTEMS AND ADVANCED
ROBOTICS
A Project Report for the Award of the Degree of B.Tech
In
Electronics and Instrumentation Engineering
At
ACADEMY OF TECHNOLOGY
By
Anirvan Misra Roll: 16900513005
Nilesh Tripathi Roll: 16900513022
Shubham Bhattacharya Roll: 16900513043
Siddhartha Mishra Roll: 16900513044
Training Provided by
Tech Learning Solutions pvt. Ltd.
Technical Support given by
Skubotics
In Association with
MYWBUT (www.mywbut.com)
2. ACKNOWLEDGEMENT
We take this opportunity to express our deep gratitude
and sincerest thank to our project mentor, Tunir Saha
for giving most valuable solution helpful guidance and
encouragement in the execution of this project work.
We will like to give a special mention to our colleagues.
Last but not the least to all the faculty member of Tech
learning solution pvt. Ltd. for the support.
3. CONTENTS
ACKNOWLEDGEMENT
INTRODUCTION
Introduction to Embedded Systems
Introduction to Arduino
Anatomy of Arduino UNO
ATmega-328p
Arduino IDE
INTERFACING WITH ARDUINO UNO
Interfacing LED
Interfacing IR Sensors
Interfacing LDR Sensors
Interfacing Temperature Sensor
Interfacing a DC Motor
AUTONOMOUS ROBOTICS USING ARDUINO
Introduction to Autonomous Robotics
Line Follower Robot
o Circuit Explanation
o Working Principle
o Code
o Project Snapshot
CONCLUSION
4. INTRODUCTION
Introduction to Embedded System:
An embedded system is a computer system with a dedicated function within a larger mechanical or
electrical system, often with real-time computing constraints. It is embedded as part of a complete
device often including hardware and mechanical parts. Embedded systems control many devices in
commonuse today. Ninety-eightpercentof all microprocessors are manufacturedascomponentsof
embedded systems.
Embedded systems range from portable devices such as digital watches and MP3 players, to large
stationary installations like traffic lights,factory controllers, and largely complex systems like hybrid
vehicles, MRI, and avionics. Complexity varies from low, with a single microcontroller chip, to very
high with multiple units, peripherals and networks mounted inside a large chassis or enclosure.
The usesof embeddedsystems are virtuallylimitless,becauseeverydaynew productsare introduced
to the market that utilize embedded computers in novel ways.
In recent years, hardware such as microprocessors, microcontrollers, and FPGA chips have become
much cheaper.
Some examples of embedded systemsinclude ATMs, cell phones, printers, thermostats, calculators,
and videogame consoles. Handheld computers or PDAs are also considered embedded devices
because of the nature of their hardware design,eventhough theyare more expandable in software
terms.
5. Introduction to Arduino:
Arduino is a computer hardware and software company, project, and user community that designs and
manufactures microcontroller kits for building digital devices and interactive objects that can sense and
control objects in the physical world. The project's products are distributed as open-source
hardware and software, which arelicensed under the GNULesser GeneralPublic License (LGPL) or the GNU
General Public License (GPL), permitting the manufacture of Arduino boards and software distribution by
anyone. Arduino boards are available commercially in preassembled form, or as do-it-yourself kits.
Anatomy of Arduino UNO:
Arduino Unois a microcontrollerboardbasedonthe ATmega328P.It has14 digital input/outputpins
(of which6 can be usedasPWMoutputs),6analoginputs,a16 MHz quartz crystal,a USB connection,
a power jack, an ICSP header and a reset button.
It containseverythingneededtosupportthe microcontroller;simplyconnectitto a computerwitha
USB cable or power it with an AC-to-DC adapter or battery to get started.
6. ATmega328p:
The Atmega328p is a very popular microcontroller chip produced by Atmel. It is an 8-bit
microcontroller that has 32K of flash memory, 1K of EEPROM, and 2K of internal SRAM.
The Atmega328 is one of the microcontroller chips that are used with the popular Arduino
Duemilanoveboards.The ArduinoDuemilanove boardcomeswitheither1of 2 microcontrollerchips,
the Atmega168 or the Atmega328. Of these 2, the Atmega328 is the upgraded,more advancedchip.
Unlike the Atmega168 whichhas 16K of flashprogram memoryand 512 bytesof internal SRAM,the
Atmega328 has 32K of flash program memory and 2K of Internal SRAM.
The Atmega328 has 28 pins.
It has 14 digital I/Opins,of which 6 can be usedas PWM outputsand 6 analog inputpins.These I/O
pins account for 20 of the pins.
Pin configuration
7. Arduino IDE:
The open-source ArduinoSoftware (IDE)makesiteasytowrite codeanduploadittothe board.Itruns
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. Programs written using Arduino Software (IDE) are
called sketches. These sketches are written in the text editor and are saved with the file extension
.ino. The editor has features for cutting/pasting and for searching/replacing text. First, the Arduino
compiler/IDE accepts C and C++ as-is. In fact many of the libraries are written in C++. Much of the
underlyingsystem is not object oriented, but it could be. Thus, "The arduino language" is C++ or C.
8. INTERFACING WITH ARDUINO UNO
LED interfacing with Arduino:
To light an external LED, we to build this circuit, where we connect one end of the resistor to the digital pin
correspondent to the LED_BUILTIN constant. Connect the long leg of the LED (the positive leg, called the
anode) to the other end of the resistor. Connect the short leg of the LED (the negative leg, called the
cathode) to the GND. In the diagram below we show an UNO board that has D13 as the LED_BUILTIN
value.The value of the resistor in series with the LED may be of a different value than 220 ohm; the LED will
lit up also with values up to 1K ohm.
Schematic:
9. Code:
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
10. Interfacing Infrared sensor:
Principle of working
The principle of an IR sensor working as an Object Detection Sensor can be explained using the
followingfigure.AnIRsensorconsistsof an IR LED and an IR Photodiode;togethertheyare calledas
Photo – Coupler or Opto – Coupler.
Whenthe IR transmitteremitsradiation,itreachesthe objectandsome of the radiationreflectsback
to the IR receiver.Basedonthe intensityof the receptionbythe IRreceiver,the outputof the sensor
is defined.Itconsistsof an IR LED, a photodiode,apotentiometer,anIC Operational amplifierandan
LED.IR LED emitsinfraredlight.The Photodiode detectsthe infraredlight.AnICOp – Ampisusedas a
voltage comparator.The potentiometerisusedtocalibrate the outputof the sensoraccordingto the
requirement.When the light emitted by the IR LED is incident on the photodiode after hitting an
object, the resistance of the photodiode fallsdown from a huge value. One of the input of the op –
amp is at threshold value set by the potentiometer. The other input to the op-amp is from the
photodiode’sseriesresistor.Whentheincidentradiationismore onthe photodiode,the voltagedrop
across the seriesresistorwillbe high.Inthe IC,both the thresholdvoltage andthe voltage acrossthe
series resistor are compared. If the voltage across the resistor series to photodiode is greater than
that of the threshold voltage, the output of the IC Op – Amp is high. As the output of the IC is
connected to an LED, it lightens up. The threshold voltage can be adjusted by adjusting the
potentiometer depending on the environmental conditions.
It is universal that black color absorbs the entire radiationincident on it and white color reflects the
entire radiationincidentonit.Basedonthisprinciple,the secondpositioningof the sensorcouplecan
be made. The IR LED and the photodiode are placed side by side. When the IR transmitter emits
infrared radiation, since there is no direct line of contact between the transmitter and receiver, the
emitted radiation must reflect back to the photodiode after hitting any object.
11. The surface of the objectcan be dividedintotwotypes:reflective surface andnon-reflective surface.
If the surface of the objectisreflectiveinnaturei.e.itiswhite orotherlightcolor,mostof theradiation
incident on it will get reflected back and reaches the photodiode.Depending on the intensity of the
radiation reflected back, current flows in the photodiode.
If the surface of the object is non-reflective in nature i.e. it is black or other dark color, it absorbs
almostall the radiationincidentonit.Asthere isno reflectedradiation,there isnoradiationincident
on the photodiode andthe resistance of the photodiode remainshigherallowingnocurrentto flow.
This situation is similar to there being no object at all.
Schematic:
12. Code:
//define pins
#define irLedPin 4 // IR Led on this pin
#define irSensorPin 5 // IR sensor on this pin
int irRead(int readPin, int triggerPin); //function prototype
void setup()
{
pinMode(irSensorPin, INPUT);
pinMode(irLedPin, OUTPUT);
Serial.begin(9600);
// prints title with ending line break
Serial.println("Program Starting");
// wait for the long string to be sent
delay(100);
}
void loop()
{
Serial.println(irRead(irSensorPin, irLedPin)); //display the results
delay(10); //wait for the string to be sent
}
13. Interfacing Light Detecting Resistor:
A Light DependentResistor(LDR) or a photoresistoris a device whose resistivityisa functionof the
incident electromagnetic radiation. Hence, they are light sensitive devices.
Theyare alsocalledasphoto conductors,photoconductive cells orsimplyphotocells.Theyare made
up of semiconductor materials having high resistance.
Schematic:
Code:
int sensorPin = A0; // select the input pin for ldr
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600); //sets serial port for communication
}
void loop() {
sensorValue = analogRead(sensorPin); // read the value from the sensor
Serial.println(sensorValue); //prints the values coming from the sensor on the screen
delay(100);
}
14. Interfacing Temperature Sensor:
Temperature sensor is a device which senses variations in temperature across it. LM35 is a basic
temperature sensor that can be used for experimental purpose. It give the readings in centigrade
(degree Celsius) since its output voltage is linearly proportional to temperature.
Schematic:
Code:
float tempC;
int tempPin = 0;
void setup()
{
Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
}
void loop()
{
tempC = analogRead(tempPin); //read the value from the sensor
tempC = (5.0 * tempC * 100.0)/1024.0; //convert the analog data to temperature
Serial.print((byte)tempC); //send the data to the computer
delay(1000); //wait one second before sending new data
}
15. Interfacing DC motor:
There are three input pins for each motor, Input1 (IN1),Input2 (IN2), and Enable1 (EN1) for Motor1
and Input3, Input4, and Enable2 for Motor2.
Since we will be controllingonly one motor in this example,we will connect the Arduino to IN1 (pin
5), IN2 (pin7), andEnable1(pin6) of the L298 IC. Pins5 and 7 are digital,i.e.ON orOFF inputs,while
pin 6 needs a pulse-width modulated (PWM) signal to control the motor speed.
The followingtable showswhichdirectionthe motorwill turn basedon the digital valuesof IN1 and
IN2.
IN1 IN2 Motor Behavior
0 0 BRAKE
1 0 FORWARD
0 1 BACKWARD
1 1 BRAKE
Pin IN1 of the IC L298 is connected to pin 8 of Arduino while IN2 is connected to pin 9. These two
digital pinsof Arduinocontrol the directionof the motor.The EN A pinof IC isconnectedtothe PWM
pin 2 of Arduino. This will control the speed of the motor.
To set the values of Arduino pins 8 and 9, we have used the digitalWrite() function, and to set the
value of pin 2, we have to use the analogWrite() function.
Schematic:
16. Code:
const int pwm = 2 ; //initializing pin 2 as pwm
const int in_1 = 8 ;
const int in_2 = 9 ;
//For providing logic to L298 IC to choose the direction of the DC motor
void setup()
{
pinMode(pwm,OUTPUT) ; //we have to set PWM pin as output
pinMode(in_1,OUTPUT) ; //Logic pins are also set as output
pinMode(in_2,OUTPUT) ;
}
void loop()
{
//For Clock wise motion , in_1 = High , in_2 = Low
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,LOW) ;
analogWrite(pwm,255) ;
/*setting pwm of the motor to 255
we can change the speed of rotaion
by chaning pwm input but we are only
using arduino so we are using higest
value to driver the motor */
delay(3000) ;
//For brake
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,HIGH) ;
delay(1000) ;
18. AUTONOMOUS ROBOTICS USING ARDUINO
Introduction to Autonomous Robotics:
An autonomous robot is a robot that performs behaviors or tasks with a high degree of autonomy,
whichisparticularlydesirableinfieldssuchasspaceflight,householdmaintenance(suchascleaning),
waste water treatment and delivering goods and services.
Some modernfactoryrobotsare "autonomous"withinthe strictconfinesof theirdirectenvironment.
It may not be that every degree of freedom exists in their surroundingenvironment,but the factory
robot's workplace is challenging and can often contain chaotic, unpredicted variables. The exact
orientationandpositionof the nextobjectof workand(inthemore advancedfactories)eventhe type
of object and the required task must be determined. This can vary unpredictably (at least from the
robot's point of view).
One importantareaof roboticsresearch isto enable the robotto cope withitsenvironmentwhether
this be on land, underwater, in the air, underground, or in space.
A fully autonomous robot can:
Gain information about the environment
Work for an extended period without human intervention
Move either all or part of itself throughout its operating environment without human
assistance
Avoid situations that are harmful to people,property, or itself unless those are part of its
design specifications
An autonomous robot may also learn or gain new knowledge like adjusting for new methods of
accomplishing its tasks or adapting to changing surroundings.
Like other machines, autonomous robots still require regular maintenance.
19. Line Follower Robot:
Line followerRobotisa machine whichfollows aline,eitherablack line orwhite line.Basicallythere
are twotypesof line followerrobots:one isblackline followerwhichfollowsblacklineandsecondis
white line followerwhich follows white line. Line follower actually senses the line and run over it.
Concepts of Line Follower:
Conceptof workingof line followerisrelatedto light.We use here the behaviorof lightat black and
white surface.Whenlightfall onawhite surface itisalmostfull reflected andincase of blacksurface
light is completely absorbed. This behavior of light is used in building a line follower robot.
20. In this arduino based line follower robot we have used IR Transmitters and IR receivers alsocalled
photo diodes.
Theyare usedforsendingandreceivinglight.IRtransmitsinfraredlights.Wheninfraredraysfallson
white surface,it’sreflectedbackandcatchedbyphotodiodeswhichgeneratessomevoltagechanges.
When IR light falls on a black surface, light is absorb by the black surface and no rays are reflected
back, thus photo diode does not receive any light or rays.
Here in this line follower robot when sensor senses white surface thenarduino gets 1 as input and
when senses black line arduino gets 0 as input.
Circuit Explanation:
The whole line follower robot can be divided into 3 sections: sensor section, control section and
driver section.
Sensor section:
This section contains IR diodes, potentiometer, Comparator (Op-Amp) and LED’s. Potentiometer is
usedfor settingreference voltage atcomparator’sone terminal andIRsensorsare usedto sense the
line and provide a change in voltage at comparator’s second terminal. Then comparator compares
both voltagesandgeneratesa digital signal at output.Here in thisline followercircuitwe have used
twocomparator for twosensors.LM358 isusedas comparator.LM358 has inbuilttwolow noise Op-
amps.
Control Section:
Arduino Uno is used for controlling whole the process of line follower robot. The outputs of
comparators are connectedto digital pinnumber2 and 3 of arduino.Arduinoreadthese signalsand
send commands to driver circuit to drive line follower.
Driver section:
Driver section consists motor driver and two DC motors. Motor driver is used for driving motors
because arduino does not supply enough voltage and current to motor. So we add a motor driver
circuit to get enough voltage and current for motor. Arduino sends commands to this motor driver
and then it drive motors.
21. Working Principle:
Workingof line followerisveryinteresting.Line followerrobotsensesblacklinebyusingsensorand
then sends the signal to arduino. Then arduino drives the motor according to sensors' output.
Here in thisprojectwe are usingtwoIR sensormodulesnamelyleftsensorandrightsensor.When
both left and right sensor senses white then robot move forward.
22. If left sensor comes on black line then robot turn left side.
If rightsensorsense black line thenrobotturn right side until bothsensorcomesat white surface.
When white surface comes robot starts moving on forward again.
23. If both sensors comes on black line, robot stops.
Sensor Response:
24. There are four conditionsinthisline following robotthat we read by usingarduino.We have used
two sensor namely left sensor and right sensor.
Robot Response Table:
Input Output Movement
Of Robot
Left Sensor Right Sensor Left Motor Right Motor
LS RS LM1 LM2 RM1 RM2
0 0 0 0 0 0 Stop
0 1 1 0 0 0 Turn Right
1 0 0 0 1 0 Turn Left
1 1 1 0 1 0 Forward
Code:
int k1=300;
int k2=300;
int lm1=5;
int lm2=6;
int lspeed=9;
int rm1=7;
int rm2=8;
int rspeed=10;
/*int left=A2;
int right=A5;*/
void setup()
{
Serial.begin(9600);
pinMode(9,OUTPUT);
27. Conclusion
In this project we have studied and implemented a Line Following Robot using Arduino Uno. The
programming and interface of microcontroller has been mastered during the implementation.
The Track Followerrobotisone of the outcomesof implementationof withmicrocontrolleronsingle
board. This robot can be autonomous if it is run by 4 AA batteries.
There are certain advantages of this robot. They are as:
Increased productivity, safety, efficiency, quality of products
Can work in hazardous environments, no need for support
Need no environmental comforts
Have repeatable precision at all times
Can be more accurate than humans
Have many capabilities beyond those of humans
Can process multiple stimuli/tasks simultaneously
.A robot can work without sleep. So it can work 24/7/365
Apart from advantages there are some disadvantages too.
Robotstake the place of manyhumansinplaceslike factories.Sothe peoplehave tofindnew jobsor
be retrained. So a MAJOR disadvantage is that the robots take the place of humans in several
situations.
Another disadvantage is that there is quite a high initial cost for the robot and the software and
equipment that you need to use with the robot