Arduino Notes
Arduino Notes
An Arduino kit is actually a microcontroller based kit which can be either used directly by purchasing
from the vendor or can be made at home using the components, owing to its open source hardware
feature. It is basically used in communica ons and in controlling or opera ng many devices. It was
founded by Massimo Banzi and David Cuar elles in 2005.
Arduino Architecture:
Arduino’s processor basically uses the Harvard architecture where the program code and program data
have separate memory. It consists of two memories‐ Program memory and the data memory. The code
is stored in the flash program memory, whereas the data is stored in the data memory. The Atmega328
has 32 KB of flash memory for storing code (of which 0.5 KB is used for the bootloader), 2 KB of SRAM
and 1 KB of EEPROM and operates with a clock speed of 16MHz.
Arduino Uno consists of 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog
inputs, a 16 MHz crystal oscillator, a USB connec on, a power jack, an ICSP header, and a reset bu on.
Power Jack: Arduino can be power either from the pc through a USB or through external source like
adaptor or a ba ery. It can operate on a external supply of 7 to 12V. Power can be applied externally
through the pin Vin or by giving voltage reference through the IO Ref pin.
Digital Inputs: It consists of 14 digital inputs/output pins, each of which provide or take up 40 mA
current. Some of them have special func ons like pins 0 and 1, which act as Rx and Tx respec vely, for
serial communica on, pins 2 and 3‐which are external interrupts, pins 3,5,6,9,11 which provides PWM
output and pin 13 where LED is connected.
Analog inputs: It has 6 Analog input/output pins, each providing a resolu on of 10 bits.
The Arduino tool window consists of the toolbar with the bu ons like verify, upload, new, open, save,
serial monitor. It also consists of a text editor to write the code, a message area which displays the
feedback like showing the errors, the text console which displays the output and a series of menus like
the File, Edit, Tools menu.
5 Steps to program an Arduino
Programs wri en in Arduino are known as sketches. A basic sketch consists of 3 parts
1. Declara on of Variables
2. Ini aliza on: It is wri en in the setup () func on.
3. Control code: It is wri en in the loop () func on.
The sketch is saved with .ino extension. Any opera ons like verifying, opening a sketch, saving
a sketch can be done using the bu ons on the toolbar or using the tool menu.
Chose the proper board from the tools menu and the serial port numbers.
Click on the upload bu on or chose upload from the tools menu. Thus the code is uploaded
by the bootloader onto the microcontroller.
serial.begin(baud rate): Sets the beginning of serial communica on by se ng the bit rate.
We can also design our own Arduino by following the schema c given by the Arduino vendor and also
available at the websites. All we need are the following components‐ A breadboard, a led, a power
jack, a IC socket, a microcontroller, few resistors, 2 regulators, 2 capacitors.
The IC socket and the power jack are mounted on the board.
Add the 5v and 3.3v regulator circuits using the combina ons of regulators and capacitors.
Mount the female headers onto the board and connect them to the respec ve pins on the
chip.
Mount the row of 6 male headers, which can be used as an alterna ve to upload programs.
Upload the program on the Microcontroller of the readymade Adruino and then pry it off and
place back on the user kit.
1. It is inexpensive
2. It comes with an open source hardware feature which enables users to develop their own kit
using already available one as a reference source.
3. The Arduino so ware is compa ble with all types of opera ng systems like Windows, Linux,
and Macintosh etc.
4. It also comes with open source so ware feature which enables experienced so ware
developers to use the Arduino code to merge with the exis ng programming language libraries
and can be extended and modified.
6. We can develop an Arduino based project which can be completely stand alone or projects
which involve direct communica on with the so ware loaded in the computer.
7. It comes with an easy provision of connec ng with the CPU of the computer using serial
communica on over USB as it contains built in power and reset circuitry.
So this is some basic idea regarding an Arduino. You can use it for many types of applica ons. For
instance in applica ons involving controlling some actuators like motors, generators, based on the
input from sensors.
Arduino Coding
The setup() func on is called when a sketch starts. Use it to ini alize variables, pin modes, start using
libraries, etc. The setup func on will only run once, a er each powerup or reset of the board.
A er crea ng a setup() func on, the loop() func on does precisely what its name suggests, and loops
consecu vely, allowing your program to change and respond as it runs. Code in the loop() sec on of
your sketch is used to ac vely control the board.
The code below won't actually do anything, but it's structure is useful for copying and pas ng to get
you started on any sketch of your own. It also shows you how to make comments in your code.
Any line that starts with two slashes (//) will not be read by the compiler, so you can write anything
you want a er it. The two slashes may be put a er func onal code to keep comments on the same
line. Commen ng your code like this can be par cularly helpful in explaining, both to yourself and
others, how your program func ons step by step.
void setup() {
}
void loop() {
// the setup func on runs once when you press reset or power the board
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
void loop() {
LED Fade
This Arduino program shows how to fade an LED on pin 9 using the analogWrite() func on. The
analogWrite() func on uses PWM, so if you want to change the pin you're using, be sure to use
another PWM capable pin.
On most Arduino boards, the PWM pins are iden fied with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.
pinMode(led, OUTPUT);
void loop() {
analogWrite(led, brightness);
fadeAmount = ‐ fadeAmount;
delay(30);