Arduino
Arduino
Black
Brown
Reset button
ICSP for
USB interface
- Pin-13 LED
-
ATmegal2s
RESET
microcontroller IC
1CSP for Scx
ATmega328 MISO
ATMega328P Microcontroller
ATmega328P pin mapping
OO Arduino function Arduino function OO
reset PC6 1 w PCS analog input 5
el Embedded Sysfems
Wreless Routen QW3 rioyer
' .
et gl
edane Vg 161 0 Mege X
¢ iia®
Communication: 12C, SPI
. & § 1 § &
Sv
Ov
25% Dury Cycle - analogWrite(64)
M i
Sv
Oov
50% Duty Cycle - analogWrite(127)
Sv
Oov
Ov
[
Sv
Ov
Different Arduino Boards
» Arduino Uno
» Arduino Leonardo
» Arduino LilyPad
» Arduino Mega
» Arduino Nano
» Arduino Mini
» Arduino Mini Pro
» Arduino BT
» Arduino Due
Different Arduino Shields
» Data Logger ot
»,
-
» Motor/Servo Shield
e
» Ethernet Shield e s
Verify
o Sy
Upload
New
Open
Save
B R
Serial Monitor
Sketch Name
Code Area
Message Area
Text Console
-
Board & Serial Port
=
Setting Up of Arduino IDE
Step 1
Settings: Tools = Board - Arduino Uno » The computer
communicates
e sketchjun17a | Arduino 105, ATomeS (etemal 20 Mt dock) ;
T ATy itemal 1 Mz lock to the Arduino
ATtiny44 (internal 8 MHz clock)
mfi i St H
n?lcrocoqtrloller
e ATtiny34 (intemal 1 MHz clock) via a serial port
‘ ATtiny4 Gesmal 8 iz cock through a USB-
o SN o ot 20 M cock) .
o Serial adapter.
T L Adino w/ ATmega28
R —— Arduino Diecimila or Duemdanove w/ ATmega 168
Serl Pot [ B » Check to make
Programmer Y Auduino
Nano w/ ATmega1é3 sure that the
Bum Bootloader Arduino Mega 2560 or Mega ADK dl'ivers are
Arduine
Mega (ATmega1280)
Asduine Lecnardo Pmperly
Arduino Esplora installed.
Step 2
Settings: Tools = Settings: Tools - Serial Port > COM#(Arduino Uno)
=00———
Arduino Sketch Structure
@ sketch_nov29s
[ Arduino 106 =
File Edit Sketch Tools Help
P “ void setup()
Will be executed only when
the program begins (or reset
e button is pressed)
void loop()
Will be executed repeatedly
Arduino Program Development
Cchar 1 o
Cint 2 -32768 767 i
H pinMode(9, OUTRPUT);
Input or Output
void loop() 2
{ void loop() {
digitalWrite(ledPin, HIGH); Port # from setup
LED ON
delay(1000): //Wait 1000ms (=1s)
digitalWrite(9, HIGH);
digitalWrite(ledPin, LOW); delay(1000);
JLED OFI digitalWrite(9, LOW);
delay(1000); //Wait 1000ms (=1s) delay(1000); Turn the LED on
N or off
. 7 } Wait for 1 second
or 1000 milliseconds
Sensor
What is a sensor?
» A device that receives a stimulus and responds with an
electrical signal.
» A special type of transducer, device that converts one type of
energy into another
Physical quantities
2y W
Protein Bacteria
Common Sensors
» Mechanical
» Accelerometers
» Gyroscopes
» Optical
» Photo Detectors
» Infrared
» Semiconductor
» Gas
» Temperature
» Magnetic
Sensor Characteristics
» Range
» Accuracy
» Transfer Function
» Sensitivity
» Error
Actuators
» Device that turns energy (typically electrical) to motion.
» An actuator is a component of a machine that is responsible
for moving and controlling a mechanism or system, for
example by opening a valve. In simple terms, it is a "mover".
» An actuator requires a control signal and a source of energy.
Features:
» Force
» Speed
» Torque
» Power
» Efficiency
A “Q'.C‘,’
.y Activities Ty
eyvre——.
;E
Indicators, small dsplays
IIIummuon
amusement, misc. other
- Longlegg| | Lo
re .B
.Automotive - -
Signs and Displays
| . Al
Circuit Connections
D=
L o 4700
g z LED
I\
Ground (GNDY -
Code & Explanation
/*LED Blink Experiment */
void setup(){
pinMode(led, OUTPUT): // Initialize the digital pin as an output
|
1 VVV 3
T Applications:
2
» Controllers
» Audio Systems
» Measuring Devices
» Tuners & Calibrators
Circuit Connections
Code & Explanation
/* Program to control LED by varying the pulse width */
void setup() {
pinMode(ledPin, OUTPUT); // declare ledPin13 as an
OUTPUT
}
void loop() {
val = analogRead(potPin); // read pot voltage as integer
digital Write(ledPin, HIGH); // turn the ledPin on
delay(val); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off
delay(val); // stop the program for some time
i
Activity 3 : Push Button Switch
Switch
» A switch is an electrical component that can "make" or "break" an
electrical circuit, interrupting the current or diverting it from one conductor
to another.
» The mechanism of a switch removes or restores the conducting path in a
circuit when it is operated.
» It may be operated manually, for example, a light switch or a keyboard
button, may be operated by a moving object such as a door, or may be
operated by some sensing element for pressure, temperature or flow.
J— -
Tt psaatly € e teed
S
e ity € oanneoing
tnresnally € cnnested
5 = @
P
Trte
s mabiy € e il
‘- ®, L.
19°0° 1) q onnnecrione
- Ui} - il >
|
il| LU
U
R B
I I )
Cre e LA
I B A
e |R A
| 0
L ) l.l%l&'ll'..l.
too’og‘"notooo
L 1 1 e R R
LU I L A R I
LR L
AR AR R RN R R AN
Code & Explanation
// Program for Push Button with LED void loop()
{
// set pin numbers: buttonState =
const int buttonPin = 7; // Pushbutton pin digitalRead(buttonPin);
const int ledPin = 9; /' LED pin // read the state of the pushbutton value
for Interrupt Service Routine. This is where the program jumps to whenever
there is an interrupt.
}"°id loop(){ » Arduino Uno Digital Pins: 2 & 3 usable for interrupts
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUPY);
attachInterrupt(digital PinToInterrupt{interruptPin), blink, CHANGE); #Interrupt
}
void loop() {
digitalWrite(ledPin, state);
}
void blink() { HISR
state = !state;
—
Activity 4 : Controlling an RGB LED
RGB LED
» RGB LED means Red, Blue and Green Light Emitting Diode.
» By configuring the intensity of each LED, other colours can be produced.
There are two kinds of RGB LEDs: common anode LED and common
cathode LED.
N N
Circuit Connections
Code & Explanation
/* Program to control RGB delay(1000); setColor(0, 255, 255);
LED ¥/ setColor(0, 255, 0); / // aqua
green delay(1000);
int redPin = 11;
H
int greenPin = 10; delay(1000);
int bluePin =9; setColor(0, 0, 255); // Void setColor(int red, int
blue green, int blue)
void setup() delay(1000); {
{ analogWrite(redPin, red);
pinMode(redPin, OUTPUT); // Next, we also get some analogWrite(greenPin,
pinMode(greenPin, secondary colours! green);
OUTPUT); analogWrite(bluePin,
pinMode(bluePin, OUTPUT); setColor(255, 255, 0); / blue);
| vellow )
delay(1000);
void loop() setColor(80, 0, 80); //
purple
i
setColor(255, 0. 0): //red delay(1000);
Activity 5 : Piezo Buzzer
Piezo Buzzer
I
- A buzzer or beeper is an audio signalling device, which may be mechanical,
electromechanical, or piezoelectric (piezo for short).
> Typical uses of buzzers and beepers include alarm devices, timers, and confirmation
of user input such as a mouse click or keystroke.
- Whenever an electric potential is applied across a piezoelectric material, a pressure
variation is generated. A piezo buzzer consists of piezo crystals in between two
conductors. When a potential difference is applied across these crystals, they push
one conductor and pull the other conductor by their internal property. The
continuous pull and push action generates a sharp sound wave.
Ac Voltage Applies
void loop() {
/*Tone needs 2 arguments, but can
take three
1) Pint#
2) Frequency - this is in hertz (cycles
per second) which determines the pitch
of the noise made
Activity 6 : LCD Display
LCD
» LCD (Liquid Crystal Display) is a type of flat panel display which uses liquid
crystals in its primary form of operation.
» LCDs have a large and varying set of use cases for consumers and businesses, as
they can be commonly found in smartphones, televisions, computer monitors and
instrument panels.
EEUPEISERNEERAR Gy
12C Bus
To Ardiuno or Raspberry port
» 12C stands for Inter Integrated Circuit
» A 12C bus is a bidirectional two-wired HD44780 compatible
serial bus which is used to transport the data 18 Pin connecter
between integrated circuits.
solder pad
LCD backlight address select
_——
Circuit Connections
- al LOoOurTnpuy —
NO -—
*axd>2
E B mMRar YVARYIN =
8 ~Seld txz 8 8,
Code & Explanation
//Program for LCD Display with 12C // Print a message to the LCD.
Bus [Link]();
[Link](2,0);
#include <Wire.h> [Link]("Hello Everyone");
#include <LiquidCrystal 12C.h> [Link](2,1);
[Link]("Welcome To DIC");
LiquidCrystal_12C led(0x27,20,4); /
—
set the LCD address to 0x27for a 16
chars and 2 line display
void loop()
void setup() {
{
[Link](); // initialize the
led
[Link]();
Activity 7 : Alphanumeric Keypad
Alphanumeric Keypad
» An alphanumeric keypad is a keyboard that contains both numbers and
letters on the same keys.
» Typically, they are found on telephones and cellular phones.
¥ T W .
Circult connectons
_UIIIICL
Code & Explanation
/* Program for Using Keypad with Arduino */ Keypad(makeKeymap(keymap), rPins, cPins, .
Rows, Cols):
#include <Keypad.h>
#include <Wire.h>
void setup()}
const byte Rows= 4;
[Link](9600); // serial monitor
//mumber of rows on the keypad i.e. 4
const byte Cols= 4; ]
//If key is pressed, this key is stored in
'keypressed' variable’
char keymap[Rows][Cols]=
//1f key is not equal to 'NO_KEY", then this
{ key is printed out
{III‘ '2!, I3I'IAI} 5
{'4,'s','6''B'},
{371’ '8., |9D,'Cl}‘ void loop() //main program
{l‘l' lol. C#'.lD', {
char keypressed = [Link]();
1 if (keypressed != NO_KEY)
//a char array is defined
byte rPins[Rows]= {9,8,7.6}; {
[Link](keypressed); // write this string on
//Rows 0 to 3
the top row
byte cPins[Cols]= {5,4.3,2};
/IColumns 0 to 3 H
/I command for library for keypad |
Keypad kpd=
Activity 8 : HC-05 Bluetooth Module
Bluetooth
7 Bluetooth is a wireless technology standard for exchanging data between
fixed and mobile devices over short distances using short-wavelength UHF
radio waves in the industrial, scientific and medical radio bands, from 2.400
to 2.485 GHz, and building personal area networks (PANs).
» It was originally conceived as a wireless alternative to RS-232 data cables.
void setup(){
[Link](9600);
[Link]("Enter AT commands:");
[Link](38400); // HC-05 default speed in AT command more
}
void loop(){
if ([Link]()) // read from HC-05 and send to Serial Monitor
[Link]([Link]()):
if ([Link]()) // Keep reading from Serial Monitor and send to HC-05
[Link]([Link]());
}
P L
4 (\T",\T':/l/,\.[l“‘\f'
1L 1L Uil L LAURRS
Bluetooth Terminal App
Download & Install Bluetooth -
Terminal App Sa—
[Link] Iui sve
details?id=[Link] s
Tre BRUTOR Bltoces
nal&hl=en IN R
Open the app and pair the HC-05 P
module to your mobile. The
password is: 1234 (default)
» Then select the Byte Stream mode ==
out of the three modes that appear.
Send “1” to ON the LED and “0” PSR i
to OFF the LED. ert._&-+()/
Thus the LED on the Arduino can - it @
be controlled by the App through ., 3 ®
Bluetooth.
Code & Explanation
/* Program to interface Bluetooth digitalWrite(ledpin,HIGH);
Module with Arduino */ [Link]("LED On!");
H
#include <SoftwareSerial.h>
else if (Data=='0"){
SoftwareSerial mySerial(3, 2); digitalWrite(ledpin,LOW);
int ledpin=13; [Link]("LED Off!");
int Data; |
}
void setup() {
[Link](9600);
pinMode(ledpin,OUTPUT);
H
void loop(){
if ([Link]()){
Data=[Link]();
if(Data=="1"){