0% found this document useful (0 votes)
12 views34 pages

Robot Programming Techniques Explained

Robot programming involves defining paths and commands for robots to perform tasks, which can be done through online or offline methods. Online programming includes teach pendant and lead-through methods, while offline programming allows for code creation without the robot present. Various programming languages such as C/C++, Python, Java, C#/.NET, and MATLAB are essential for developing robotic applications.

Uploaded by

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

Robot Programming Techniques Explained

Robot programming involves defining paths and commands for robots to perform tasks, which can be done through online or offline methods. Online programming includes teach pendant and lead-through methods, while offline programming allows for code creation without the robot present. Various programming languages such as C/C++, Python, Java, C#/.NET, and MATLAB are essential for developing robotic applications.

Uploaded by

munenejohn07
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

TOPIC 6: ROBOT PROGRAMMING.

 A robot program can be defined as a path in space to be followed by the manipulator, combined
with peripheral actions that support the work cycle. A robot can perform complex tasks under
the control of stored programs, which can be modified at will.
 To program a robot, specific commands are entered into the robot’s controller memory,
and this action may be performed in a number of ways.
 For limited sequence robots programming occurs when limit switches and mechanical
stops are set to control the endpoints of its motions.
 A sequencing device controls the occurrence of the motions, which in turn controls the
movement of the joints that completes the motion cycle.

For practical applications in industry, there are two categories of robot programming:

 Online programming
 Offline programming

Online Robot Programming Methods


This involves stopping the robot from its productive work and switching it to “programming
mode.” Then, you create or update the program while the robot is online.

There are two methods

1. Teach Pendant Programming/walk through

 The teach pendant is the interface between the operator / programmer and the robot,
and the robot is manually driven to the required positions and paths in turn to create
the program. A teach pendant is a device which you plug directly into the robot.
 Using its interface, you move the robot to the desired positions and record each
movement.
 To program the robot, the operator moves it from point-to-point, using the buttons on
the pendant to move it around and save each position individually.
 When the whole program has been learned, the robot can play back the points at full
speed.

Advantages of a Teaching Pendant

 Most traditional industrial robots come with a teach pendant, which makes them
familiar to technicians.
 They allow precise positioning, as the robot can be programmed using numerical
coordinates in world coordinates, robot coordinates, or another coordinate system.
 Teach pendants are great for simple movements, such as painting in a straight line or
over a large flat surface.

Disadvantages of a Teaching Pendant

 Disruptive to the whole system due to robot downtime. The robot must be put into
"teach mode" and all operations using the robot halted until it has been programmed.
 Requires training to learn and program.
 Might be difficult for skilled craftspeople who are unfamiliar with programming.

2. Lead-through or hand-guiding (Demonstration)

 It requires the operator to move the robot arm through the desired motion path during a
teach procedure, thereby entering the program into the controller memory for subsequent
playback.
 Task is ‘taught’ to the robot by manually moving the manipulator through the
required motion cycle, and simultaneously entering the program into the controller
memory for playback.
There are two methods of performing the lead through teach procedure

a) Powered lead through


 Commonly used as the programming method for play back robots with point to point control
 It involves the use of a teach pendant which has toggle switch or contact buttons for controlling
the movement of the manipulator joints.
 Using the toggle switches or buttons the programmer drives the robot arm to the desired
positions in sequence and records the positions in the memory.
 During subsequent playback the robot moves through the sequence of positions under its own
power
b) Manual lead through
 The operator physically grasps the end- of -arm or tools attached to the arm and manually move
through the motion sequence, recording the paths into memory.
 The motions are recorded as a series of closely spaced points.
 During playback, the path is recreated by controlling the actual robot arm through the same
sequence of points

Advantages of Teaching by Demonstration

 Quicker than traditional teach pendants. It removes the need for multiple button
pressing, allowing the operator to simply move the robot to the desired position.
 More intuitive than both traditional teach pendants and offline programming as the task
is programmed in almost the same way a human operator would perform it. This makes
it simple for operators to learn.
 Very good for detailed tasks which would require many lines of code to achieve the
same effect, such as path following and error handling (failed picks for example).

Disadvantages of Teaching by Demonstration

 As with a traditional teach pendant, this method uses the physical robot for
programming. This means that it does not reduce downtime, as much as offline
programming.
 Moving the robot to precise coordinates is not as straightforward as with the other
methods. This is especially true with some joystick-based systems, where there is no
way of entering a numerical value.
 Some systems combine these features by allowing for the entering of exact numerical
coordinates along with positioning-based coordinates.
 Not so good for tasks which are "algorithmic" in nature. For example, if a robot had to
paint a flat surface by moving horizontally along the surface, then move down an inch,
move horizontally in the opposite direction, etc. Moving the robot by hand would be
arduous and inaccurate for such a task.

