Project Based Summer Professional Training Course
Introduction to...
Arduino
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Introduction
Design, organize, and collaborate
Department of E & TC Engineering, VIT Pune Date:16-06-2017
What is microcontroller
It is a micro-computer. As any
computer it has internal CPU, RAM,
IOs interface.
It is used for control purposes, and
for data analysis.
Famous microcontroller
manufacturers are MicroChip,
Atmel, Intel, Analog devices, and
more.
[list]
Department of E & TC Engineering, VIT Pune Date:16-06-2017
What is microprocessor?
Department of E & TC Engineering, VIT Pune Date:16-06-2017
What is microcontroller?
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Why microcontroller and why not microprocessor?
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Electrical Circuits
• Hardware and software
• IoT devices combine
hardware and software
• Hardware interacts with the
physical world
• Software is the
“intelligence”
Hardware platforms for internet of things
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Implementation on…
• Arduino Uno
• Node MCU
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Quiz 1
• Internet of things components are harder to
design than traditional system because they
are designed for a specific hardware platform
– True
– False
What is Arduino?
A microcontroller board, contains on-board power supply,
USB port to communicate with PC, and
an Atmel microcontroller chip.
It simplify the process of creating any control system by
providing the standard board that can be programmed and
connected to the system without the need to any sophisticated
PCB design and implementation.
It is an open source hardware, any one can get the details of its
design and modify it or make his own one himself.
Arduino.
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Why Arduino?
• In-expensive (Less than Rs. 1000/-)
• Simple and easy to learn programming
• Controller independent programming
language
• One language compatibility with all boards
• Single software for programming, compiling
and burning the code
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Arduino boards:
UNO Mega LilyPad
Arduino BT Arduino Nano Arduino Mini
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Arduino UNO:
Digital output
~: PWM. In circuit Serial
0,1: Serial port. programming
Atmel
MicroController
USB port
Power input
Analog input.
Power Supply
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Features of the Arduino UNO:
• 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.
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Arduino Uno – Pin Diagram
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Arduino IDE
Install the IDE on your
development laptop
Link for setup will be
emailed to all
Opensource available on
Arduino website
Department of E & TC Engineering, VIT Pune Date:16-06-2017
The main features you need to know about are:
• Code area: This is where you will type all your
code
The Arduino IDE • Info panel: This will show any errors during
compiling or uploading code to your Arduino
• Verify: This allows you to compile your code to
code the Arduino understands. Any mistakes you
have made in the syntax of your code will be
show in the info pannel
• Upload: This does the same as verify but will
then send your code to your Arduino if the code
is verified successfully
• Serial Monitor: This will open a window that
allows you to send text to and from an Arduino.
We will use this feature in later lectures.
Department of E & TC Engineering, VIT Pune Date:16-06-2017
The Arduino IDE
By far one of the most valuable part of the
Arduino software is its vast library of example
programs. All features of the Arduino are
demonstrated in these.
Optional libraries usually add their own
examples on how to use them.
Arduino shields will often come with their
own libraries and therefore their own
examples.
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Basic Functions
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Basic Functions
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Sensors
• Allow the microcontroller to receive
information about the environment
– How bright is it?
– How loud is it?
– How humid is it?
– Is the button being pressed?
• Perform operations based on the state of
environment
• Turn on a light if its dark
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Digital or Analog?
All physical quantities are analog.
Analog : any value between its minimum and maximum.
Digital: specific levels of values with specific offset between
each other.
Digital and analog.
Ex: 1- Digital:
Lights in the room can be either on or off.
- Square waves are Digital.
Ex.: 2- Analog:
Temperature, can take any value[-1,12.8,25.002,… etc.].
- Sine waves are analog.
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Sensing the Environment
• Microcontrollers sense voltage
• digitalRead(pin) – returns state of a digital pin
• analogRead(Pin) – returns the analog voltage
on a pin
• Sensor logic must convert an environmental
effect into voltage
• Photosensor – light into voltage
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Project 1: Interfacing LED
Department of E & TC Engineering, VIT Pune Date:16-06-2017
LED Interfacing
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Current limits
• Watch out for current limits
• LED can only handle 20mA
– Be sure to use an appropriate resistor
– 330 ohm or 470 ohm
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Project 1: Interfacing LED
Department of E & TC Engineering, VIT Pune Date:16-06-2017
/*
Blink
Turns on an LED on for one second, then off for one
second, repeatedly.
*/
int ledPin = 9; // LED connected to digital pin 9
Department of E & TC Engineering, VIT Pune Date:16-06-2017
// the setup function runs once when you press
reset or power the board
void setup() {
// initialize digital pin ledPin as an output.
pinMode(ledPin, OUTPUT);
}
Department of E & TC Engineering, VIT Pune Date:16-06-2017
// the loop function runs over and over again forever
void loop() {
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Flashing Led
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Do it yourself
Task 1
• Using three LED’s mimic the effect of the
traffic signal.
Task 2
• Using multiple LED’s mimic the Diwali Lighting
effect.
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Arduino Traffic lights
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Arduino Traffic lights
//Traffic light in arduino UNO R3
int red = 10;
int yellow = 9;
int green = 8;
Department of E & TC Engineering, VIT Pune Date:16-06-2017
void setup() {
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
}
Department of E & TC Engineering, VIT Pune Date:16-06-2017
void loop() {
Write by yourself
Department of E & TC Engineering, VIT Pune Date:16-06-2017
void loop() {
// green off, yellow on for 3 seconds
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
delay(3000);
// turn off yellow, then turn red on for 5 seconds
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delay(5000);
// red and yellow on for 2 seconds (red is already on though)
digitalWrite(yellow, HIGH);
delay(2000);
// turn off red and yellow, then turn on green
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
delay(3000);
}
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Arduino Coding.
Stylize, edit, and animate your device
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Statement and operators:
Statement represents a command, it ends with ;
Ex:
int x;
x=13;
Operators are symbols that used to indicate a specific
function:
- Math operators: [+, -, *, /, %, ^]
- Logic operators: [==, !=, &&, ||]
- Comparison operators: [==, >, <, !=, <=, >=]
Syntax:
; Semicolon, {} curly braces, //single line
comment, /*Multi-line comments*/
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Statement and operators:
Compound Operators:
++ (increment)
-- (decrement)
+= (compound addition)
-= (compound subtraction)
*= (compound multiplication)
/= (compound division)
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Control statements:
If Conditioning:
if(condition)
{
statements-1;
…
Statement-N;
}
else if(condition2)
{
Statements;
}
Else{statements;}
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Control statements:
Switch case:
switch (var) {
case 1:
//do something when var equals 1
break;
case 2:
//do something when var equals 2
break;
default:
// if nothing else matches, do the default
// default is optional
}
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Loop statements:
Do… while:
do
{
Statements;
}
while(condition); // the statements are run at least once.
While:
While(condition)
{statements;}
for
for (int i=0; i <= val; i++){
statements;
}
Use break statement to stop the loop whenever needed.
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Code structure:
Void setup(){}
Used to indicate the initial values of system on starting.
Void loop(){}
Contains the statements that will run whenever the system is
powered after setup.
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Input and output:
Led blinking example:
Used functions:
pinMode();
digitalRead();
digitalWrite();
delay(time_ms);
other functions:
analogRead();
analogWrite();//PWM.
Department of E & TC Engineering, VIT Pune Date:16-06-2017
References…
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Arduino IDE:
You can download the Arduino IDE
(The program used to write code and
uploading it to arduino boards) from:
http://arduino.cc/en/Main/Software
Department of E & TC Engineering, VIT Pune Date:16-06-2017
Arduino Reference:
Here you can learn how to program Arduino and what each code
means and do, from here:
http://arduino.cc/en/Reference/HomePage
Department of E & TC Engineering, VIT Pune Date:16-06-2017
VLSI EGY- I.GEEK – S3Geeks
Thanks ☺