You are on page 1of 49

Workshop on Arduino

What is Arduino

What is Arduino?
“Arduino is an open-source electronics prototype platform based on flexible, easy-to-use hardware and software. It’s
intended for artists, designers, hobbyists and anyone interested in creating interactive objects or environments.”

- http://www.arduino.cc/

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 2


What is Arduino
❑ Arduino is an open-source physical computing platform.

❑ It is a small microcontroller board with a USB plug.

❑ Based on a simple i/o board and a development environment that implements the Processing/writing language.

❑ Arduino can be used to develop stand-alone interactive objects or can be connected to software on your
computer.

❑ Easy-to-use hardware and software.

❑ It’s intended for students, artists, designers, hobbyists and anyone who tinker with technology.

❑ It is programmed in Arduino Programming language(APL) similar to C/C++.

❑ Way more easy to program compared to other microcontroller packages.

❑ The Arduino is a microcontroller development platform(not a microcontroller….)


❑ It is the winner of “worlds best interaction award 2012” sponsered by google
9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 3
Different Arduino flavor's!!!

❑ There are many versions of Arduino board. Versions differ by size, microcontroller, etc

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 4


Meet Arduino Uno

The most commonly used Arduino board. We will be using this board in this workshop

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 5


Meet Arduino Uno

Microprocessor – Atmega328
- 16 MHz speed
- 14 Digital I/O Pins
- 6 Analog Input Pins
- 32K program Memory
- 2K RAM
- 1K EEPROM
Contains a special program called A
“Bootloader”
- Always programming from USB port
- Requires 0.5K of Program Memory

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 6


Meet Arduino Uno

USB Interface
- USB client device
- Allows computer to program the
Microprocessor
- Can be used to communicate with
computer
- Can draw power from computer to
run Arduino

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 7


Meet Arduino Uno

Power Supply
- Connect 7V-12V Provides
- Required 5V to Microprocessor
Will automatically pick USB or Power
Supply to send power to The
Microprocessor

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 8


Meet Arduino Uno

Indicator LEDs
1. L-Connected to
digital pin 13
2.TX- transmit data
to computer
3.RX- receive data
from computer
4.ON- when power
is applied

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 9


Meet Arduino Uno

Quartz Crystal which


provides
16MHz clock to
Microprocessor

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 10


Meet Arduino Uno

Reset Button
Allows you to reset
the Microprocessor
so program will
start from the
beginning.

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 11


Meet Arduino Uno

External power
❑ Should be between 9V and 12V DC.

❑ Must be rated for a minimum of 250mA current output.

❑ Must have a 2.1mm power plug on the Arduino end.

❑ The plug must be “center positive", that is, the middle pin of the plug has to be the
+ connection

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 12


Meet Arduino Uno

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 13


Arduino Software
❑ Arduino boards can be controlled
Using an implementation of Wiring,
Which is a version of Processing
developed specifically for electronic
I/O.
❑ Arduino looks like Processing, but
is actually built in C, so there are a
few differences to look out for.
❑ Arduino. IDE can be downloaded from
http://www.arduino.cc
❑ Currently used version is 1.8.10.

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 14


Arduino IDE

❑ The Arduino is programmed in C/C++ language.

❑ The language is very simple and provides many abstraction for simplicity of reading and
writing powerful applications.

❑ It provides a serial monitor to see the serial data from the USB virtual COM port.

❑ Allows one click compiling, verification and burning of code onto the Arduino.

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 15


Arduino Programming language
❑ Arduino has two reserved functions:
1. void setup()
2. void loop()

❑ There is no pop-up display window, hence void draw() is not special.


Loop() can be considered to do the same thing as draw() for the Arduino.
❑ There are four types of variable in Arduino:
i. char
ii. int
iii. float
iv. double

❑ Arduino has a few reserved constants, which do not need to be defined:


1. HIGH//5 volts
2. LOW//0 volts
3. INPUT//pin is input
4. OUTPUT//pin is output

❑ Conditional statements are the same as in C.


❑ Functions can be defined the same as in C.

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 16


Arduino Programming language

Some Commands

• Serial.begin()
- e.g., Serial.begin(9600)
• Serial.print() or Serial.println()
- e.g., Serial.print(value)
• Serial.read()
• Serial.available()
• Serial.write()
• Serial.parseInt()
9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 17
Arduino Pin

Input / Output connectors


1. Allows you to connect
external devices to
Microprocessor
2. Can accept wires to
individual pins
3. Circuit boards
“Shield” can be
plugged in to
connect external
devices

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 18


Arduino Digital Pin

1. These pins are used to communicate with the outside world.

2. When an output pin is HIGH, it can provide 5V at 40mA maximum.

3. Trying to get more than 40mA out of the pin will destroy the Microprocessor

4. When the output pin is LOW, it provides no current. You can use a transistor
and/or a relay to provide a higher voltage or more current

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 19


Arduino Digital Pin