Offline Programming
This involves creating the robot code without (necessarily) having the robot present. When the
program is ready, you then download it onto the robot and debug it. As a result, the robot can
continue to do productive work while you create the program.

There are two different types of offline programming:

1. Text-based programming

 You write the program offline in a text editor then download it to the robot when it
is ready.
 If you use the manufacturer’s programming language, it is likely that you can access
more of the robot’s functionality using this method. However, it has a disadvantage
that it requires a lot more debugging than other programming methods.

2. Graphical offline programming

 This involves programming the robot as if you were moving the real robot, but really
you are moving a simulation of it.
 When you have finished and debugged the program, you can load it onto the robot.
 If the software is good, this method combines the best of both lead-through and
teach pendant programming, with the added advantages of being an offline method.
Advantages of Offline Programming

 Reduces downtime required for robot programming. Programs are developed offline, so
the robot only must be halted while the new program is being downloaded and tested.
 Offline programming with simulation can be available to visualize the final motion in a
virtual work environment.
 Can be quite intuitive, especially if the robot can be moved around in a 3D CAD
environment with drag and drop techniques.
 Easy to test many different approaches to the same problem, this would be inefficient
for online programming methods

Disadvantages of Offline Programming

 Virtual models will never be able to represent the real world with 100% accuracy.
Programs may still need to be altered after they are applied to the real robot.
 Might take longer overall

Robot Programming Functions


a. World modeling

World modeling is the process used by a robot to determine the position of other objects in its world.
Communication between the robots has enabled cooperative world modeling to be used to determine
team strategy.

b. Path generation

Path generation is a fundamental task for a mobile robot by which it moves in an environment avoiding
obstacles, defects in the floor and generating a safe path. The path generation problem is as old as
mobile robots and is a fundamental problem to the adaptation of artificial intelligence technology
to robotics.

c. Sensing

Robotic sensing mainly gives robots the ability to see, touch, hear and move and uses algorithms that
require environmental feedback.

Sensing enable force control, equipping the robot to place and fit objects precisely.

The force sensing capabilities in advanced force/torque and proximity sensors help to find the right
orientation of the object using the right amount of force.

d. Programming support

To perform a particular action, robots are programmed either by guiding or by off-line programming. Most of
the industrial robots are programmed by guiding a robot from point to point through the phases of an
operation, with each point stored in the robotic control system.

Robot programming environment

 The development environment is a set of processes and tools that are used to develop a source
code or program.
Integrated Development Environment (IDE) is the software development tool used to write,
build, test and debug a program.
 They also provide developers with a common user interface (UI) to develop and debug in
different modes.
 Thus, we need to have the required software setup, i.e., installation on our PC which will be
used to write computer programs, compile, and execute them.
 examples
AVR Studio
 AVR Studio is an Integrated Development Environment (IDE) for writing and debugging
AVR applications in Windows 9x/ME/NT/2000/XP/VISTA environments.
 AVR Studio provides a project management tool, source file editor, simulator,
assembler and front-end for C/C++, programming, emulation and on-chip debugging.
 AVR Studio supports the complete range of ATMEL AVR tools and each release will
always contain the latest updates for both the tools and support of new AVR devices.
 AVR Studio 4 has a modular architecture which allows even more interaction with 3rd
party software vendors.
Atmel Studio
 Is the integrated development platform for developing and debugging all AVR® and
SAM microcontroller applications
 The Atmel Studio 7 IDP gives you a seamless and easy-to-use environment to write,
build and debug your applications written in C/C++ or assembly code.
 It also connects seamlessly to the debuggers, programmers and development kits that
support AVR and SAM devices

 You will need the following setup to start with programming using any programming language.

1. A text editor to create computer programs.


2. A compiler to compile the programs into binary format.
3. An interpreter to execute the programs directly.

Text Editor
A text editor is software that is used to write computer programs. Your Windows machine must have a
Notepad, which can be used to type programs.
You can use this software to type your computer program and save it in a file at any location. You can
download and install other good editors like Notepad++, which is freely available.

Compiler
You write your computer program using your favorite programming language and save it in a text file
called the program file.
The computer cannot understand your program directly given in the text format, so we need to convert
this program in a binary format, which can be understood by the computer.
The conversion from text program to binary file is done by software called Compiler and this process of
conversion from text formatted program to binary format file is called program compilation.
Finally, you can execute binary file to perform the programmed task.
The following flow diagram gives an illustration of the process −
So, if you are going to write your program in any such language, which needs compilation like C, C++,
Java and Pascal, etc., then you will need to install their compilers before you start programming.

Interpreter
We just discussed about compilers and the compilation process. Compilers are required in case you are
going to write your program in a programming language that needs to be compiled into binary format
before its execution.
There are other programming languages such as Python, PHP, and Perl, which do not need any
compilation into binary format, rather an interpreter can be used to read such programs line by line
and execute them directly without any further conversion.

