0% found this document useful (0 votes)
228 views

Lab-1 Arduino PDF

This document outlines an agenda for basic Arduino training over 8 modules. Module 1 introduces Arduino, including its history and boards like the Arduino Uno. It also covers setting up the Arduino IDE and creating a basic blink project. Module 2 covers basic C programming constructs like conditionals, loops, operators and functions. Further modules discuss Arduino programming, shields, libraries, interfacing with Processing, and building IoT projects.

Uploaded by

NIKHIL ARORA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
228 views

Lab-1 Arduino PDF

This document outlines an agenda for basic Arduino training over 8 modules. Module 1 introduces Arduino, including its history and boards like the Arduino Uno. It also covers setting up the Arduino IDE and creating a basic blink project. Module 2 covers basic C programming constructs like conditionals, loops, operators and functions. Further modules discuss Arduino programming, shields, libraries, interfacing with Processing, and building IoT projects.

Uploaded by

NIKHIL ARORA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 73

Basic Arduino Training

Internal research group training


Dr. Vinay Chamola, Assistant Professor, EEE Department, BITS-Pilani
EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 1
Agenda
Module 1: Introduction to Arduino
− What is Arduino
− History of Arduino
− Arduino Boards
− Arduino Uno
− Setting Up Arduino IDE
− Your First Arduino Project

Module 2: Basic C Programming


− Conditional
− Loop
− Operators
− Function
− Comment
− Preprocessor

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 2


Agenda
Module 3: Arduino Programming
−Components & Ohm's Law
−pinMode
−digitalWrite
−analogWrite
−Serial Communication
−digitalRead
−analogRead & Map
−Challenge 1: Digital Read/Write
−Challenge 2: Analog Read/Write
−tone

Module 4: Arduino Shields


- Motor Shield
- Ethernet Shield
- WiFi Shield

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 3


Agenda
Module 5: Arduino Standard Libraries
- EEPROM
- Ethernet
- Firmata
- Liquid Crystal Display
- Servo
- SPI
- SoftwareSerial
- Stepper
- WIFI
- Wire
- Install Additional Libraries

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 4


Agenda
Module 6: Introduction to Processing
- Install Processing
- Basics of Processing
- Interface Processing with Arduino

Module 7: Arduino Sonar Project


- Ultrasonic Ranging Sensor
- Servo Motor
- Building a Sonar System

Module 8: Arduino IoT

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 5


Module 1
Introduction to Arduino

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 6


What is Arduino?
www.arduino.cc

● Arduino is an open-source electronics platform


● The hardware and software are open source.
● Software code, based on C is transferable.
● Large community for Arduino.
EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 7
History of Arduino

Arduino was started in 2005 by Massimo Banzi and other co-founders


from Interaction Design Institute Ivrea (IDII) in Ivrea, Italy. It was
named after the bar where the co-founders visited often. The name
of the bar is named after King Arduin.
EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 8
Arduino Products

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 9


Arduino Boards
Lilypad Nano Micro Mini Pro

Mega Leonardo Due Yun

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 10


Arduino Uno
Digital Input/Output & PWM

Reset Button

Power LED
USB

TX & RX LEDs On board LED

Microcontroller

Power Plug

Power 5V/GND Analog Inputs


Microcontroller: ATmega328 Operating Voltage: 5V
Digital I/O Pins: 14 (6 PWM output) Analog Input Pins :6
Flash Memory: 32 KB (ATmega328) Clock Speed: 16 MHz

PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.
LED: 13. There is a built-in LED connected to digital pin 13.
EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 11
Download Arduino IDE
http://www.arduino.cc/download

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 12


Installing Driver on Window
Goto Device Manager Locate Driver Location

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 13


Setup Arduino IDE
Select the Board : Tools->Board->Arduino Uno
Select the Port: Tools->Port -> COM3 (Window)

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 14


Arduino Communication Ports

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 15


Navigate Arduino IDE

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 16


Blink Project
● Open File->Example->
0.1Basic->Blink
● Click the upload button
● Observe the LED blink
● Change the delay value to
100
● Click the upload button
● Observe the LED blink
● Change the delay value to
2000
● Click the upload button
● Observe the LED blink

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 17


Module 2
Basic C Programming

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 18


Conditional

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 19


if Statement

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 20


if Syntax

if (condition)
{
// do something here
}

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 21


if Statement Example
if (x > 120) {
digitalWrite(LEDpin1, HIGH);
digitalWrite(LEDpin2, HIGH);
}

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 22


if-else Statement

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 23


if-else Syntax
if (condition)
{
// action A
}
else
{
// action B
}

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 24


If-else Statements
if (x > 120) {
digitalWrite(LEDpin1, HIGH);
digitalWrite(LEDpin2, HIGH);
} else {
digitalWrite(LEDpin1, LOW);
digitalWrite(LEDpin2, LOW);
}

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 25