pinMode(pin, mode)
Sets pin to either INPUT or OUTPUT
digitalRead(pin)
Reads HIGH or LOW from a pin
digitalWrite(pin, value)
Writes HIGH or LOW to a pin
Electronic stuff
Output pins can provide 40 mA of
current
Writing HIGH to an input pin installs a
20KΩ pullup
9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 20
Arduino Analog Pin

1. The pins can be used to accept an input also. Digital pins can
read a voltage (1) or no voltage(0).

2. Analog pins can read voltage between 0V and 5V. You will read
a value of 0 and 1023.

3. Both of these return a value you can put into a


variable and/or make decision based on the
value

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 21


Arduino Analog Pin

pinMode(pin, mode)
Sets pin to either INPUT or OUTPUT
analoglRead(pin)
Reads analog value from a pin
analogWrite(pin, value)
Writes analog value to a pin

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 22


Pulse Width Modulation(PWM)

• Can’t use digital pins


to directly supply say
2.5V, but can pulse
the output on and off
really fast to produce
the same effect

• The on-off pulsing


happens so quickly,
the connected output
device “sees” the
result as a reduction
in the voltage

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 23


Image from Theory and Practice of Tangible User Interfaces at UC Berkley
PWM Duty Cycle
output voltage = (on_time / cycle_time) * 5V

Image credit: Tod Kurt

Fixed cycle length; constant


9/21/2019 IEEE Workshop by Md.number
Jahid Hasan, Deptof cycles/sec
of EEE, HSTU. 24
Arduino PWM Pin

• Command:
analogWrite(pin, value)

• value is duty cycle:


between 0 and 255

• Examples:
analogWrite(9, 128)
for a 50% duty cycle

analogWrite(11, 64)
for a 25% duty cycle
Image from Theory and Practice of Tangible User Interfaces at UC Berkley
9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 25
A rd u i n o P ro j e c t
Project Tools

Breadboard

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 27


Project Circuit

Simple Schematic

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 28


Project Circuit

Simple Layout

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 29


Ohm’s Law s

Current = Volts / Resistance


or
I=E/R
If we have a 5 volt battery and a 200 ohm resistor.
5 volts / 200 ohms = .025 amps

The higher the resistance, the lower the current.


9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 30
Don’t Blow It Up

• An LED needs about 1.4 volts to light up.

• An LED should run at around .02 amps.


• If you put 5V into an LED, it could burn out.
• We’ll need a resistor to reduce the voltage and
ensure adequate current.

5V - 1.4V = 3.6V
I = E / R is the same as R = E / I
R = 3.6 / .02 = 180 ohms

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 31


Blinky LED Layout

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 32


Blinky LED Code

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 33


The switch or button

A switch is a simple, digital sensor

Switches come in different forms, but all of them in some way open or
close a gap in a wire

The pushbutton switch has four legs for easier mounting, but only two
of them are needed

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 34


Button Schematic

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 35


Button Schematic

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 36


9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 37
The Push Button

1. A push button can be connected to a digital pin.


2. There is an open circuit normally.
3. There is a closed circuit when pressed.
4. If connected between 5V and a pin, we get 5V when Pressed, but an open
circuit when not pressed.
5. This is a problem- we need 0V when not pressed.

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 38


The Push Button

1. There is a solution.
2. A resistor to 5V will make the pin HIGH when
the Button is not pressed
3. Pressing it will make the pin LOW
4. The resistor makes sure we don’t connect 5V
directly To Ground.

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 39


The Push Button

1. This is a common method for using push


buttons.
2. The resistor is called a “Pull Up Resistor”.
3. The Arduino has built in pull up resistors on
the digital pins.
4. We need to enable them when we need
them.

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 40


9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 41
9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 42
9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 43
Additional Experiments

• LCD display • Ultrasonic Sensor

• Servo • Motor driver board

• Stepper motor • Robot chassis

• Temperature sensor • LED Strips

• Tilt sensor • 8x8 LED display

• Shift register • Color organ board

• IR sensor • Electroluminescent wire

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 44


More Tools

• Needle nose pliers

• Multi-meter

• Wire strippers

• Wire cutter

• Soldering iron + solder + flux + wick

• Vise

• 3rd hand

• Oscilloscope (for those with $$$)

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 45


Inspirational Web Sites

• www.instructables.com

• www.tindie.com

• www.makershed.com

• www.makezine.com

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 46


Sources for Parts

• www.techshopbd.com

• https://bdspeedytech.com

• https://www.aliexpress.com

• www.adafruit.com

• www.ebay.ca

• www.amazon.com

• www.dealextreme.com

9/21/2019 IEEE Workshop by Md. Jahid Hasan, Dept of EEE, HSTU. 47


T H A N K YO U
Contact to:
MD. Jahid Hasan
Dept of EEE
L-4, S-I
Facebook: https://www.facebook.com/jahid2angrybird
Phone : +8801772905097

You might also like