So, to write your programs in PHP, Python, Perl, Ruby, etc., you will need to install their interpreters
before you start programming.

Online Compilation
If you are not able to set up any editor, compiler, or interpreter on your machine,
then [Link] provides a facility to compile and run almost all the programs online with an
ease of a single click.
Programming Activities

Computer programming is the process of designing and building an executable computer program to
accomplish a specific computing result or to perform a specific task.

Programming involves tasks such as:

 Analysis,
 Generating algorithms,
 Profiling algorithms' accuracy
 resource consumption
 The implementation of algorithms in a chosen programming language (commonly referred to
as coding)

Robotic Programming:

To perform a particular action, robots are programmed either by guiding or by off-line programming.
Most of the industrial robots are programmed by guiding a robot from point to point through the
phases of an operation, with each point stored in the robotic control system.
Different Types of Robot Programming Languages

 Robotic software plays a key role in performing complex operations and accurate
functionalities.
 To start programming in robotics, you must start learning various types of languages to make
a robot work.
 There are over 1500 programming languages in the world, which are used to learn and
implement. Here are the top and most popular programming languages in robotics:

1) C/C++

 Choosing to learn C and C++ is the best start for aspiring roboticists as it is a general
purpose programming language that contains imperative, object-oriented and generic
programming features.
 C++ allows interaction with low level hardware, and also real time performance.
 C and C++ are very mature programming languages.
 To ensure the best performance of a robot, it will be better to use C++.
 As the robotics is very dependent on the real time performance, C and C++ are the best
options to the roboticists.

2) Python

Python is the high-level programming language and it plays a key role in building and testing robots.
Python is a good platform to automate, teach, and post-process robot programs.

Many people choose this programming language as we can write script that calculates, records, and
simulates an entire robot program instead of manually teaching every statement to a robot. This
helps to quickly test and visualize solution in simulation as well as refine the program and its logic.

Why Python is the Most Used Programming Language in Robotics?

• When compared to C, C++ and Java, you can write fewer lines of code in Python.
• Learning python is an essential guide to create an autonomous mobile robot using popular
robotic software frameworks.
• This language is used in designing embedded system and it is an integral part of Robot operating
system.
• The major focus of Python is ease of use and less time is required to program such as defining,
and casting variable types.
• When you are required to implement some basic functionality, there are a huge number of free
libraries for it, which means you do not have to ‘reinvent the wheel’.

3) Java

 To perform human-like tasks, robotics systems must be included with functions via
programming languages.
 To enable robots with these functions, Java language can be used as it offers an array of
APIs that are tailor-made to the needs of the robotics realm.
 Command-and-control recognizers, dictation systems, and speech synthesizers can be built
using the Java Speech API and the Java Media Framework can be used to receive and
process visual images.

Why Java is the Most Used Programming Language in Robotics?

 Java contains all the high-level features needed in robotics industry especially when it comes
to artificial intelligence.
 Using Java, you can create highly efficient algorithms for machine learning, search and
neural algorithms, language processing etc.
The Java Virtual Machine interprets the instructions at run-time
 Java enables users to use the same code on many different machines, thanks to the Java
Virtual Machine.
 It provides all the high level features needed to deal with various aspects of robotics.

4) C#/.NET

 C#/.NET is the Microsoft’s proprietary language used to develop applications in Visual


Studio. Examples include Netduino, FEZ Rhino and others).
 It provides aspiring programmers a solid foundation based on which they can branch out to
different fields. C#/.NET is generally used in port and socket level programming.

Why C#/.Net is the Most Used Programming Language in Robotics?

 C#/.NET allows using multiple languages and has horizontal scalability.


NET creates a unified environment that allows robotic developers to create programs in C++,
Java or Virtual Basic
 All tools and IDEs have been pre-tested and are easily available in the Microsoft Developer
Network.
 Language integration is seamless, as you can call methods from C# to [Link]

5) MATLAB

 Technically speaking, MATLAB is not a programming language but it is a tool with which you
can find engineering solutions based on mathematics.
 Robotic developers need to learn MATLAB if they want to analyze data, produce advanced
graphs or implement control systems.
 MATLAB, and its open source relatives, such as Octave, is very popular with some robotic
engineers for analyzing data and developing control systems.

Why MATLAB is the Most Used Programming Language in Robotics?

 MATLAB is highly useful in designing the entire robotic system.


 It is widely used in the robotics industry as it is deeply rooted in the foundation and
development of robots.
 It is a simulation tool whereby you can provide your algorithm or design and it
simulates the result.
 On the other hand, simulation helps engineers to refine the system design and
eliminate errors before developing hardware prototypes.

Example: Modeling and Simulation of Kuka kr6 robot.


Other high level computer programming languages

Wave

 Wave was the first high-level language created for programming a robot.
 Standford Artificial Laboratory developed it in 1973.