if-else-if Syntax
if (condition) {
do Something;}
else if (condition2) {
do Something Else;}
else {
do Another Thing;}

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 26


if-else-if Example
if (x > 120) {
digitalWrite(LEDpin1, HIGH);
digitalWrite(LEDpin2, HIGH);
} else if (x > 200) {
digitalWrite(LEDpin1, LOW);
digitalWrite(LEDpin2, HIGH);
} else {
digitalWrite(LEDpin1, LOW);
digitalWrite(LEDpin2, LOW);
}

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 27


Switch Syntax
switch (var) {
case label:
// statements
break;
case label:
// statements
break;
default:
// statements
break;
}

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 28


Switch Example
char grade = 'B';
switch(grade)
{
case 'A' :
printf("Excellent!\n" );
break;
case 'B' :
case 'C' :
printf("Well done\n" );
break;

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 29


Goto Syntax
label:

goto label;

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 30


Goto Example
for(byte r = 0; r < 255; r++) {
if (analogRead(0) > 250) { goto bailout;}
}

bailout:

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 31


Loop

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 32


While Loop Statement

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 33


While Loop Syntax
while(expression) {
// statement(s)
}

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 34


While Loops Examples
int i = 10;
while ( i > 0 ) {
printf("Hello %d\n", i );
i = i - 1;
}

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 35


Do While Loop Statement

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 36


Do While Loops Syntax
do
{
// statement block
} while (test condition);

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 37


Do While Loops Examples
do{
delay(50);
x = readSensors();
} while (x < 100);

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 38


For Loop Statement

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 39


For Loops Syntax
for (initialization; condition; increment) {
//statement(s);
}

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 40


For Loops Example
for (int i=0; i <= 255; i++){
analogWrite(PWMpin, i);
delay(10);
}

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 41


Break
for (x = 0; x < 255; x ++) {
analogWrite(PWMpin, x);
sens = analogRead(sensorPin);
if (sens > threshold) {
x = 0;
break;
}
delay(50);
}

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 42


Continue
for (x = 0; x < 255; x ++) {
if (x > 40 && x < 120){
continue;
}

analogWrite(PWMpin, x);
delay(50);
}

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 43


Operators

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 44


Arithmetic Operators

= (assignment operator)
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
% (modulo)

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 45


Comparison Operators

== (equal to)
!= (not equal to)
< (less than)
> (greater than)
<= (less than or equal to)
>= (greater than or equal to)

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 46


Boolean Operators
&& (and)
|| (or)
! (not)

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 47


Compound Operators
++ (increment)
-- (decrement)
+= (compound addition)
-= (compound subtraction)
*= (compound multiplication)
/= (compound division)
%= (compound modulo)
&= (compound bitwise and)
|= (compound bitwise or)

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 48


Function

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 49


Function Example
int checkSensor()

{
if (analogRead(0) > 400) {
return 1;
else{
return 0;
}
}

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 50


Comment

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 51


Comment

Single line comment


// ….
Multiple lines comment
/*
…..
*/

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 52


Preprocessor

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 53


#define

#define Name value


#define ledPin 3

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 54


#include

#include <Wire.h>

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 55


Module 3
Arduino Programming

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 56


Electrical Components

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 57


Solderless Breadboard

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 58


Solderless Breadboard
Prototyping without soldering

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 59


LED
● Light-emitting Diode
● Pasess current one way
● Emits Lights
● spec of current threshold : 20mA

Anode + Cathode -

Cathode - Anode +

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 60


Resistor

Color code represent the resistance value

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 61


Resistor Color Code

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 62


Push Button

Press to Turn On
Release to Turn Off

Generate Digital Input

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 63


Potentiometer

Variable Resistor

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 64


Ohm's Law

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 65


Basic Concept: Ohm's Law

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 66


Applying Ohm's Law to LED

Voltage across LED is 2V


Voltage across R1 resistor is 5V
Maximum current for LED is 0.02A
5V

R= 5V/0.02A= 250Ω

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 67


Arduino Program Structure

Define variables here

Define INPUT/OUTPUT Pins here Sketch = Program =


Source Code

Create your main program here

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 68


Pin Setup

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 69


PinMode Syntax

pinMode(pin, INPUT/OUTPUT)

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 70


Digital Output

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 71


digitalWrite
Syntax:
digitalWrite(pin, HIGH/LOW)

Eg
digitalWrite(9,HIGH)

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 72


delay
Pauses the program for the amount of
time (in miliseconds) specified as
parameter

Syntax
delay(ms)

EEE F411, IoT course, Dr. Vinay Chamola, BITS-Pilani 73

You might also like