Arduino
Arduino
Arduino
Arduino
Arduino also simplifies the process of working with microcontrollers, but it offers some
advantage for teachers, students, and interested amateurs over other systems:
Cross-platform - The Arduino Software (IDE) runs on Windows, Macintosh OSX, and Linux
operating systems. Most microcontroller systems are limited to Windows.
Simple, clear programming environment - The Arduino Software (IDE) is easy-to-use for
beginners, yet flexible enough for advanced users to take advantage of as well. For teachers,
it's conveniently based on the Processing programming environment, so students learning to
program in that environment will be familiar with how the Arduino IDE works.
Open source and extensible software - The Arduino software is published as open source
tools, available for extension by experienced programmers. The language can be expanded
through C++ libraries, and people wanting to understand the technical details can make the
leap from Arduino to the AVR C programming language on which it's based. Similarly, you
can add AVR-C code directly into your Arduino programs if you want to.
1
2. Microcontroller
instructions we give tothe Microcontroller. It is this job of telling the chip what to do, is what
we refer to as programming on it.However, the uC by itself, cannot accomplish much; it
needs several external inputs: power, for one; a steady clock signal, for another. Also, the job
of programming it has to be accomplished by an external circuit. So typically, a uC is used
along with a circuit which provides these things to it; this combination is called a
microcontroller board. The Arduino Uno that you have received, is one such microcontroller
board. The actual microcontroller at its heart is the chip called Atmega328. The advantages
that Arduino offers over other microcontroller boards are largely in terms of reliability of the
circuit hardware as well as the ease of programming and using it.
2
3. Hardware
3
3.3) FTDI
FTDI provides application-specific integrated circuit (ASIC) design services. They also
provide consultancy services for product design, specifically in the realm of electronic
devices.
Note: For higher current applications (>30mA), never use the com port!!
4
The power requirement for ARDUINO is 9 to 12V DC, 250mA or more, 2.1mm plug, Centre
pin positive.
5
4. Flavours of Arduino
There have been many revisions of the USB
Arduino. Some of them are
4.2)ArduinoMega 2560:
A larger, more powerful Arduino
board. Has extra digital pins, PWM
pins, analog inputs, serial ports,
etc.The version of the Mega released
with the Uno, this version features the
Atmega2560, which has twice the
memory, and uses the ATMega 8U2 for USB-to-serial communication.
4.3)Arduino Duemilanove:
The Duemilanove automatically selects the
appropriate power supply (USB or external power),
eliminating the need for the power selection jumper
found on previous boards. It also adds an easiest to
cut trace for disabling the auto-reset, along with a
solder jumper for re-enabling it.
6
4.4)Arduino Fio:
An Arduino intended for use as a wireless node. Has a header
for an XBee radio, a connector for a LiPobattery, and a battery
chargingcircuit.
4.5)LilyPad Arduino:
A stripped-down, circular Arduino board designed for stitching into
clothing and other fabric/flexible applications. Needs an additional
adapter to communicate with a computer.
The main change in the Arduino Diecimila is that it can be reset from the computer, without
the need to physically
press the reset button on
the board. The
Diecimila uses a low
dropout voltage
regulator which lowers
the board's power
consumption when
powered by an external
supply (AC/DC adapter or battery). A resettable polyfuse protects your computer's USB ports
from shorts and surges. It also provides pin headers for the reset line and for 3.3V. There is a
built-in LED on pin 13. Some blue Diecimila boards say "Prototype - Limited Edition" but
are in fact fully-tested production boards (the actual prototypes are red).
7
4.7)Lilypad Arduino 03
This revision has a 6-pin programming header that's compatible with FTDI USB cables and
the Sparkfun FTDI Basic Breakout. It adds support for automatic reset, allowing sketches to
be uploaded without pressing the reset button on the board. The header is surface mounted,
meaning that the board has no pokey bits sticking out the back.
4.8)Arduino Nano
The pros of this board are:Tiny size (or, compact) is one the major advantages of this board
and bread-board friendly.
But, the cons are:There is no direct power-source jack. So, you use any power source.But, the
preceding statement is not quite true. Since, it's a low voltage board you can use a power
source using the Vin Pin, but you need to take a few precautions. Otherwise it will burn the
board.More or less, it is equivalent to an Arduino UNO.
The only difference between pro mini and Nano is, that it
8
doesn’t have a USB to serial interface and voltage regulator (3.3v in 5v version).
It is basically designed to be used in the places where size is the topmost priority and
permanent installation.
Features:
9
5. Basic Terminologies
Here,
10
NOTE: PWM pins are output pins.
PWM signals can be used to control dc motors, servos, stepper motors, brightness of any led,
etc.
5.3) Sketch
This is the term used for a program.
5.4) Shield
This is a circuit board that can be plugged on top of an Arduino. Shields have a variety of
applications. For example, motor driver shields, LCD shields etc.
11
5.5 ) Processing Code
This is the programming environment used most often with Arduino. It can be downloaded
(free) from arduino.cc. It is a somewhat simplified version of the C programming language.
The black screen below the sketch is the compiler, which comes alive once the program is
run by pressing the tick button in the leftmost side.
The button beside the compile button is the upload button which is an arrow directing to the
right. This burns the program to the board connected to the USB port. The board connected
can be changed by going in the ‘Tools’ option in the menu bar.
12
5 Basic Programming concepts
The Arduino works on basic C environment. But the header files are pre-included in writing a
program. The sketch contains only the most relevant part of the program/code.
6.1)functions
A function is a block of code that has a name and a block of statements that are executed
when the function is called. The functions void setup() and void loop() have already been
discussed and other built in functions will be discussed later. Custom functions can be written
to perform repetitive tasks and reduce clutter in a program. Functions are declared by first
declaring the function type. This is the type of value to be returned by the function such as
‘int’ for an integer type function. If no value is to be returned, then the function type will be
taken as void.
type functionName(parameters)
{ statements; }
type function()
{ statements; }
6.3); semicolon
A semicolon must be used to end a statement and separate elements of the program. A
semicolon is also used to separate elements in a for loop.
13
Forgetting this semicolon will result in compile error.
6.4)Variables
A variable is a way of naming and storing a numerical value for later use by the program. As
their namesake suggests, variables are numbers that can be continually changed as opposed to
constants whose value never changes. A variable needs to be declared and optionally
assigned to the value needing to be stored. The following code declares a variable called
inputVariable and then assigns it the value obtained on analog input pin 2:
6.5)byte
Byte stores an 8-bit numerical value without decimal points. They have a range of 0-255.
6.6)int
Integers are the primary datatypefor storage of numbers without decimal points and store a
16-bit value with a range of 32,767 to -32,768.
intsomeVariable = 1500;
6.7)long
Extended size datatype for long integers, without decimal points, stored in a 32-bit value with
a range of 2,147,483,647 to -2,147,483,648.
14
6.8)float
A datatype for floating-point numbers, or numbers that have a adecimal point. Floating-point
numbers have greater resolution than integers and are stored as a 32-bit value with a range of
3.4028235E+38 to -3.4028235E+38.
6.9)arrays
An array is a collection of values that are accessed with an index number. Any value in the
array may be called upon by calling the name of the array and the index number of the value.
Arrays are zero indexed, with the first value in the array beginning at the index number 0. An
array needs to be declared and optionally assigned values before they can be used.
Likewise, it is possible to declare an array by declaring the array type and size and later assign values
to an index position.
intmyArray[5];
myArray[3]=10;
To retrieve a value from an array, assign a variable to the array and index position:
x=myArray[3];
Arrays are often used in for loops, where the increment counter is also used as the index position for
each array value. The following example uses an array to flicker an LED. Using a for loop, the
counter begins at 0, writes the value contained at index position 0 in the array flicker[], in this case
180, to the PWM pin 10, pauses for 200ms, then moves to the next index position :
void setup()
15
}
void loop()
for(inti=0;i<7;i++)
6.10) arithmetic
Arithmetic operators include addition, subtraction , multiplication, and division. They return
the sum, difference, product, or quotient (respectively) of two operands.
y = y + 3; // addition
x = x – 7; // subtraction
i = j * 6; // multiplication
r = r / 5; // division
The operation is conducted using the data type of the operands, so, for example, 9/4 results in
2 instead of 2.25 since 9 and 4 are ints and are incapable of using decimal points. This also
means that the operation can overflow if the result is larger than what can be stored in the
data type.
If the operands are of different data type, the larger type is used for the calculation. For
example, if one of the numbers (operands) are of the type float and the other of type integer,
floating point math will be used for the calculation.
Choose variables sizes that are large enough to hold the largest results from your calculations.
Know at what point your variable will rollover and also what happens in the other direction
16
e.g. (0 - 1) OR (0 - - 32768). For math that requires fractions, use float variables, but be
aware of their drawbacks: large size and slow computation speeds.
Note: Use the cast operator e.g. (int)myFloat to convert one variable type to another on the
fly. For example, i = (int)3.6 will set i equal to 3.
x *= y // same as x = x * y, or multiplies x by y
x /= y // same as x = x / y, or divides x by y
Note: For example, x *= 3 would triple the old value of x and re-assign the resulting value to
x.
x == y // x is equal to y
x != y // x is not equal to y
17
x <= y // x is less than or equal to y
Logical AND:
if (x > 0 && x < 5 ) // true only if both the expressions are true
Logical OR:
Logical NOT:
6.14) Constants
The Arduino language has a few predefines values, which are called constants. They are used
to make the programs easier to read. Constants are classified in groups.
6.15) true/false
These are Boolean constants that define logic levels. FALSE is easily defined as 0 (zero)
while TRUE is often defined as 1, but can also be anything else except zero. So in a Boolean
sense, -1,2, and -200 are all also defined as TRUE.
18
6.16) HIGH / LOW
These constants define pin levels as HIGH or LOW and are used when eeading or writing to
digital pins. HIGH is defined as logic level 1, ON, or 5 volts while LOW is logic level 0,
OFF, or 0 volts.
if(inputPin == HIGH)
{ doThingA; }
else
{ doThingB; }
else can also precede another if test, so that multiple, mutually exclusive test can be run at the
same time. It is even possible to have an unlimited number of these else branches. Remember
though, only one set of statements will be run depending on the condition tests:
if(inputPin< 500)
{ doThingA; }
{ doThingB; }
19
else
{ doThingC; }
Note: An if statement simply tests whether the condition inside the parenthesis is true or
false. This statement can be any valid C statement as in the first example, if(inputPin ==
HIGH). In this example, the if statement only checks to see if indeed the specified input is at
logic level high, or +5v.
{ doSomething; }
The initialization of a local variable, or increment counter, happens first and only once. Each
time through the loop, the following condition is tested. If the condition remains true, the
following statements and expression are executed and the condition is tested again. When the
condition becomes false, the loop ends.
The following example starts the integer i at 0, tests to see if i is still less than 20 and if true,
increments i by 1 and executes the enclosed statements:
20
6.20)pinMode(pin, mode)
Used in void setup() to configure a specified pin to behave either as an INPUT or an
OUTPUT.
Arduino digital pins default to inputs, so they don’t need to be explicitly declared as inputs
with pinMode(). Pins configured as INPUT are said to be in a high impedance state.
There are also convenient 20Kohm pullup resistors built into the atmega chip that can be
accessed from software. These built-in pull up resistors are accessed in the following manner:
Pullup resistors would normally be used for connecting inputs like switches. Notice in the
above example that it does not convert pin to an output, it is merely a method for activating
the internal pull-ups.
Pins configuredas OUTPUT are said to be in a low-impedance state and can provide 40 mA
(milliamps) of current to other devices/circuits. This is enough current to brightly light up an
LED (don’t forget the series resistor), but not enough current to run most relays, solenoids, or
motors.
Short circuits on Arduino pins and excessive current can damage or destroy the output pin, or
damage the entire Atmega chip. It is often a good idea to connect an OUTPUT pin to an
external device in series with a 470ohm or 1kohm resistor.
6.21)digitalRead(pin)
Reads the value from a specified digital pin with the result either HIGH or LOW. The pin can
be specified as either a variable or constant (0-13).
21
6.22)digitalWrite(pin, value)
Outputs either logic level HIGH or LOW at (turns on or off) a specified digital pin. The pin
can be specified as either a variable or constant (0 - 13).
digitalWrite(pin, HIGH);
6.23)analogRead(pin)
Reads the value from a specified analog pin with a 10-bit resolution. This function only
works on the analog in pins (0-5). The resulting integer values range from 0 to 1023.
value = analogRead(pin);
Note: Analog pins inlike as digital ones, do not need to be first declared as INPUT or
OUTPUT.
6.24)analogWrite(pin, value)
Writes a pseudo- analog value using hardware enabled pulse width modulation (PWM) to an
output pin marked PWM. On newer Arduinos with the ATmega168 chip, this function works
on pins 3,5,6,9,10, and 11. Older Arduinos with an ATmega8 only support pin 9,10and 11.
The values can be specified as a variable or constant with a value from 0-225.
analogWrite(pin, value);
A value of 0 generates a steady 0 volts output at the specified pin; a value of 255 generates a
steady 5 volts output at the specified pin. For values in between 0 and 255, the pin rapidly
alternates between 0 and 5 volts – the higher the value, the more often the pin is HIGH (5
volts). For example, a value of 64 will be 0 volts three quarters of the time, and 5 volts one
quarter of the time; a value of 128 will be at 0 half the time and 255 half the time; and a value
of 192 will be 0 volts, one quarter of the time and 5 volts three quarters of the time.
22
Because this is a hardware function, the pin will generate a steady wave after a call to
analogWrite in the background until the next call to analogWrite (or a call to digitalRead or
digitalWrite on the same pin).
Note: analog pins unlike digital ones, donot need to be first declared as INPUT nor
OUTPUT.
6.25) delay(ms)
Pauses your program for the amount of time as specified in milliseconds, where 1000 equals
1 second.
6.26)millis()
Returns the number of milliseconds since the Arduino board began running the current
program as an unsigned long value.
Note: This number will overflow (reset back to zero), after approximately 9 hours.
23
6. First Program
7.1) Object:
7.2) Schematic:
7.3) Sketch:
void setup()
void loop()
if (digitalRead(Sw)==HIGH)
{ digitalWrite(LedPin,HIGH); //LED ON
}}
24
7. Serial Communication
The Serial Communication is bit by bit data sending through the serial port. This is basically
done by the Tx and the Rx pins on the board. This mode of communication is used to send or
receive the data or for entering inputs and displaying ouputs on the screen via serial monitor
in the IDE.
8.1) Serial.begin(rate)
Opens serial port and sets the baud rate for serial data transmission. The typical baud rate for
communicating with the computer is 9600 although other speeds are supported.
void setup()
{ Serial.begin(9600); }
Note: When using serial communication, digital pins 0 (Rx) and 1 (Tx) cannot be used at the
same time
8.2) Serial.println(data)
Prints data to the serial port, followed by an automatic carriage return and line feed. This
command takes the same form as Serial.print(), but is easier for reading data on the serial
monitor.
8.3) Serial.available()
This is the function that fetches the data on the serial bus at the communication port. This is
used to read the data coming from the Arduino through the serial port.
25
8. Home Automation System
9.1) Object :
Controlling a an AC appliance with an android device.
9.2) Requirements:
Arduino board, HC-05 bluetooth module, jumper wires, bread board, relay
module(5vDC,220vAC,7A), battery and android phone.
9.3) Schematic:
9.4) Procedure:
Download the Application Bluetooth Terminal from the google play store in android.
Connect the hardware as shown in the figure.
Follow the code
26
#define switch 3;
void setup()
digitalWrite(switch,LOW);
void loop()
Serial.println(“Relay ON”);
Serial.println(“Relay OFF”);
else
Serial.println(“Invalid input”);
27
Give the supply through the external adapter of the Arduino board
Now scan for new Bluetooth devices in the android phone and connect with the
‘HC-05’ name.
9.5) Observations:
In the Bluetooth terminal app, the values 1 and 0 are able to switch the relay ON and OFF.
9.6) Result:
Android phone can be used to control even more relays in the same fashion. This will help to
control the appliances wirelessly.
28
10. Conclusion
Arduino is an open source platform for embedding, innovating, building, inventing and
achieving automation goals. This is a report which has only the basics to just get started.
Although the scope extends to infinity.
Currently people on industrial basis, use Arduino to control CNC machines, 3D printing,
home automation, radio sensing, weather stations, robotic controls, biometrics, medical
sciences and the list goes on and on.
And with the addition of IoT (internet of things), Arduino achieves a whole new level of
grounds.
29
10. References
10.1)https://www.arduino.cc/
10.2)https://www.adafruit.com/
10.3)https://en.wikipedia.org/
10.4) http://www.instructables.com/tag/type-id/category-technology/channel-arduino/
30