Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
JorgeCute F. Resurreccion
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.
Arduino Board
◼ “Strong Friend” Created in Ivrea, Italy
◼ in 2005 by Massimo Banzi & David Cuartielles
◼ Processor
◼ Coding is accessible & transferrable → (C++, Processing, java)
Arduino…
http://spectrum.ieee.org/geek-life/hands-on/the-making-of-arduino
PWR IN USB
(to Computer)
RESET
SCL\SDA
(I2C Bus)
POWER
5V / 3.3V / GND
Digital I\O
PWM(3, 5, 6, 9, 10, 11)
Analog
INPUTS
PWR IN USB
(to Computer)
RESET
SCL\SDA
(I2C Bus)
POWER
5V / 3.3V / GND
Digital I\O
PWM(3, 5, 6, 9, 10, 11)
Analog
INPUTS
Go ahead and plug your board in!
Arduino Shields
PCB Built Shield Inserted Shield
Arduino Shields
◼What happens
when you break
the circuit?
◼What if you
wanted to add
more than one
LED?
Arduino Software
The Arduino programming
platform was designed in
JAVA to help newcomers
become familiar with
programming. The language
used to write code is C/C++
and only uses TWO functions
to make a functionable
program.
Adding control – let’s use the Arduino
and start programming!!!
Concepts: INPUT vs. OUTPUT
Referenced from the perspective of the microcontroller (electrical board).
Almost all systems that use physical computing will have some form of
output
5V 5V
0V 0V
Arduino Integrated Development Environment (IDE)
Part of the Sketch
void setup()
{
// runs once
}
void loop()
{
// repeats
error & status messages }
Settings: Tools → Serial Port
◼Your computer
communicates to the Arduino
microcontroller via a serial
port → through a USB-Serial
adapter.
digitalRead()
analogRead()
Serial communication
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.
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.
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.
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.
+ (addition)
- (subtraction)
* (multiplication)
/ (division)
Comparison Operators
These are used to make logical comparisons.
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.
Note: There are ways to use the board as analog. Those will be explained later.
Lesson #1 – Blinking LED
What will you need? Arduino, breadboard, 4
wires, 10mm LED(large white), 560W resistor,
USB cable.
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.
◼
Programming Concepts: Variables
Variable Scope
◼Global
◼---
◼Function-
level
Programming Concepts: Variable
Types
◼ Variable Types:
◼analogWrite(pin, val);
◼
◼pin – refers to the OUTPUT
pin (limited to pins 3, 5, 6, 9, 10,
11.) – denoted by a ~ symbol
Color Mixing
Tri-color LED
◼ Note: The
longest leg of
the RGB LED is
the Common
Cathode. This
goes to GND.
Use Colorpicker.com or
experiment on your
own.
Pick out a few colors that
you want to try re-
creating for a lamp or
lighting display...
Play around with this with
the analogWrite()
command.
RGB LED Color Mixing
◼ int redPin = 5;
◼ int greenPin = 6;
◼ int bluePin = 9;
◼ void setup()
◼ {
◼ pinMode(redPin, OUTPUT);
◼ pinMode(greenPin, OUTPUT);
◼ pinMode(bluePin, OUTPUT);
◼ }
RGB LED Color Mixing
◼ void loop()
◼ {
◼ analogWrite(redPin, 255);
◼ analogWrite (greenPin, 255);
◼ analogWrite (bluePin, 255);
◼ }
Project: Mood Lamp / Light Sculpture
Driving Motors or other High Current
Loads
◼ NPN Transistor (Common Emitter “Amplifier”
Circuit)
to Digital
Pin 9
Input
to Digital Pin 2
Digital Sensors (a.k.a. Switches)
Add an indicator LED to Pin 13
This is just like our 1st
circuit!
Digital Input
<Boolean> Description
( ) == ( ) is equal?
( ) != ( ) is not equal?
( ) > ( ) greater than
( ) >= ( ) greater than or equal
( ) < ( ) less than
( ) <= ( ) less than or equal
Trimpot (Potentiometer)
Variable Resistor
fixed
end
wiper
fixed
end
Analog Sensors
3 Pin Potentiometer = var. resistor (circuit)
a.k.a. Voltage Divider Circuit
wiper
fixed
ends
1.0 V 1.0 V
Ohms Law… (just the basics)
Actually, this is the “voltage divider”
◼
analogRead()
Opens up a Serial
Terminal Window
Analog Sensors
2 Pin Analog Sensors = var. resistor
◼Take two sensors -- Use
the Serial Monitor and find
the range of input values
you get for each sensor.
◼MaxAnalogRead = _________
◼MinAnalogRead = _________
Analog Sensors
Examples:
Sensors Variables
Mic soundVolume
Photoresistor lightLevel
Potentiometer dialPosition
Temp Sensor temperature
Flex Sensor bend
Accelerometer tilt/acceleration
Additional Serial Communication
Sending a Message
void loop ( )
{
Serial.print(“Hands on “) ;
Serial.print(“Learning ”) ;
◼ Serial.println(“is Fun!!!”) ;
}
Serial Communication:
Serial Debugging
void loop()
{
int xVar = 10;
Serial.print ( “Variable xVar is “ ) ;
Serial.println ( xVar ) ;
}
Serial Communication:
Serial Troubleshooting
void loop ( )
{
Serial.print (“Digital pin 9: “);
Serial.println (digitalRead(9));
}