Lecture Notes 1
Lecture Notes 1
Lecture Notes 1
Applications (EC-506)
• You can control your board functions by sending a set of instructions to the
microcontroller on the board via Arduino IDE (referred to as uploading
software).
• Unlike most previous programmable circuit boards, Arduino does not need
an extra piece of hardware (called a programmer) in order to load a new
code onto the board. You can simply use a USB cable.
• Finally, Arduino provides a standard form factor that breaks the functions of
the micro-controller into a more accessible package.
Reasons why Arduino is being preferred
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 software is compatible with all types of operating systems like Windows,
Linux, and Macintosh etc.
4. It also comes with open source software feature which enables experienced software
developers to use the Arduino code to merge with the existing 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 communication with the software loaded in the computer.
7. It comes with an easy provision of connecting with the CPU of the computer using serial
communication over USB as it contains built in power and reset circuitry.
The Many Flavors of Arduino
• Arduino Uno
• Arduino Leonardo
• Arduino LilyPad
• Arduino Mega
• Arduino Nano
• Arduino Mini
• Arduino Mini Pro
• Arduino BT
Arduino-like Systems
• Cortino (ARM)
• Xduino (ARM)
• LeafLabs Maple
(ARM)
• BeagleBoard (Linux)
• Wiring Board
(Arduino
predecessor)
Arduino Add-ons (Shields)
• TFT Touch Screen
• Data logger
• Motor/Servo shield
• Ethernet shield
• Audio wave shield
• Cellular/GSM shield
• WiFi shield
• ...many more
Where to Get an Arduino Board
PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the
analogWrite() function. On boards with an ATmega8, PWM output is
available only on pins 9, 10,and 11.
LED: 13. There is a built-in LED connected to digital pin 13. When the pin is
HIGH value, the LED is on, when the pin is LOW, it's off.
Analog Pins
In addition to the specific functions listed below,
the analog input pins support 10-bit analog-to-digital
conversion (ADC) using the analogRead() function.
Most of the analog inputs can also be used as digital
pins: analog input 0 as digital pin 14 through analog
input 5 as digital pin 19. Analog inputs 6 and 7
(present on the Mini and BT) cannot be used as digital
pins.
I2C: 4 (SDA) and 5 (SCL). Support I2C (TWI)
communication using the Wire library
Power Pins
VIN (sometimes labelled "9V"). The input voltage to the Arduino board
when it's using an external power source (as opposed to 5 volts from the USB
connection or other regulated power source). You can supply voltage
through this pin, or, if supplying voltage via the power jack, access it through
this pin. Note that different boards accept different input voltages ranges,
please see the documentation for your board. Also note that the LilyPad has
no VIN pin and accepts only a regulated input.
5V. The regulated power supply used to power the microcontroller and
other components on the board. This can come either from VIN via an on-
board regulator, or besupplied by USB or another regulated 5V supply.
3V3. A 3.3 volt supply generated by the on- board FTDI chip.
Power Supply: Power supply section provide different voltage level to different
part of arduino board. This part contain bridge rectifier and voltage regulator.
AVR Atmega CPU: This block is the heart of the controller. Generally Atmega
8, Atmega 16, Atmega 32, Atmega 328 controller are used in arduino board.
This block execute all the fuctions that written in arduinoprogram.
SPI Interface section: This section is used for serial peripheral interfacing.
Analog input section: We know that Atmega 8 CPU has inbuilt 6 channel 10
– bit ADC. This ADC can convert analog data from analog pin into digital. So,
for taking analog value for digital conversion we have to use this section.
Circuit Diagram of Arduino
Atmega328 Microcontroller and its pin
mapping with Arduino board pins
Arduino Architecture
• Based on Harvard architecture where the program code and
program data have separate memory.
• Microcontroller: ATmega328
• Operating Voltage: 5V
• Input Voltage (recommended): 7-12V
• Input Voltage (limits): 6-20V
• Digital I/O Pins: 14 (of which 6 provide PWM output)
• Analog Input Pins: 6
• DC Current per I/O Pin: 40 mA
• DC Current for 3.3V Pin: 50 mA
• Flash Memory: 32 KB of which 0.5 KB used by bootloader
• SRAM: 2 KB (ATmega328)
• EEPROM: 1 KB (ATmega328)
• Clock Speed: 16 MHz
Arduino IDE ( Software)
The sketch is saved with .ino extension. Because INO files are plain text files,
you can also open them in any text editor, including:
Notepad++ (Windows) Apple TextEdit (Mac) GitHub Atom (cross-platform)
• Serial.println(val)
Same as S e r i a l . p r i n t ( ) , but with line-feed
Serial Communication -Reading
• Serial.available()
Returns the number of bytes available to be read, if any
Example:
i f ( S e r i a l . a v a i l a b l e ( ) > 0) {
data = S e ri a l . re a d ( ) ;
}
void loop() {
di g i t a lW r i t e ( 1 3 , HIGH); // s et the LED on
Wait 1000 milliseconds delay(1000); // wait f o r a second
di g i t a lW r i t e ( 1 3 , LOW); // set the LED o f f
delay(1000); // wait f o r a second
Set output low (0V) }
Notes:
• Resistor is needed to limit current
• Resistor and LED may be
interchanged
(but polarity of LED is important)
http://www.wikipedia.org/ • Pin 13 is special: has built-in
resistor and LED
• Change program and upload
Example: Using a Solderless
Breadboard
Comments
• Comments can be anywhere
• Comments created with // or /* and */
• // is used for single linecomment.
• /* */ is used for multiline
comments
• Comments do not affect code
• You may not need comments, but
think about the community!
Programming Symbols
/ / - Single line comment
/* */ - Multiline comment
{ } –used to define a block of code that starts andends.
; - used to define the end of a line of code.
Numeric Data Type in Arduino Programming
Types of operators
• Arithmetic Operators
• Comparison Operators
• Boolean Operators
• Bitwise Operators
• Compound Operators
Arithmetic Operators
Comparison Operators
Boolean Operators
Bitwise Operators
Compound Operators
Arduino programming Language