0% found this document useful (0 votes)
6 views29 pages

15. Introduction to Arduino

Arduino is an open-source microcontroller designed to simplify electronics projects, initially aimed at making student designs more affordable. The document covers key components, programming routines, and basic concepts of input and output in Arduino, along with a practical example of creating a blinking LED circuit. It also outlines the learning goals for students to understand circuit building and C programming elements related to Arduino.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
6 views29 pages

15. Introduction to Arduino

Arduino is an open-source microcontroller designed to simplify electronics projects, initially aimed at making student designs more affordable. The document covers key components, programming routines, and basic concepts of input and output in Arduino, along with a practical example of creating a blinking LED circuit. It also outlines the learning goals for students to understand circuit building and C programming elements related to Arduino.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 29

Introduction to

Arduino
Md. Nazmul Abdal
Lecturer, Department of CSE
University of Liberal Arts
Bangladesh (ULAB)
What is Arduino?
Arduino is a popular “open source” single
board microcontroller. It is designed to make
the process of using electronics in
multidisciplinary projects more accessible.

This idea began in Italy and its initial


purpose was to make STUDENT design
projects more affordable than other
prototyping projects at the time.
USB
(to
PWR IN
Computer)

RESET

SCL\SDA
(I2C
Bus)

POWER
5V / 3.3V / Digital I\O
GND PWM(3, 5, 6, 9,
10, 11)
Analog
INPUTS
Go ahead and plug your
board in!
SparkFun Inventor’s Kit
Components
Name Image Type Function Notes
Push Button Digital Switch - Polarized,
Input Closes or needs
opens circuit resistor
Trim Analog Variable Also called a
potentiomete Input resistor Trimpot.
r
Photoresistor Analog Light Resistance
Input Dependent varies with
Resistor light.
(LDR)
Relay Digital Switch Used to
Output driven by a control larger
small signal voltages
Temp Sensor Analog Temp
Input Dependent
Resistor
Flex Sensor Analog Variable
Input resistor
SIK Components

control electrical
devices such as
volume controls
on audio
equipment.
SIK Components
The resistance of
a photo
resistor decreas
es with
increasing
incident light
intensity.
Concepts: INPUT vs.
OUTPUT
Referenced from the perspective of the microcontroller
Inputs is a signal / (electrical board).
Output is any signal exiting
information going into the the board.
board.
Almost all systems that use physical computing will have
some form of output

What are some examples of Inputs and Outputs?

Inputs: Buttons Switches, Outputs: LEDs, DC motor,


Light Sensors, Flex Sensors, servo motor, a piezo
Humidity Sensors, buzzer, relay, an RGB
Temperature Sensors LED
Arduino Software
The language used to write
code is C/C++ and only uses
TWO functions to make a
function able program.
Programming - Routines
Each Arduino program is called a
SKETCH and has two required
functions, called ROUTINES.

void setup ( ) { } - All of the code within the


curly braces will be run ONCE when the
program first runs.
void loop ( ) { } - This function is run AFTER
setup has finished. All of the code within the
curly braces will be run again, and again,
until the power is removed.
Programming - Syntax

// - Single line comment


/* */ - Multiline comment
{ } – used to define a block of code that
starts and ends.
; - used to define the end of a line of code.
Programming - Variables
int (integer) – this stores a number in 2 bytes(16 bits)
and has no decimal places. The value must be between
-32,768 and 32,768.

long(long) – Used when the integer is NOT large


enough. This takes 4 bytes(32 bits) of RAM and has a
range of -2,147,483,648 and 2,147,483,648.

boolean(boolean) – A simple true and false variable.


It is useful because it only takes up 1 bit of RAM.

float (float) – Used for floating decimals. It takes 4


bytes of RAM and has a range of -3.4028235E+38 and
3.4028235E+38

char(character) – Stores one character using ASCII


