Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Arduino

Arduino is a prototype platform (open-source) based on an easy-to-use hardware and software. It


consists of a circuit board, which can be programmed and a ready-made software called Arduino IDE
(Integrated Development Environment), which is used to write and upload the computer code to the
physical board.
The key features are −
• Arduino boards are able to read analog or digital input signals from different sensors and
turn it into an output such as activating a motor, turning LED on/off, connect to the cloud
and many other actions.
• board functions can be controlled by sending a set of instructions to the microcontroller
on the board via Arduino IDE (referred to as uploading software).
• Arduino does not need a programmer in order to load a new code onto the board.
• Additionally, the Arduino IDE uses a simplified version of C++, making it easier to learn to
program.

Board Types
• Various kinds of Arduino boards are available depending on different microcontrollers used.
However, all Arduino boards have one thing in common: they are programmed through the
Arduino IDE.
• The differences are based on the number of inputs and outputs (the number of sensors, LEDs,
and buttons you can use on a single board), speed, operating voltage, form factor etc. Some
boards are designed to be embedded and have no programming interface (hardware), which you
would need to buy separately. Some can run directly from a 3.7V battery, others need at least 5V.

Arduino UNO:
Arduino UNO board is the most popular board in the Arduino board family. In addition, it is the
best board to get started with electronics and coding.
Looking at the board from the top down, this is an outline of what you will see (parts of the
board you might interact with in the course of normal use are highlighted):

The Arduino UNO.


Starting clockwise from the top center:
• Analog Reference pin (orange)
• Digital Ground (light green)
• Digital Pins 2-13 (green)
• Digital Pins 0-1/Serial In/Out - TX/RX (dark green) - These pins cannot be used for digital i/o
(digitalRead and digitalWrite) if you are also using serial communication (e.g. Serial.begin).
• Reset Button - S1 (dark blue)
• In-circuit Serial Programmer (blue-green)
• Analog In Pins 0-5 (light blue)
• Power and Ground Pins (power: orange, grounds: light orange)
• External Power Supply In (9-12VDC) - X1 (pink)
• Toggles External Power and USB Power (place jumper on two pins closest to desired supply) -
SV1 (purple)
• USB (used for uploading sketches to the board and for serial communication between the board
and the computer; can be used to power the board) (yellow)

Board Description in detail:


Power USB
Arduino board can be powered by using the USB cable from your computer. All you
need to do is connect the USB cable to the USB connection.

Power (Barrel Jack)


Arduino boards can be powered directly from the AC mains power supply by
connecting it to the Barrel Jack.

Voltage Regulator
The function of the voltage regulator is to control the voltage given to the Arduino
board and stabilize the DC voltages used by the processor and other elements.

Crystal Oscillator
Arduino uses 16 MHz crystal oscillator
Arduino Reset
Used to reset the Arduino board, i.e., start the program from the beginning.
Two ways to reset the UNO board: First, by using the reset button (17) on the board.
Second, connecting an external reset button to the Arduino pin labelled RESET (5).

Pins (3.3, 5, GND, Vin)


• 3.3V (6) − Supply 3.3 output volt
• 5V (7) − Supply 5 output volt
• Most of the components used with Arduino board works fine with 3.3
volt and 5 volt.
• GND (8)(Ground) − There are several GND pins on the Arduino, any of
which can be used to ground your circuit.
• Vin (9) − This pin also can be used to power the Arduino board from an
external power source, like AC mains power supply.

Analog pins
The Arduino UNO board has six analog input pins A0 through A5. These pins can read
the signal from an analog sensor like the humidity sensor or temperature sensor and
convert it into a digital value that can be read by the microprocessor.

Main microcontroller
Each Arduino board has its own microcontroller (11) which is the brain of board.

ICSP pin
Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino consisting
of MOSI, MISO, SCK, RESET, VCC, and GND. It is often referred to as an SPI (Serial
Peripheral Interface), which could be considered as an "expansion" of the output.
Actually, you are slaving the output device to the master of the SPI bus.

Power LED indicator


This LED should light up when you plug your Arduino into a power source to indicate
that your board is powered up correctly. If this light does not turn on, then there is
something wrong with the connection.

TX and RX LEDs
On your board, you will find two labels: TX (transmit) and RX (receive). They appear
in two places on the Arduino UNO board. First, at the digital pins 0 and 1, to indicate
the pins responsible for serial communication. Second, the TX and RX led (13). The
TX led flashes with different speed while sending the serial data. The speed of
flashing depends on the baud rate used by the board. RX flashes during the receiving
process.

Digital I/O
The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide PWM (Pulse
Width Modulation) output. These pins can be configured to work as input digital pins
to read logic values (0 or 1) or as digital output pins to drive different modules like
LEDs, relays, etc. The pins labelled “~” can be used to generate PWM.

AREF
AREF stands for Analog Reference. It is sometimes, used to set an external reference
voltage (between 0 and 5 Volts) as the upper limit for the analog input pins.

Arduino Programming:
The Arduino software is open-source.
The Arduino program is called “sketch”.

Structure of program:
Software structure consist of two main functions −
• Setup( ) function
• Loop( ) function
These are the Basic, Important and required functions in Arduino programming. When Arduino IDE is
opened, these two functions appear on the screen.

setup :
It is called only when the Arduino is powered on or reset. It is used to initialize variables and pin modes.
The setup() function is called when a sketch starts. Use it to initialize the variables, pin modes,
start using libraries, etc. The setup function will only run once, after each power up or reset of the
Arduino board.