AL

 The AL (Arm Language) high-level programming language was developed at the


robotics research center of Stanford University.
ACL

 The Advanced Command Language (ACL) is a robot language that employs a


user-friendly conversational command environment. Yaskaua robots use it.
AML

 AML is the programming language used for the control of robots produced by
IBM.
 AML is intended to provide a complete interpreted computer language along
with all of the programming support typically associated with high-level
programming languages.
APT

 The Automatically Programmed Tools (APT) language is a computer language


dealing with motion. Electronic Systems Laboratory of MIT developed it in 1956.
ARCL

 ARCL (A Robot Control Language) was based on Pascal-like syntax. It was a


compiled language and the developed cross-compiler required three passes
before the executable code was ready to be downloaded and executed in a
robot.
 This language has a Pascal-like syntax with sensory-control and motion control
commands. An example of an ARCL-language command is
 MOVA (GRIP, HI, CONT, MED), which opens the gripper on the robot.
 ARCL emphasized sensory-based programming rather than planned trajectory
motion and was designed for educational robot.
ZDRL

 ZDRL (Zhe Da Robot Language) was a motion-oriented robot language.


 It was an interpretative system and the language was composed of system
commands and program instructions.
 System commands were used to prepare the system for execution of user-
written programs. ZDRL included 32 system commands and 37 program
instructions, and it contained capabilities for program editing, file management,
location-data teaching, program executing, and program debugging.
HELP

 HELP is a high-level programming language developed for use with General


Electric’s Allegro assembly robot.
Karel

 Karel, Karel 2, and Karel 3 are robot control languages used by some FANUC
robot controllers.
CAP 1

 The Conversational Auto Programming 1 (CAP 1) robot language is used by the


FANUC 32-18-T Robot Controller.
MML

 MML was a model-based mobile robot language that was developed at the
University of California.
 It is a high-level offline programming language, which contains functions for
high-level sensor functions, geometric model description and path planning, and
others.
 This language contains an important concept of slow and fast functions, which
architecture is essential for real-time control of robots.
 A slow function is executed sequentially, while a fast function is executed
immediately.
 The second important concept is the separation of the reference and current
posture, which makes precise and smooth motion control and dynamic posture
correction possible.
RIPL

 RIPL (Robot Independent Programming Language) is based on an object-oriented


Robot Independent Programming Environment [RIPE].
 The RIPE computing architecture consists of a hierarchical multiprocessor
approach, which employs distributed general and special-purpose processors.
 This architecture enables the control of diverse complex subsystems in real time
while co-coordinating reliable communications between them.
MCL
 MCL is short for Manufacturing Control Language and was developed by
McDonnell Douglas for the U.S. Air Force’s ICAM project.
RAIL

 RAIL is a high-level programming language developed by Automatix for use with


robots and vision systems.
RPL

RPL is a high-level programming language developed by SRI and is used to



configure automated manufacturing systems.
ARMBASIC

 ARMBASIC is an extension of the hobbyist computer language BASIC.


 It was used with the Microbot Mini-Mover 5 educational robot.
Androtext

 Androtext is a high-level computer language developed by Robotronic


Corporation to make commanding a personal robot easier.
VAL

 VAL stands for Victor’s Assembly Language. VAL is a high-level programming


language developed for PUMA lines of robots.
 The programming language is similar to BASIC.
 It has a complete set of vocabulary words for writing and editing robot
programs.
IBL

 IBL (Instruction Based Learning) is a method to train robots using natural


language instructions.
 IBL uses unconstrained language with a learning robot system.
 A robot is equipped with a set of primitive sensorymotor procedures such as turn
left or follow the road that can be regarded asan execution-level command
language.
 The user’s verbal instructions are converted into a new procedure and that
procedure becomes a part of the knowledge that the robot can use to learn
increasingly complex procedures.
 With this procedure, the robot should be capable of executing increasingly
complex tasks.
 Because errors are always possible in human-machine communication, IBL
verifies whether the learned subtask is executable. If it is not, then the user is
asked for more information.
Ladder Logic

 Ladder logic is a programming language designed to be used by electricians.


 It closely resembles the relay logic that appears on the inside lids or doors of
dishwashers and washing machines.
 The only robots that use ladder logic programming are those that come without
a controller or with a programmable logic controller.

EXAMPLE OF A ROBOT PROGRAM USING VAL

 The VAL language is the most advanced commercial language designed for use with
Unimation, Inc. industrial robots.
 VAL stands for Victor’s Assembly Language. It is basically an offline language in which the
program defining the motion sequence can be developed off line, but the various point
locations used in the work cycle are most conveniently defined by leadthrough.
 To demonstrate the VAL language, let us assume that the robot must pick up objects from a
