2. Sypnopsis
This workshop intends to expose participants to a much
simpler approach to microcontroller based on practical
problem-based approach.
Enable participants to gain real-world experience to
monitor and control engineering processes and develop
competent skills.
It has been specially designed for beginners and
educators
myduino.com 2
3. Microcontroller
Microcontrollers are dedicated to
one task and run one specific
program.
Examples of tasks could be:
i. Received from inputs via ports
(read from external hardware)
ii. Stored data in file registers &
arithmetic operations (added,
subtracted, logic gates)
iii. Sent out data (control external
hardware)
Processor, Storage and RAM all in
one tiny package
myduino.com 3
5. Internal Architecture
Program
Memory Register
RAM EEPROM PORTS
Program Memory: Where all commands, written by users are stored
Register: To determine what action the uC takes in reference to the
program commands
RAM: Temporarily store data of any action
EEPROM: The data is retain even after power is switched-off
Ports: Bidirectional pins of Input and Output
myduino.com 5
7. Arduino Uno Specifications
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
Flash Memory: 32 KB (ATmega328) of which 0.5
KB used by bootloader
SRAM: 2 KB (ATmega328)
EEPROM: 1 KB (ATmega328)
Clock Speed: 16 MHz
myduino.com 7
8. Arduino Terminology
“sketch” – a program you write to run on an
Arduino board
“pin” – an input or output connected to
something. e.g. output to an LED, input from
a knob.
Analog signals – directly measurable
quantities in terms of some other quantity
Digital Signals – have only two states. For
digital computers, we refer to binary states, 0
and 1. “1” can be on, “0” can be off
myduino.com 8
9. Workshop Summary
Introduction to Arduino
Setting up your Arduino Environment
First Arduino sketch
Making LEDs glow and blink
How to read buttons/switches
Analog Signals
Serial Communication
Digital Thermometer
myduino.com 9
10. Participant Manifest
Thumb drive with notes, arduino software for
Windows and source code (“sketches”) used
in class
Arduino Starter Kit:
Arduino Uno Tactile push button
Half size breadboard Liquid Crystal Display
Jumper wires Piezo Buzzer
LEDs USB Cable
Resistors Temperature Sensor
Potentiometer
myduino.com 10
11. Breadboard
A breadboard (or protoboard)
is a construction base for
prototyping of electronics
Wires and components are
simply pushed into the holes to
form a completed circuit and
power can be applied.
myduino.com 11
12. Components: LED
LED (Light Emitting Diode)
What it Does: Emits light
when a small current is passed
through it.
Leads: 2 (one longer, this one
connects to positive)
Things to watch out for: Will
only work in one direction
Looks like a mini light bulb. -
Requires a current limiting
resistor
myduino.com 12
13. Resistors
What it Does: Restricts
the amount of current
that can flow through a
circuit.
Leads: 2
Things to watch out
for: Easy to grab the
wrong value
Cylinder with wires
extending from either
end. The value is
displayed using a color
myduino.com 13
14. Potentiometer
What it Does: Produces a
variable resistance dependant
on the angular position of the
shaft.
Leads: 3
Things to watch out for:
Identifying: - Accidentally
buying logarithmic scale.
They can be packaged in
many different form factors,
look for a dial to identify.
myduino.com 14
15. Pushbutton
What it Does: Completes a
circuit when it is pressed. 4
Leads: 4
A little square with leads out
the bottom and a button on the
top.
myduino.com 15
16. Piezo Element
What it Does: A pulse of
current will cause it to click. A
stream of pulses will cause it
to emit a tone.
Leads: 2
Things to watch out for:
Difficult to misuse.
In this kit it comes in a little
black barrel, but sometimes
they are just a gold disc
myduino.com 16
17. Temperature Sensor (LM35)
The LM35 series are precision integrated-circuit
temperature sensors, whose output voltage is linearly
proportional to the Celsius (Centigrade) temperature.
The LM35 is rated to operate over a −55° to +150°C
temperature range, and has a linear + 10.0 mV/°C scale
factor.
myduino.com 17
18. Liquid Crystal Display
An LCD has the advantage of
displaying alpha-numeric
characters and even user-
defined graphics.
It also offers the ability for
lower power consumption,
making it ideal for battery
operated systems.
It comes in a wide variety of
shapes and sizes with line
lengths of 8, 16, 20, 24, 32 and
40 characters, in one, two and
four line versions.
myduino.com 18
19. What is Electricity
A fan contains a small battery,
a couple of wires, a switch and
an electric motor.
If you turn the switch on, the
motor will start to spin
Battery is both a water
reservoir and a pump, the
switch is a tap, and the motor
is one of those wheels that you
see in watermills.
When you open the tap, water
flows from the pump and
pushes the wheel into motion.
myduino.com 19
20. The hydraulic system
Increasing the size of the pipes
allows a greater flow of water
to go through them, effectively
reduced the pipes' resistance
to the flow of water.
This approach works up to a
certain point, at which the
wheel won't spin any faster,
because the pressure of the
water is not strong enough.
When we reach this point, we
need the pump to be stronger.
myduino.com 20
21. Voltage, Current & Resistance
So when you read that a battery's voltage is 9 V, think of this voltage
like the water pressure that can potentially be produced by this little
"pump".
The flow rate of water relates to current, and is measured in
amperes.
Finally, the resistance opposing the flow of current over any path
that it travels is called resistance, and is measured in ohms.
Relationship: A higher voltage (pressure) lets you spin a wheel
faster; a higher flow rate (current) lets you spin a larger wheel.
Ohms Law, V = IR
myduino.com 21
29. Blinking an LED
digitalWrite
The Arduino board comes with
an LED preinstalled. It's
marked "L". You can also add
your own LED
Tell Arduino what to do.
This is done through code, that
is, a list of instructions that we
give the microcontroller to
make it do what we want.
Blink an LED is the Hello
World of physical computing
myduino.com 29
37. Pulse Width Modulation (PWM)
If you blink the LED fast
enough, you don't see it blink
any more, but you can change
its brightness by changing the
ratio between the on time and
the off time.
This technique also works with
devices other than an LED.
For example, you can change
the speed of a motor in the
same way
analogWrite(9,128) will set the
brightness of an LED
connected to pin 9 to 50%.
39. myduino.com 39
Arduino PWM
8 Bits
Data Vout
x 0.0196
0
To
255
0
To
5V
PWM Output (Vout) = Data
5V 255
PWM Output (Vout) = Data x 5 V
255
= Data x 0.0196
Ex: If Data = 128; Vout = 128 x 0.0196 = 2.5088 V
analogWrite (PWM_pin, 128); // Will give an output of 2.5088 V
41. Analogue Input
This is the difference
between an on/off
sensor (which tells us
whether something is
there) and an analogue
sensor, whose value
continuously changes.
By using the
analogRead() function,
we can read the voltage
applied to one of the
pins. This function
returns a number
between 0 and 1023,
which represents
voltages between 0 and
5 volts
myduino.com 41
42. myduino.com 42
Number of iterations (steps) for an ADC is
calculated as follows:
2N
= Number of steps.
Where N corresponds to the number of bits
Ex: 2 bits, 22
= 4
Resolution = Voltage Range = 5V = 1.25
No of steps 4
Vin Dout
0 – 1.25 0
1.25 – 2.5 1
2.5 – 3.75 2
3.75 - 5 3
43. Arduino ADC Calculations
10 bit ADC, 210
= 1024 steps
The resolution of an ADC is calculated as follows:
Resolution = Voltage Range = 5V = 0.00488 V
No of steps 1024
The output of the ADC is calculated as follows:
ADC Output (dout) = Vin = 3.3 = 676
Resolution 0.00488
myduino.com 43
46. Temperature Sensor (LM35)
The LM35 series are precision integrated-circuit
temperature sensors, whose output voltage is linearly
proportional to the Celsius (Centigrade) temperature.
The LM35 is rated to operate over a −55° to +150°C
temperature range, and has a linear + 10.0 mV/°C scale
factor.
myduino.com 46
48. Liquid Crystal Display
An LCD has the advantage of
displaying alpha-numeric
characters and even user-
defined graphics.
It also offers the ability for
lower power consumption,
making it ideal for battery
operated systems.
It comes in a wide variety of
shapes and sizes with line
lengths of 8, 16, 20, 24, 32 and
40 characters, in one, two and
four line versions.
myduino.com 48
55. Arduino Library
A library is a big collection of related procedures.
If you, say, want to control a motor, you may want
to find a Motor Control Library: a collection of
procedures that have already been written for you
that you can use without having to do the dirty
work of learning the nuances of motors.
One of the best features of the Arduino project is
the ability to add on pre-crafted libraries that add
hardware support. There's tons of them, and you
can pick and choose which to install.
56. Arduino Library
A library is a folder with some files in it, the files will end
in .cpp (C++ code file) and .h (C++ header file).
Two optional files are keywords.txt (this is a hints file to
tell the Arduino IDE how to colorize your sketch and
examples folder, which may have some handy test-
sketches.
57. How to Install Library
Download your desired library
(normally in a compressed zip file)
Find the zip file on your local computer
(wherever downloaded files end up).
Under Windows, you should be able to
double click on the file to open it up.
Older windows, winrar or winzip will
pop-up.
Copy the file and paste in inside the
libraries folder in your Arduino
directory.