SKILL DEVELOPMENT PROGRAMME
ARDUINO
PROGRAMMING
Department of Electrical and Electronics Engineering
Mar Baselios College of Engineering and Technology, Trivandrum
SKILL DEVELOPMENT PROGRAMME
WHY THIS COURSE…?
Let us see the things happening around us
▪ Future Technology
▪ Amazon Warehouse
▪ Robotic Competitions
SKILL DEVELOPMENT PROGRAMME
WHY ARDUINO..?
▪ Open-source electronics platform
▪ Arduino boards are able to read inputs
and turn it into an output
▪ You can tell your board what to do by
sending a set of instructions to the
microcontroller on the board
SKILL DEVELOPMENT PROGRAMME
TECHNICAL SPECIFICATIONS
• Microcontroller: Microchip ATmega328P
• Operating Voltage: 5 Volt
• Input Voltage: 7 to 20 Volts
• Digital I/O Pins: 14 (of which 6 provide
PWM output)
• Analog Input Pins: 6
• DC Current per I/O Pin: 20 mA
• DC Current for 3.3V Pin: 50 mA
• Flash Memory: 32 KB of which 0.5 KB
used by bootloader
SKILL DEVELOPMENT PROGRAMME
ARDUINO TYPES
ARDUINO TYPES
Arduino MKR Zero - SAMD21 Cortex-M0+
Arduino YÚN - ATmega32U4
Arduino Uno - ATmega328P-PU Arduino Ethernet - ATmega328
Arduino Mega - ATmega 2560 Arduino Tian - Atheros AR9342
Arduino Nano - ATmega328P-AU Arduino Industrial 101 - Atheros AR9331
Arduino Leonardo - ATmega32u4 Arduino Leonardo ETH - ATmega32u4
Arduino 101 - Intel Curie Arduino MKR WAM 1300 - SAMD21 Cortex-M0+
Arduino Micro - ATmega32U4 Arduino MKR GSM 1400 - SAMD21 Cortex-M0+
Arduino Mini - ATmega328 Arduino Gemma - ATiny85
Arduino Zero - ATSAMD21G18 Arduino Lilypad Arduino USB - ATmega32u4
Arduino Due - AT91SAM3X8E Arduino Lilypad Arduino Main Board -
Arduino ADK - ATmega2560 ATmega168/ATmega328V
Arduino MO - ATSAMD21G18 Arduino Lilypad Arduino Simple - ATmega328P-AU
Arduino MO Pro - ATSAMD21G18 Arduino Lilypad Arduino Simple Snap - ATmega328P-AU
SKILL DEVELOPMENT PROGRAMME
PIN CONFIGURATION
• Analog Reference pin (orange)
• Digital Ground (light green)
• Digital Pins 2-13 (green)
• Digital Pins 0-1/Serial In/Out - TX/RX (dark green) -
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)
Arduino Uno pinout - Power Supply
There are 3 ways to power the Arduino Uno
▪ Barrel Jack - The Barrel jack, or DC Power Jack can
be used to power your Arduino board. The barrel jack
is usually connected to a wall adapter. The board can
be powered by 5-20 volts but the manufacturer
recommends to keep it between 7-12 volts . Above
12 volts, the regulators might overheat, and below 7
volts, might not suffice.
• VIN Pin - This pin is used to power the Arduino Uno
board using an external power source. The voltage
should be within the range mentioned above.
• USB cable - when connected to the computer,
provides 5 volts at 500mA.
Arduino Uno pinout - Power Supply
• 5v and 3v3 - They provide regulated 5 and 3.3v to
power external components according to
manufacturer specifications.
• GND - In the Arduino Uno pinout, you can find 5
GND pins, which are all interconnected.
The GND pins are used to close the electrical circuit and
provide a common logic reference level throughout your
circuit. Always make sure that all GNDs (of the Arduino,
peripherals and components) are connected to one
another and have a common ground.
• RESET - resets the Arduino
• IOREF - This pin is the input/output reference. It
provides the voltage reference with which the
microcontroller operates.
Arduino Uno Pinout - Analog IN
• The Arduino Uno has 6 analog pins, which utilize ADC (Analog to Digital converter).
• These pins serve as analog inputs but can also function as digital inputs or digital
outputs.
Analog to Digital Conversion
• ADC stands for Analog to Digital Converter. ADC is an electronic circuit used to
convert analog signals into digital signals. This digital representation of analog signals
allows the processor (which is a digital device) to measure the analog signal and use it
through its operation.
• Arduino Pins A0-A5 are capable of reading analog voltages. On Arduino the ADC has
10-bit resolution, meaning it can represent analog voltage by 1,024 digital levels. The
ADC converts voltage into bits which the microprocessor can understand.
• One common example of an ADC is Voice over IP (VoIP)
Arduino Uno Pinout - Digital Pins
• Pins 0-13 of the Arduino
Uno serve as digital
input/output pins.
• Pin 13 of the Arduino Uno
is connected to the built-in
LED.
• In the Arduino Uno - pins
3,5,6,9,10,11 have PWM
capability.
It’s important to note that:
● Each pin can
provide/sink up to 40 mA
max. But the recommended
current is 20 mA.
What does digital mean?
• Digital is a way of representing voltage in 1 bit: either 0 or 1. Digital pins on
the Arduino are pins designed to be configured as inputs or outputs according
to the needs of the user. Digital pins are either on or off. When ON they are in
a HIGH voltage state of 5V and when OFF they are in a LOW voltage state of
0V.
• On the Arduino, When the digital pins are configured as output, they are set to
0 or 5 volts. When the digital pins are configured as input, the voltage is
supplied from an external device. This voltage can vary between 0-5 volts
which is converted into digital representation (0 or 1). To determine this, there
are 2 thresholds:
● Below 0.8v - considered as 0.
● Above 2v - considered as 1.
SKILL DEVELOPMENT PROGRAMME
Arduino IDE
Open your
Start AND Connect Arduino UNO Board Succes
Online Arduino Editor : https://create.arduino.cc/
WRITE SOMETHING HERE
Arduino IDE
Start Succes
SPECIAL PIN FUNCTIONS
Each of the 14 digital pins and 6 Analog pins on the Uno can be used as an input
or output, using pinMode(),digitalWrite(), and digitalRead() functions.
The Uno has 6 analog inputs, labeled A0 through A5
Variable declaration types
int
Integers are the primary data type for storage of numbers without decimal points and stores a
16 bit value with a range of 32767 to -32768.
E g: int variableName=1500;
long
Extended size data type for long integers, without decimal points, stored in 32 bit value with a
range of 2147483647 to -2147483648.
long variableName=90000;
Float
A data type for floating point numbers or numbers having decimal points. Floating point
numbers having greater resolution than integers and are stored as 32 bit value with a range of
3.4028235E+38 to -3.4028235E+38
float variableName=3.14;
Special Functions
pinMode()
Description
Configures the specified pin to behave either as an input or an output. See the Digital Pins
page for details on the functionality of the pins.
Syntax
pinMode(pin, mode);
Parameters
pin: the Arduino pin number to set the mode of.
mode: INPUT, OUTPUT
Eg: pinMode(4, INPUT);
It assigns pin no. 4 as INPUT which reads data
digitalRead()
Reads the value from a specified digital pin, either HIGH or LOW.
Syntax
digitalRead(pin);
Parameters
pin: the Arduino pin number you want to read
Returns
HIGH or LOW
digitalWrite()
Description
Write a HIGH or a LOW value to a digital pin.
If the pin has been configured as an OUTPUT with pinMode(),
Example
void setup() {
pinMode(13, OUTPUT); // sets the digital pin 13 as output
}
void loop() {
digitalWrite(13, HIGH); // sets the digital pin 13 on
delay(1000);
}
analogRead()
Description
Reads the analog value from the specified analog pin (A0-A5)
Syntax
analogRead(pin);
Parameters
pin: the name of the analog input pin to read from (A0 to A5)
analogRead(A3);
analogWrite()
Description
• Writes an analog value (PWM wave) to a pin.
• Can be used to light a LED at varying brightnesses or drive a motor at various speeds.
Syntax
analogWrite(pin, value);
Eg: analogWrite(ledPin, value / 4);
delay()
Description
Pauses the program for the amount of time (in milliseconds) specified as parameter. (There are 1000
milliseconds in a second.)
Syntax
delay(time that you want to delay in ms);
Eg:
delay(500);
This provides a delay of 500ms
delayMicroseconds()
Description
Pauses the program for the amount of time (in microseconds) specified as parameter.
Syntax
delayMicroseconds(time that you want to delay in ms)
Eg:
delay(500);
This provides a delay of 500microseconds
SKILL DEVELOPMENT PROGRAMME
LED blinking
Start Succes
Programming Language Reference : https://www.arduino.cc/reference/en/
SKILL DEVELOPMENT PROGRAMME
LED blinking
pinMode(LED_BUILTIN, OUTPUT);
Start Succes
digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(LED_BUILTIN, LOW);
SKILL DEVELOPMENT PROGRAMME
LED blinking
Start Succes
SKILL DEVELOPMENT PROGRAMME
RGB LED
Start Succes
SKILL DEVELOPMENT PROGRAMME
LED blinking
Start Succes
SKILL DEVELOPMENT PROGRAMME
LED Array
Try it yourself…..
Start Succes
How many different patterns you can make…?
SKILL DEVELOPMENT PROGRAMME
Potentiometer
Start Succes
SKILL DEVELOPMENT PROGRAMME
Potentiometer
Start Succes
Try to adjust the brightness of an LED……..
This example demonstrates the use of the analogWrite() function in fading an LED off and on. AnalogWrite
uses pulse width modulation (PWM), turning a digital pin on and off very quickly with different ratio between on and
off, to create a fading effect.
Hardware Required
•Arduino board
•LED
•220 ohm resistor
•hook-up wires
•breadboard
Circuit
Connect the anode (the longer, positive leg) of your LED to digital output pin 9 on your board through a 220 ohm
resistor. Connect the cathode (the shorter, negative leg) directly to ground.
• Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means. Digital
control is used to create a square wave, a signal switched between on and off.
• This on-off pattern can simulate voltages in between the full Vcc of the board (e.g., 5 V on UNO, 3.3 V
on a MKR board) and off (0 Volts) by changing the portion of the time the signal spends on versus the
time that the signal spends off.
• The duration of "on time" is called the pulse width. To get varying analog values, you change, or
modulate, that pulse width.
• If you repeat this on-off pattern fast enough with an LED for example, the result is as if the signal is a
steady voltage between 0 and Vcc controlling the brightness of the LED.
Code
After declaring pin 9 to be your ledPin, there is nothing to do in the setup() function of your code.
The analogWrite() function that you will be using in the main loop of your code requires two
arguments: One telling the function which pin to write to, and one indicating what PWM value to
write.
In order to fade your LED off and on, gradually increase your PWM value from 0 (all the way off) to
255 (all the way on), and then back to 0 once again to complete the cycle. In the sketch below, the
PWM value is set using a variable called brightness. Each time through the loop, it increases by the
value of the variable fadeAmount.
If brightness is at either extreme of its value (either 0 or 255), then fadeAmount is changed to its
negative. In other words, if fadeAmount is 5, then it is set to -5. If it's -5, then it's set to 5. The next
time through the loop, this change causes brightness to change direction as well.
analogWrite() can change the PWM value very fast, so the delay at the end of the sketch controls
the speed of the fade. Try changing the value of the delay and see how it changes the fading effect.
SKILL DEVELOPMENT PROGRAMME
Seven Segment LED
Start Succes
SKILL DEVELOPMENT PROGRAMME
PIR Sensor
Start Succes
SKILL DEVELOPMENT PROGRAMME
PIR Sensor
Start Succes
SKILL DEVELOPMENT PROGRAMME
Buzzer
Start Succes
SKILL DEVELOPMENT PROGRAMME
Buzzer
Start Succes
SKILL DEVELOPMENT PROGRAMME
Intruder Detector
Try to make an intruder detector………
Start Succes
SKILL DEVELOPMENT PROGRAMME
Ultrasonic Sensor
Start Succes
SKILL DEVELOPMENT PROGRAMME
Step 1 : Definition
#define echoPin 8
Ultrasonic Sensor #define trigPin 9
long duration;
int distance;
Start Step – 2 : Setup Succes
void setup(){
Serial.begin(9600);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
}
SKILL DEVELOPMENT PROGRAMME
Step 3 : Clearing trigpin
digitalWrite(trigPin, LOW);
Ultrasonic Sensor delayMicroseconds(2);
Start Step – 4 : Pulse Generation Succes
digitalWrite(trigpin,HIGH);
delayMicroseconds(10);
digitalWrite(trigpin,LOW);
distance=(duration*0.034/2);
SKILL DEVELOPMENT PROGRAMME
Step 5 : Calculating duration
duration=pulseIn(echoPin,HIGH);
Ultrasonic Sensor
Start Step – 6 : Distance Calculation Succes
distance=(duration*0.034/2);
distance=(duration*0.034/2);
SKILL DEVELOPMENT PROGRAMME
Step 5 : Calculating duration
duration=pulseIn(echoPin,HIGH);
Ultrasonic Sensor
Start Step – 6 : Distance Calculation and Serial Succes
printing
distance=(duration*0.034/2);
Serial.print("Distance: ");
Serial.println(distance);
Serial.print(" cm ");
SKILL DEVELOPMENT PROGRAMME
IR Sensor Module
Start Succes
SKILL DEVELOPMENT PROGRAMME
Let us control a D C Motor……
Start Succes
SKILL DEVELOPMENT PROGRAMME
Motor Driver
Start Succes
SKILL DEVELOPMENT PROGRAMME
Relay
Start Succes
SKILL DEVELOPMENT PROGRAMME
Relay
Start Succes
SKILL DEVELOPMENT PROGRAMME
LCD Display
Start Succes
SKILL DEVELOPMENT PROGRAMME
LCD Display
Start Succes
LCD Display Pin1(Vss):Ground pin of the LCD module.
Pin Description
Pin2(Vcc): Power to LCD module (+5V supply is given to this pin)
Pin3(VEE):Contrast adjustment pin. This is done by connecting the
ends of a 10K potentimeter to +5V and ground and then connecting
the slider pin to the VEE pin. The voltage at the VEE pin defines the
contrast. The normal setting is between 0.4 and 0.9V.
Pin4(RS):Register select pin.The JHD162A has two registers namely
command
Start Succes
register and data register. Logic HIGH at RS pin selects data register
and logic LOW at RS pin selects command register. If we make the
RS pin HIGH and feed an input to the data lines (DB0 to DB7), this
input will be treated as data to display on LCD screen. Pin5(R/W):
Read/Write modes. This pin is used for selecting between read and
write modes. Logic HIGH at this pin activates read mode and logic
LOW at this pin activates write mode.
LCD Display
Pin Description
LCD Display
Pin Description Pin6(E): This pin is meant for enabling the LCD module. A HIGH to
LOW signal at this pin will enable the module.
Pin7(DB0) to Pin14(DB7): These are data pins.
Pin15(LED+): Anode of the back light LED. When operated on 5V, a
Start Succes
560 ohm resistor should be connected in series to this pin. In arduino
based projects the back light LED can be powered from the 3.3V
source on the arduino board.
Pin16(LED-): Cathode of the back light LED.
#include <LiquidCrystal.h>
Programming LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2);
Start lcd.print("hello, world!"); Succes
}
void loop() {
}
)
#include <LiquidCrystal.h>
// LiquidCrystal(RS, E, D4, D5, D6, D7
Programming
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2);
Start lcd.print("hello, world!"); Succes
}
void loop() {
}
LCD
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Display Options void setup() {
lcd.begin(16, 2);
1. lcd.clear()
}
void loop() {
lcd.print("hello, world!");
Start delay(500); Succes
lcd.clear();
delay(500);
}
LCD #include <LiquidCrystal.h>
Display Options LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
2. lcd.home() {
lcd.begin(16, 2);
lcd.print("hello, world!");
}
Start Succes
void loop()
{
lcd.home();
lcd.print("XXX");
}
LCD #include <LiquidCrystal.h>
Display Options LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
3. lcd.setCursor() lcd.begin(16, 2);
lcd.setCursor(2, 1);
lcd.print("hello, world!");
}
Start Succes
void loop() {
}
LCD #include <LiquidCrystal.h>
Display Options
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
4. lcd.cursor() void setup() {
lcd.begin(16, 2);
lcd.print("hello, world!");
}
Start Succes
void loop() {
lcd.cursor();
delay(500);
lcd.noCursor();
delay(500);
}
#include <LiquidCrystal.h>
LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Display Options
void setup() {
lcd.begin(16, 2);
5. lcd.setCursor() lcd.print("hello, world!");
}
Start void loop() { Succes
lcd.setCursor(12, 1);
lcd.cursor();
delay(500);
lcd.setCursor(12, 1);
lcd.noCursor();
delay(500);
}
#include <LiquidCrystal.h>
LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Display Options
void setup() {
lcd.begin(16, 2);
6. lcd.display(); lcd.print("hello, world!");
}
Start void loop() { Succes
lcd.display();
delay(500);
lcd.noDisplay();
delay(500);
}
LCD #include <LiquidCrystal.h>
Display Options LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2);
7. lcd.scrollDisplayLeft() lcd.print("hello, world!");
}
Start Succes
void loop() {
lcd.scrollDisplayLeft();
delay(1000);
}
LCD #include <LiquidCrystal.h>
Display Options LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
lcd.begin(16, 2);
8. lcd.autoscroll() }
void loop() {
Start Succes
lcd.setCursor(0, 0);
lcd.autoscroll();
lcd.print("ABC");
delay(500);
}
The circuit is so simple and small , there is only few connection to be made
Arduino Pins Bluetooth Pins
Bluetooth Module RX (Pin 0) ———-> TX
TX (Pin 1) ———-> RX
5V ———-> VCC
GND ———-> GND
Start Succes
Connect a LED negative to GND of arduino and positive to pin 13 with a
resistance valued between 220Ω – 1KΩ. And your done with the circuit
SKILL DEVELOPMENT PROGRAMME
Start Succes
MIT App Inventor
Designer
SKILL DEVELOPMENT PROGRAMME
App Inventor
Block editor
Start Succes
SKILL DEVELOPMENT PROGRAMME
App Inventor
Block editor
Start Succes
SKILL DEVELOPMENT PROGRAMME
MIT App Inventor 2
Start Succes
Robotics: Robots are playing a major role in manufacturing industries for assembling,
Transportation etc. Hence one should use Arduino if he/she is planning to make a
prototype in these areas.
Monitoring Devices: There are several applications in mechanical engineering exists,
where we need to monitor any parameters via sensors like Temperature of coils, Fluid
levels, Pressure etc, In that case Arduino comes into play. Similarly, in several projects
like automatic vending machines, bar cutting and feeding machines Arduino can be
programmed to control the pneumatic motions or valves etc.
Aero-modelling/ UAV applications: Arduino can be used in UAV aircrafts or drones for
several control and measurement applications.
Thermal / Refrigeration: Automatic control panels of Thermal / Refrigeration units can
be programmed by using Arduino for applications such as Heat exchanger temperature
monitoring, Refrigeration parameter monitoring etc.