chute and place them in successive boxes. One possible sequence of robot activity is as
follows:
1. Move to a location above the part in the chute.
2. Move to the part.
3. Close the gripper jaws.
4. Remove the part from the chute.
5. Carry the part to a location above the box.
6. Put the part into the box.
7. Open the gripper jaws.
8. Withdraw from the box.
The corresponding VAL program is as follows:

EDIT DEMO. 1

PROGRAM DEMO. 1

1. ? APPRO PART, 50 @
2. ? MOVES PART @
3. ? CLOSE I @
4. ? DEPARTS 150@
5. ? APPROS BOX, 200@
6. ? MOVE BOX@
7. ? OPENI @
8. ? DEPART@
The exact meaning of each line is:

1. Move to a location 50 mm above the part in the chute.


2. Move along a straight line to the part.
3. Close the gripper jaws.
4. Withdraw the part 150 mm from the chute along a straight-line path.
5. Move along a straight line to a location 200 mm above the box.
6. Put the part into the box.
7. Open the gripper jaws.
8. Withdraw 75 mm from the box.
When the program is executed, it causes the robot to perform the steps which describe
the task.

Most articulated robots perform by storing a series of positions in memory, and moving
to them at various times in their programming. For example, a robot that is moving items from
one place to another might have a simple program like this:

Define points P1–P5:

1. Safely above workpiece


2. 20 cm above bin A
3. At position to take part from bin A
4. 20 cm above bin B
5. At position to take part from bin B
Define program:

 Move to P1
 Move to P2
 Move to P3
 Close gripper
 Move to P4
 Move to P5
 Open gripper
 Move to P1 and finish
For a given robot, the only parameters necessary to locate the end effector (gripper,
welding torch, etc.) of the robot completely are the angles of each of the joints. However, there
are many different ways to define the points for the robot to move to, some of which can be
much more efficient, depending on the task to be accomplished.
Why robots

The reasons for using robots are:

1. Reduced costs—robots can perform tasks more economically than humans.


2. Improved productivity—robots are not only less expensive than human labor, but also
have higher rates of output. This increase in productivity is due to robot’s slightly faster
work pace but much is the result of the robot’s ability to work almost continually,
without lunch breaks and rest periods.
3. Better quality—robots have a distinct advantage of being able to perform repetitive
tasks with a higher degree of consistency, which in turn leads to improved product
quality.
4. Elimination of hazardous tasks -Robots were initially applied to jobs that were hot,
heavy, and hazardous such as die-casting, forging, and spot welding
ROBOT CAPABILITIES

The three important capabilities of robots that make them useful for applications are:

 Transport
 Manipulation
 Sensing
Transport

 Material handling is one of the basic operations, which is performed on an object as it


passes through the manufacturing process.
 The object is moved from one location to another to be stored, machined, assembled,
or packaged.
 The robot’s capability to acquire an object, move it through space, and release it makes
it ideal for transport operations.
Manipulation

 Workpieces are inserted, oriented, or twisted to be in proper position for machining,


assembly, or some other operation.
 A robot’s capability to manipulate both parts and tooling make it very suitable for
processing applications e.g. spot and arc welding, and spray painting.
Sensing

 A robot’s ability to react to its environment by means of sensory feedback is also


important, particularly in applications like assembly and inspection. These sensory
inputs may come from a variety of sensor types, including proximity switches, force
sensors, and machine vision systems.
APPLICATIONS OF ROBOTS

Manufacturing Applications

 Arc and spot-welding


 Spray painting
 Machine loading and unloading
 Machining
 Die casting
 Forging
 Investment casting
 Parts transferring
 Plastics molding
 Finishing
 Assembly
 Inspection
Materials Handling

 Transport goods
 Pick and place
 Palletizing
Space Industry

 Robot arms used as manipulator to handle bulky telescopes


 Mounted on space shuttle or repair craft
Military

 Remote bomb detonation


 Smart bombs
Medical Applications

 Intelligent wheelchairs
 Robot arms used to manipulate and handle patients

EXAMPLES
Arduino
 is an open-source hardware and software company, project and user community that
designs and manufactures single-board microcontrollers and microcontroller kits for building
digital devices.
 Arduino board designs use a variety of microprocessors and controllers.
 The boards are equipped with sets of digital and analog input/output (I/O) pins that may be
interfaced to various expansion boards ('shields') or breadboards (for prototyping) and other
circuits. The boards feature serial communications interfaces, including Universal Serial
Bus (USB) on some models, which are also used for loading programs from personal
computers.
 The microcontrollers can be programmed using the C and C++ programming languages,
using a standard API which is also known as the "Arduino language".
 The Arduino project provides an integrated development environment (IDE)

Sketch:

A sketch is a program written with the Arduino IDE.


It's the unit of code that is uploaded to and run on an Arduino board.

Comments

Everything between the /* and */ is ignored by the Arduino when it runs the sketch. There's
another style for short, single-line comments. These start with // and continue to the end of
the line.

Variables