code (“A” = 65). Uses 1 byte of RAM
Programming – Math
Operators
These are used for manipulating
numbers.
= (assignment) makes something equal to
something else. For example, x = 10*2, thus x =
20.

% (modulo) – this gives the remainder when one


number is divided by another. For example 12 %
10 gives 2.

+ (addition)
- (subtraction)
* (multiplication)
/ (division)
Comparison Operators
These are used to make logical
comparisons.
== (equal to) - For example 12==10 is
FALSE and 12 ==12 is TRUE.

!= (not equal to) - For example 12!=10 is


TRUE and 12!=12 is FALSE.

< (less than)


> (greater than)
Programming – Control
Structures
These execute code based on CONDITIONS. Here
are just a few.
if(condition) { }
else if (condition) { }
else { }

This will execute the code between the curly


braces if the condition is true, and if not test the
condition of the “else if”. If that is false , the
“else” code will execute.
for (int i =0; i < #repeats; i ++) { }
Used when you would like to repeat a line of code
a specific # of times. Often called a FOR LOOP.
Programming - Digital

pinmode (pin, mode) ; - Used to address the pin


# on the Arduino board you would like to use 0-
19. The mode can either be INPUT or OUTPUT.

digitalwrite (pin, value); - Once a pin is set to


output it can be set to either HIGH (5 Volts) or
LOW(0 volts). This basically means turn ON and
OFF.
Note: There are ways to use the board as analog.
Those will be explained later.
Let’s Begin – Learning Goals
Learning Goals: The student will be able to:
1. Build a complete circuit using the Arduino
microprocessor
2. Identify important electrical components in a
circuit and explain their use
3. Identify and apply specific elements in “C” code
used to run a program in conjunction with how
a circuit is built
Lesson #1 – Blinking LED
What will you need?
Arduino, breadboard, 4 wires, 10mm LED(large
white), 560Ω resistor, USB cable.

Longer Lead is POSITIVE


LEDs
An LED (light emitting diode) emits light
when a small current passes through it.
You can identify it as it looks like a small
bulb
It only works in ONE
direction. So make
sure you attach it
correctly. Also it often
needs a resistor to
limit the current
going to it.

Schematic symbol
Resistors
Resistors restrict the amount of electrical
current that can flow through a circuit.
The color bands indicate the VALUE of the
resistor
Note: it is easy to grab
the WRONG one so be
careful. Also, it does
not matter which way
the resistor is wired.
Schematic
symbol
The schematic
This is basically a SERIES circuit
where the resistor and LED are
wired one after another.

1.Run a red wire from the 5V on


the Arduino to the red strip on the
BB.
2.Run a black wire from the
GROUND(GND) on the Arduino to
the blue strip on the BB.
3.Place the LED on H 22 and 21
with the longer lead(+) of the LED
in H22.
4.Place a resistor on I21 and I11.
Notice that both the resistor and
LED share row 21.
5.Run a red wire from Digital 13
port on Arduino to F22
6.Run a black wire from J11 to the
blue strip.
Writing the code - Integers
Load up the Arduino software.

Begin by using the variable “int” or


integer and let’s tell the Arduino
which port the LED is in.
Writing the code - Setup

Remember that SETUP is used for


things that only need to be done
once. Therefore we must tell the
Arduino that the LED in port 13 is
an output. That means when we
input data it outputs an outcome or
result.
Writing the code - Loop

The next steps is telling the Arduino what we


want to do with the LED. We first need to use
the digitalWrite command to turn the LED ON.
We then use the “delay” command to specify
and amount of time in milliseconds. We then
use the same command to turn it OFF then wait
again. Since this is a loop the process will
repeat forever until the power is removed.
Compile
To compile your sketch,
click the checkmark.

Make sure your Arduino is


plugged into an available
USB port.

Click the arrow to upload


the program to Arduino. If
everything is attached
correctly. The LED should
blink.
Circuit Diagram
Arduino Output
THANK
YOU

You might also like