Arduino 2
Arduino 2
Note:
Most Arduino boards use
What is Arduino? the Atmel 8-bit AVR
microcontroller.
32 KB (ATmega328P) of which
Flash Memory
0.5 KB used by bootloader
SRAM 2 KB (ATmega328P)
EEPROM 1 KB (ATmega328P)
EEPROM: Electrically
Clock Speed 16 MHz
Erasable Programmable
u However do not be too concerned if you do not understand all those Read-Only Memory. Non-
specifications because we will be interacting with the microcontroller volatile memory.
using the interface that the Arduino board provides us. Can be erased and
u It is good to know these specifications as you begin to develop more reprogrammed using a
complex applications because they do put limits on what we can do. pulsed voltage
What is Arduino?
u The Arduino is an open source hardware and software platform that is
incredibly powerful yet easy to use.
u You can look at and download the code from any of the Arduino
repositories on GitHub here:
u https://github.com/arduino
u This platform has captured the imagination of electronic enthusiasts
and the maker community everywhere. It enables people to
inexpensively experiment with electronic prototypes and see their
projects come to life.
u Projects can range from simply making an LED blink or recording the
temperature to controlling 3D printers or making robots.
u While there are numerous models of the Arduino, in this course we
will primarily be using the very popular Arduino UNO R3 board.
Arduino Uno's R3 board layout
DC supply Input: The DC supply input can
be used with an AC-to-DC power
adapter or a battery. The power source
can be connected using a 2.1 mm
centerpositive plug. The Arduino Uno
operates at 5 volts but can have a
maximum input of 20 volts; however, it is
recommended to not use more than 12V.
Power and External Reset: These pins in this header, Analog In Connectors: The pins, labeled A0 to A5, can be
provide ground and power for external devices and used for analog input. These pins can be used to read the
sensors from the Arduino. The Arduino can also be output from analog sensors.
powered through these pins. There is also a reset pin
that can be used to reset the Arduino.
Arduino shields
u An Arduino shield is a modular circuit
board that plugs directly into the pin
headers of the Arduino board.
u These shields will add extra
functionality to the Arduino board.
u If we are looking to connect to the
internet, do speech recognition,
control DC motors or add other
functionality to the Arduino, there is
probably a shield that can help us.
u While you don’t have to use shields,
they do make adding extra
functionality to our Arduino boards
very easy.
Arduino looks with two shields attached:
u A shield fits on top of the
Arduino by plugging directly
into the pin headers.
u We can also stack one shield
on top of another if they do
not use the same resources.
Here is how an
Arduino pin
u There is a total of
31 pins in the
Arduino Uno pin
headers.
u Most of these pins
can be configured to
perform different
functions.
Digital pins
u Used the most when
connecting external sensors.
u These pins can be configured
for either input or output.
u These pins default to an
input state
u The digital pins will have one
of two values: HIGH (1),
which is 5V, or LOW (0),
which is 0V.
Analog input pins
u The Arduino Uno contains a
built-in Analog-To-Digital
(ADC) converter with six
channels, which gives us six
analog input pins. The ADC
converts an analog signal into
a digital value.
u While the digital pins have two
values, either high or low, the
analog input pins have values
from 0 to 1023 relative to the
reference value of the
Arduino.
u The Arduino Uno has a
reference value of 5V.
u Used to read analog sensors
such as rangefinders and
temperature sensors.
u The six analog pins can also be
configured as digital pins if we
run out of digital pins in our
project.
PWM pins
u Where the analog input pins
are designed to read analog
sensors (input), the PWM pins
are designed for output.
PWM is a technique for
obtaining analog results
with digital output.
u Since a digital output can be
either on or off, to obtain
the analog output the digital
output is switch between
HIGH and LOW rapidly.
u The percentage of the time
that the signal is high is
called the duty cycle.
Duty cycle
u The Arduino programming language is Basic code Used to initialize the pin modes
based on a very simple hardware structure and start serial communication.
programming language called processing, This function has to be included
which is similar to the C language. void setup( ) even if there are no statements
{ to execute.
u You create sketches which contain your
statements;
code
}
u After the sketch is written in the Arduino The execution block runs after
IDE, it should be uploaded on the Arduino void loop( ) setup and hosts statements like
board for execution. { reading inputs, triggering outputs,
statement; checking conditions etc..
}
As the name suggests, the loop( )
function executes the set of
statements (enclosed in curly
braces) repeatedly.
Example int led = 9; // The digital pin to which the LED is connected
int brightness = 0; // Brightness of LED is initially set to 0
program int fade = 5; // By how many points the LED should fade
void setup()
{
LED fade-in and pinMode(led, OUTPUT); //pin 10 is set as output pin
fade-out }
fade = -fade;
}
delay(30); // Wait for 30 milliseconds
}