A variable is a place for storing a piece of data. It has a name, a type, and a value. There's more
information in the Variables tutorial.

NOTE: refer to the Blink example.

Functions
A function (procedure or sub-routine) is a named piece of code that can be used from elsewhere in a
sketch. You can call a function that's already been defined (either in your sketch or as part of the
Arduino language).
There are two special functions that are a part of every Arduino sketch:
 setup()
 loop().
The setup () is called once, when the sketch starts.
It's a good place to do setup tasks like setting pin modes or initializing libraries.
The loop () function is called over and over and is heart of most sketches. You need to include both
functions in your sketch, even if you don't need them for anything.

Microcontrollers (Arduino)
Digital Pins
 The pins on the Arduino can be configured as either inputs or outputs.
 Arduino (Atmega) pins default to inputs, so they don't need to be explicitly declared as inputs
with pinMode().
Analog Input Pins
 The Atmega controllers used for the Arduino contain an onboard 6 channel analog-to-digital
(A/D) converter.
 While the main function of the analog pins for most Arduino users is to read analog sensors,
the analog pins also have all the functionality of general purpose input/ output (GPIO) pins
(the same as digital pins 0 – 13). The analog pins can be used identically to the digital pins,
using the aliases A0 (for analog input 0), A1, etc.
PWM
Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means.
Digital control is used to create a square wave, a signal switched between on and off.
Memory
There are three pools of memory in the microcontroller used on Arduino boards (ATmega168):
Flash memory (program space), is where the Arduino sketch is stored.
SRAM (static random access memory) is where the sketch creates and manipulates variables
when it runs.
EEPROM is memory space that programmers can use to store long- term information.

Blink example

1. – Test Arduino
 To build the circuit, attach a 220-ohm resistor to pin 13.
 Then attach the long leg of an LED (the positive leg, called the anode) to the resistor.
 Attach the short leg (the negative leg, called the cathode) to ground.
 Then plug your Arduino board into your computer.
 In the program below, the first thing you do is to initialize pin 13 as an output pin with the line

pinMode(13, OUTPUT);

In the main loop, you turn the LED on with the line: digitalWrite(13, HIGH);
This supplies 5 volts to pin 13. That creates a voltage difference across the pins of the LED, and lights it
up. Then you turn it off with the line:

digitalWrite(13, LOW);

#define LED_PIN 13 // Pin number attached to LED.

void setup() {
pinMode(LED_PIN, OUTPUT); // Configure pin 13 to be a digital
output.
}

void loop() {
digitalWrite(LED_PIN, HIGH); // Turn on the LED.
delay(1000); // Wait 1 second (1000 milliseconds).
digitalWrite(LED_PIN, LOW); // Turn off the LED.
delay(1000); // Wait 1 second.
}

2. – Potentiometer
Using a potentiometer, you will be able to control the resistance of
an LED. Turning the knob will increase and decrease the frequency
the LED blinks.

Parts Needed
 (1) Arduino Uno
 (1) USB A-to-B Cable
 (1) Breadboard – Half Size
 (1) LED 5mm
 (1) 220 Ω Resistor
 (1) Potentiometer (10k Trimpot)
 (6) Jumper Wires
Project Diagram

The circuit:
* Potentiometer attached to analog input 0
* Center pin of the potentiometer to the analog pin
* One side pin (either one) to ground
* The other side pin to +5V
* LED anode (long leg) attached to digital output 13
* LED cathode (short leg) attached to ground

Project Code
1. Connect the Arduino board to your computer using the USB
cable.
2. Open project code
/*
Analog Input
Demonstrates analog input by reading an analog sensor on analog pin 0 and
turning on and off a light emitting diode(LED) connected to digital pin 13.
The amount of time the LED will be on and off depends on
the value obtained by analogRead().

* Note: because most Arduinos have a built-in LED attached to pin 13 on the board, the LED is
optional.

*/

int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor

void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}

void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}
3. Select the board and serial port as outlined in earlier section.
4. Click upload button to send sketch to the Arduino.

3. – Photoresistor
A photoresistor changes the resistance a circuit gets based on the
amount of light that hits the sensor. In this project, the brightness
of the LED will increase and decrease based on the amount of light
present.

Parts Needed
 (1) Arduino Uno
 (1) USB A-to-B Cable
 (1) Breadboard – Half Size
 (1) LED 5mm
 (1) 330 Ω Resistor
 (1) 10K Ω Resistor
 (1) Photoresistor
 (6) Jumper Wires
Project Diagram
Project Code
1. Connect the Arduino board to your computer using the USB
cable.
2. Open project code
/******************************************************************
* SparkFun Inventor's Kit
* Example sketch 06
*
* PHOTO RESISTOR
*
* Use a photoresistor (light sensor) to control the brightness
* of a LED.
*
* This sketch was written by SparkFun Electronics,
* with lots of help from the Arduino community.
* This code is completely free for any use.
* Visit [Link] for SIK information.
* Visit [Link] to learn about the Arduino.
*
* Version 2.0 6/2012 MDG
* Version 2.1 9/2014 BCH
/*****************************************************************/