loop :
The loop functions runs continuously till the
device is powered off. The main logic of the code
goes here. Similar to while (1) for micro-
controller programming.
After creating a setup() function, which
initializes and sets the initial values,
the loop() function does precisely what its name
suggests, and loops consecutively, allowing your
program to change and respond. Use it to actively
control the Arduino board.

Comments:
Comments are used to give information about the program. They are not compiled by the
compiler. The compiler ignores them. They increase the readability of the program.
There are two types of comments:
1. single line comment
// this is for single line comments
2. multi-line comment
/* this is for multi-line comments
Like this…
And this….
*/

Language Reference
Arduino programming language can be divided in three main parts: values (variables and
constants), functions, and structure.

Constants and Variables:


The constants and variables are both used to store data.

Constants:
The constants are those variables or values which cannot be modified once they are defined in the
program.
• They have fixed values till the program’s life.
• We can only assign value to the constant in the declaration.

The const keyword stands for constant. It is a variable qualifier that modifies the behavior of the
variable, making a variable "read-only". This means that the variable can be used just as any other
variable of its type, but its value cannot be changed. You will get a compiler error if you try to assign a
value to a const variable.

Constants defined with the const keyword obey the rules of variable scoping that govern other
variables. This, and the pitfalls of using #define, makes the const keyword a superior method for
defining constants and is preferred over using #define.

Example Code
const float pi = 3.14;
float x;
// ....
x = pi * 2; // it's fine to use consts in math
pi = 7; // illegal - you can't write to (modify) a constant

Note:
#define or const
You can use either const or #define for creating numeric or string constants. For arrays, you will
need to use const. In general const is preferred over #define for defining constants.

Types:
1. Integer Constants
Integer constants are numbers that are used directly in a sketch. By default, these numbers are
treated as int but you can change this with the U and L modifiers.
Keyword: int
Normally, integer constants are treated as base 10 (decimal) integers, but special notation
(formatters) may be used to enter numbers in other bases.
BASE EXAMPLE FORMATTER COMMENT
10 (decimal) 123 none
2 (binary) 0b1111011 leading "0b" characters 0 & 1 valid
8 (octal) 0173 leading "0" characters 0-7 valid
16 (hexadecimal) 0x7B leading "0x" characters 0-9, A-F, a-f valid

Note- Constants without other prefixes are assumed to be in decimal format.

Floating Point Constants


Used to define floating-point numbers, a number that has a decimal point.

Keyword: float
Floating point constants can also be expressed in a variety of scientific notation. 'E' and 'e' are
both accepted as valid exponent indicators. Eg: 10.0, 2.34E5, 67e-12

Arduino has defined builtin constants, they are:

HIGH | LOW
When reading or writing to a digital pin there are only two possible values a pin can take/be-set-to:
HIGH and LOW. These are the same as true and false, as well as 0 and 1.
HIGH
The meaning of HIGH (in reference to a pin) is somewhat different depending on whether a pin is set
to an INPUT or OUTPUT.
When a pin is configured as an INPUT, the Arduino (ATmega) will report HIGH if:
• a voltage greater than 3.0V is present at the pin (5V boards)
• a voltage greater than 2.0V is present at the pin (3.3V boards)
When a pin is configured to OUTPUT, and set to HIGH with digitalWrite(), the pin is at:
• 5 volts (5V boards)
• 3.3 volts (3.3V boards)

LOW
The meaning of LOW also has a different meaning depending on whether a pin is set to INPUT or
OUTPUT.
When a pin is configured as an INPUT with pinMode(), the Arduino (ATmega) will report LOW if:
• a voltage less than 1.5V is present at the pin (5V boards)
• a voltage less than 1.0V (Approx) is present at the pin (3.3V boards)

When a pin is configured to OUTPUT, and set to LOW with digitalWrite(), the pin is at 0 volts.

INPUT | OUTPUT
Digital pins can be used as INPUT, or OUTPUT. Changing a pin with pinMode() changes the electrical
behavior of the pin.
INPUT
Arduino pins configured as INPUT with pinMode() are said to be in a high-impedance state.
Pins configured as INPUT make extremely small demands on the circuit that they are sampling,
equivalent to a series resistor of 100 Megohms in front of the pin.
If a pin is configured as an INPUT, and is reading a switch, when the switch is in the open state
the input pin will be "floating", resulting in unpredictable results. In order to assure a proper reading
when the switch is open, a pull-up or pull-down resistor must be used. The purpose of this resistor is
to pull the pin to a known state when the switch is open.
• If a pull-down resistor is used, the input pin will be LOW when the switch is open and HIGH
when the switch is closed.
• If a pull-up resistor is used, the input pin will be HIGH when the switch is open and LOW when
the switch is closed.

OUTPUT
Pins configured as OUTPUT with pinMode() are said to be in a low-impedance state. This means that
they can provide a substantial amount of current to other circuits.
ATmega pins can source (provide current) or sink (absorb current) up to 40 mA (milliamps) of
current to other devices/circuits. This makes them useful for powering LEDs because LEDs typically
use less than 40 mA. Loads greater than 40 mA (e.g. motors) will require a transistor or other interface
circuitry.

LED_BUILTIN
Most Arduino boards have a pin connected to an on-board LED in series with a resistor. The constant
LED_BUILTIN is the number of the pin to which the on-board LED is connected. Most boards have this
LED connected to digital pin 13.

true | false
There are two constants used to represent truth and falsity in the Arduino language: true, and false.
true: Any integer which is non-zero is true. So -1, 2 and -200 are all defined as true.
false: false is defined as 0 (zero).
*Note that, true and false constants are typed in lowercase unlike HIGH, LOW, INPUT, and OUTPUT.

You might also like