// As usual, we'll create constants to name the pins we're using.


// This will make it easier to follow the code below.

const int sensorPin = 0;


const int ledPin = 9;

// We'll also set up some global variables for the light level:
int lightLevel;
int calibratedlightLevel; // used to store the scaled / calibrated
lightLevel
int maxThreshold = 0; // used for setting the "max" light level
int minThreshold = 1023; // used for setting the "min" light level

void setup()
{
pinMode(ledPin, OUTPUT); // Set up the LED pin to be an output.
[Link](9600);
}
void loop()
{
lightLevel = analogRead(sensorPin); // reads the voltage on the
sensorPin
[Link](lightLevel);
//autoRange(); // autoRanges the min / max values you see in your
room.

calibratedlightLevel = map(lightLevel, 0, 1023, 0, 255); // scale the


lightLevel from 0 - 1023 range to 0 - 255 range.
// the map() function applies a linear
scale / offset.
// map(inputValue, fromMin, fromMax,
toMin, toMax);
[Link]("\t"); // tab character
[Link](calibratedlightLevel); // println prints an CRLF at the end
(creates a new line after)

analogWrite(ledPin, calibratedlightLevel); // set the led level based


on the input lightLevel.
}
/******************************************************************
* void autoRange()
*
* This function sets a minThreshold and maxThreshold value for the
* light levels in your setting. Move your hand / light source / etc
* so that your light sensor sees a full range of values. This will
* "autoCalibrate" to your range of input values.
/*****************************************************************/

void autoRange()
{
if (lightLevel < minThreshold) // minThreshold was initialized to 1023
-- so, if it's less, reset the threshold level.
minThreshold = lightLevel;

if (lightLevel > maxThreshold) // maxThreshold was initialized to 0 --


so, if it's bigger, reset the threshold level.
maxThreshold = lightLevel;

// Once we have the highest and lowest values, we can stick them
// directly into the map() function.
//
// This function must run a few times to get a good range of bright
and dark values in order to work.

lightLevel = map(lightLevel, minThreshold, maxThreshold, 0, 255);


lightLevel = constrain(lightLevel, 0, 255);
}
3. Select the board and serial port as outlined in earlier section.
4. Click upload button to send sketch to the Arduino.
4. Temp. Sensor
A temperature sensor measures ambient temperatures of the world
around it. In this project, we will be displaying the temperature in
the serial monitor of the Arduino IDE.

Parts Needed
 (1) Arduino Uno
 (1) USB A-to-B Cable
 (1) Breadboard – Half Size
 (1) Temperature Sensor – TMP36
 (5) Jumper Wires
Project Diagram

Project Code
1. Connect the Arduino board to your computer using the USB
cable.
2. Open project code
/******************************************************************
SparkFun Inventor's Kit
Example sketch 07 - TEMPERATURE SENSOR

Use the "serial monitor" window to read a temperature sensor.

The TMP36 is an easy-to-use temperature sensor that outputs


a voltage that's proportional to the ambient temperature.
You can use it for all kinds of automation tasks where you'd
like to know or control the temperature of something.

More information on the sensor is available in the datasheet:


[Link]

Even more exciting, we'll start using the Arduino's serial port
to send data back to your main computer! Up until now, we've
been limited to using simple LEDs for output. We'll see that
the Arduino can also easily output all kinds of text and data.
This sketch was written by SparkFun Electronics,
with lots of help from the Arduino community.
This code is completely free for any use.
Visit [Link] for SIK information.
Visit [Link] to learn about the Arduino.

Version 2.0 6/2012 MDG


******************************************************************/

// We'll use analog input 0 to measure the temperature sensor's


// signal pin.

const int temperaturePin = A0;

void setup()
{

[Link](9600); //Initialize serial port & set baud rate to 9600 bits per
second (bps)
}

void loop()
{

float voltage, degreesC, degreesF; //Declare 3 floating point variables

voltage = getVoltage(temperaturePin); //Measure the voltage at the analog


pin

degreesC = (voltage - 0.5) * 100.0; // Convert the voltage to degrees Celsius

degreesF = degreesC * (9.0 / 5.0) + 32.0; //Convert degrees Celsius to


Fahrenheit

//Now print to the Serial monitor. Remember the baud must be 9600 on your
monitor!
// These statements will print lines of data like this:
// "voltage: 0.73 deg C: 22.75 deg F: 72.96"

[Link]("voltage: ");
[Link](voltage);
[Link](" deg C: ");
[Link](degreesC);
[Link](" deg F: ");
[Link](degreesF);

delay(1000); // repeat once per second (change as you wish!)


}
float getVoltage(int pin) //Function to read and return
//floating-point value (true voltage)
//on analog pin
{

return (analogRead(pin) * 0.004882814);


// This equation converts the 0 to 1023 value that analogRead()
// returns, into a 0.0 to 5.0 value that is the true voltage
// being read at that pin.
}

// Other things to try with this code:

// Turn on an LED if the temperature is above or below a value.

// Read that threshold value from a potentiometer - now you've


// created a thermostat!
3. Select the board and serial port as outlined in earlier section.
4. Click upload button to send sketch to the Arduino.

5. – Servo
In this project, you will be able to sweep a servo back and forth
through its full range of motion.

Parts Needed
 (1) Arduino Uno
 (1) USB A-to-B Cable
 (1) Breadboard – Half Size
 (1) Servo
 (6) Jumper Wires
Project Diagram
Project Code
1. Connect the Arduino board to your computer using the USB
cable.
2. Open project code
/*
SparkFun Inventor's Kit
Example sketch 08-1

SINGLE SERVO

Sweep a servo back and forth through its full range of motion.

A "servo", short for servomotor, is a motor that includes


feedback circuitry that allows it to be commanded to move to
specific positions. This one is very small, but larger servos
are used extensively in robotics to control mechanical arms,
hands, etc. You could use it to make a (tiny) robot arm,
aircraft control surface, or anywhere something needs to be
moved to specific positions.

This sketch was written by SparkFun Electronics,


with lots of help from the Arduino community.
This code is completely free for any use.
Visit [Link] for SIK information.
Visit [Link] to learn about the Arduino.

Version 2.0 6/2012 MDG


*/

#include <Servo.h> // servo library

Servo servo1; // servo control object

void setup()
{

[Link](9, 900, 2100); //Connect the servo to pin 9


//with a
minimum pulse width of
//900 and a
maximum pulse width of
//2100.

void loop()
{
int position;

// To control a servo, you give it the angle you'd like it


// to turn to. Servos cannot turn a full 360 degrees, but you
// can tell it to move anywhere between 0 and 180 degrees.

// Change position at full speed:

[Link](90); // Tell servo to go to 90 degrees

delay(1000); // Pause to get it time to move

[Link](180); // Tell servo to go to 180 degrees

delay(1000); // Pause to get it time to move

[Link](0); // Tell servo to go to 0 degrees

delay(1000); // Pause to get it time to move

// Tell servo to go to 180 degrees, stepping by two degrees each


step

for(position = 0; position < 180; position += 2)


{
[Link](position); // Move to next position
delay(20); // Short pause to allow it to move
}

// Tell servo to go to 0 degrees, stepping by one degree each step

for(position = 180; position >= 0; position -= 1)


{
[Link](position); // Move to next position
delay(20); // Short pause to allow it to move
}
}
3. Select the board and serial port as outlined in earlier section.
4. Click upload button to send sketch to the Arduino.
6. – LCD Screen
An LCD is a liquid crystal display that is able to display text on its
screen. In this project, you should see the words “hello,world!”
displayed on the screen. The potentiometer is used to adjust the
contrast of the display.

Parts Needed
 (1) Arduino Uno
 (1) USB A-to-B Cable
 (1) Breadboard – Half Size
 (1) LCD Screen
 (1) Potentiometer
 (16) Jumper Wires
Project Diagram

Project Code
1. Connect the Arduino board to your computer using the USB
cable.
2. Open project code
/*
SparkFun Inventor's Kit
Example sketch 15

LIQUID CRYSTAL DISPLAY (LCD)

A Liquid Crystal Display (LCD) is a sophisticated module


that can be used to display text or numeric data. The display
included in your SIK features two lines of 16 characters, and
a backlight so it can be used at night.
If you've been using the Serial Monitor to output data,
you'll find that a LCD provides many of the same benefits
without needing to drag a large computer around.

This sketch will show you how to connect an LCD to your Arduino
and display any data you wish.

This sketch was written by SparkFun Electronics,


with lots of help from the Arduino community.
This code is completely free for any use.
Visit [Link] for SIK information.
Visit [Link] to learn about the Arduino.

Version 1.0 2/2013 MDG


*/

// Load the LiquidCrystal library, which will give us


// commands to interface to the LCD:

#include <LiquidCrystal.h>

// Initialize the library with the pins we're using.


// (Note that you can use different pins if needed.)
// See [Link]
// for more information:

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{

[Link](16, 2); //Initialize the 16x2 LCD

[Link](); //Clear any old data displayed on the LCD

[Link]("hello, world!"); // Display a message on the LCD!

void loop()
{

[Link](0, 1); //Set the (invisible) cursor to column 0,


// row 1.

[Link](millis() / 1000); //Print the number of seconds


//since the Arduino
last reset.
}
3. Select the board and serial port as outlined in earlier section.
4. Click upload button to send sketch to the Arduino.

You might also like