Arduino
Arduino
08.04.2013 F. Schubert
HAW - Arduino
Description
Datasheets
Schematics
Calculations
Source-codes with comments
Documentation of the results
08.04.2013
HAW - Arduino
First Steps
Introduction
Hardware and software
Installation of the environment
The first Arduino-program
Inputs and outputs
Voltmeter
Thermometer
Piezo sensor
Servo-motor
08.04.2013
HAW - Arduino
The Hardware
HAW-Arduino USB-Board
Breadboard small
Breadboard big
USB cable
Piezo-buzzer
Potentiometer
Switches
LEDs
Transistor
Resistors
Photoresistor
Photodiode
08.04.2013
LCD-module
NTC
Operational amplifier
Comparator
Wires
Cables
Soldering equipment
Socket strips
Connectors
Experimentation board
Relay
IR-transmitter
HAW - Arduino
08.04.2013
Programming-software
HAW - Arduino
Community
Hardware
08.04.2013
HAW - Arduino
Arduino Characteristics
16 kByte EEPROM
1 kByte RAM
16 MHz Clock
Inputs and Outputs
14 digital Inputs/Outputs
6 analog Inputs
6 PWM-Outputs
I2C-Bus, serial Bus (TX/RX)
08.04.2013
HAW - Arduino
Microcontroller
External Power Supply
Analog Inputs
08.04.2013
HAW - Arduino
08.04.2013
HAW - Arduino
Arduino-Software
Verify
(Compile)
Serial Monitor
ON
Stop
Upload to
I/O Board
New
Open
Save
Status Field
Status Messages
08.04.2013
HAW - Arduino
10
Installation
Unzip of the Arduino-software
Connection of the Arduino-board
Installation of the drivers (administrator rights
needed)
Reboot the computer
Run the Arduino-software
Go on..
08.04.2013
HAW - Arduino
11
08.04.2013
HAW - Arduino
12
08.04.2013
HAW - Arduino
13
Driver Installation
08.04.2013
HAW - Arduino
14
08.04.2013
HAW - Arduino
15
08.04.2013
HAW - Arduino
16
Status-Messages
Upload done
Wrong board
08.04.2013
HAW - Arduino
17
Troubleshooting
Press the reset-button on
Arduino and try again
Check the serial port (Connection and
number)
Read the red text (Debugging output) at the
bottom to determine the problem
The status area shows what is wrong
08.04.2013
HAW - Arduino
18
Cycle of Development
EDIT
UPLOAD
COMPILE
COMPILE
UPLOAD
ERROR ?
YES
UPLOAD
YES
ERROR ?
ERROR ?
YES
RUN
08.04.2013
HAW - Arduino
19
Program-Structure
Declaration of variables
int ledPin = 13;
Initialization
setup( ) Set the inputs and outputs
void setup()
{
pinMode(ledPin, OUTPUT);
}
Main program
loop( ) Loop without end
void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
08.04.2013
HAW - Arduino
20
08.04.2013
HAW - Arduino
21
Program Examples
08.04.2013
HAW - Arduino
22
Hardware
HAW-Arduino
08.04.2013
HAW - Arduino
23
Solderless Breadboard
Not connected
08.04.2013
All connected
All connected
HAW
HAW-- Arduino
Arduino
Group of 5 connected
24
08.04.2013
HAW - Arduino
25
Power Supply
From USB (Current is limited to 500 mA)
External power supply (Duemilanove switches
automatically) (VIN and GND or power jack)
SMPS
Battery
Diecimila
Jumper to EXT
08.04.2013
HAW
HAW- - Arduino
Arduino
26
HAW - Arduino
27
Analog I/O
analogReference(type)
int analogRead(pin)
analogWrite(pin, value)
08.04.2013
- initialization
- initialization
- PWM
HAW - Arduino
28
Digital Output
Make an external LED at pin 6 blinking
VCC (from USB)
Arduino Board
220
Pin 6
GND
HAW - Arduino
29
Digital Input
A digital input floats between 0 and 5 V, if it is
not connected
A resistor pulls an input to 5V (pull up) or to
GND (pull down)
Using a pullup-resistor the switch pushes the
input to GND
Using a pulldown-resistor the switch pushes
the input to 5 V
08.04.2013
HAW - Arduino
30
Digital Input
Pullup-resistor
Pulldown-resistor
VCC
VCC
Arduino Board
Arduino Board
Digital Input
Digital Input
GND
GND
08.04.2013
HAW - Arduino
31
08.04.2013
HAW - Arduino
32
HAW - Arduino
33
HAW - Arduino
34
+12 V
VCC (from USB)
1N4148
4,7 k
Arduino Board
5V
Pin 6
Pin 11
GND
08.04.2013
HAW - Arduino
35
+12 V
M
4,7 k
1N4148
Arduino Board
5V
1 k
Pin 6
BD139
Pin 11
GND
08.04.2013
HAW - Arduino
36
PWM Output
Pulse Width Modulation
Characteristics:
Pulse width range HIGH
level
Pulse period
width
LOW
Voltage levels
period
Average is like an analog voltage UAV
UAV = width/period *(HIGH LOW) + LOW
For PWM use the analogWrite() instruction
08.04.2013
HAW - Arduino
37
Analog Input
The ATmega 168 has 6 ADC inputs
The maximum input range
is from 0 V to 5 V
The resolution is 10 bit
(1024 values)
The reference voltage is variable
08.04.2013
HAW - Arduino
38
HAW - Arduino
39
External UREF
3,3 V
4,7 K
08.04.2013
HAW - Arduino
40
High-impedance input
Input-range: -5 V to + 5 V
UREF = 5 V
Output on LCD :
+ 2 . 7 3
08.04.2013
- 8 7 6
HAW - Arduino
m V
41
UIN
08.04.2013
Pre-Amp
Protection
Circuit
HAW
Arduino
HAW -- Arduino
Arduino
LCD
42
Pre-Amplifier (Level-Shifter)
08.04.2013
HAW - Arduino
43
08.04.2013
HAW - Arduino
44
Pre-Amplifier (Level-Shifter)
08.04.2013
HAW - Arduino
45
Protection Circuit
5V
Arduino Board
1 K
BAT 85
Pin 2
U
OUT
08.04.2013
BAT 85
HAW - Arduino
470 nF
46
08.04.2013
HAW - Arduino
47
08.04.2013
LCD-Module
24-Pin-Socket
Description
Symbol
12
GND
VSS
24
+5V
VDD
N.C.
VEE
H = Data / L = Command
RS
H = Read / L = Write
R/W
Enable
N.C.
LSB (8 Bit)
D0
N.C.
D1
N.C.
D2
10
N.C.
D3
11
14
12
15
D5(D1)
13
16
D6(D2)
14
17
LSB (4 Bit)
MSB
HAW - Arduino
D4(D0)
D7(D3)
48
08.04.2013
HAW - Arduino
49
The Voltmeter
Power Supply
Input Voltage
Generation of
the Input Voltage
Protection Circuit
Pre-Amplifier
08.04.2013
HAW - Arduino
50
08.04.2013
HAW - Arduino
51
Temperature / C
Resistor / k
27,25
50
4,162
100
0,949
Input-range: 0 C to 100 C
Buzzer alarm, if temperature encreases 90 C
Output on LCD :
4 2
C
1 0 8
08.04.2013
HAW - Arduino
52
R RL
HAW - Arduino
53
08.04.2013
HAW - Arduino
54
Arduino Board
5V
R
LCD-Module
L
Pin 2
NTC
08.04.2013
GND
HAW - Arduino
55
HAW - Arduino
56
Notes
08.04.2013
note
frequency/Hz
period/s
261
3830
294
3400
329
3938
349
2864
392
2550
440
2272
493
2038
523
1912
HAW - Arduino
57
+12 V
M
10 k
1N4001
Arduino Board
5V
1 k
Pin 6
BD139
Pin 2
GND
08.04.2013
HAW - Arduino
58
Arduino Board
5V
R
220
L
Pin 2
GND
08.04.2013
HAW - Arduino
59
Tasks
Piezo-sensor: input value -> serial out
Piezo-sensor: input value -> buzzer frequency
08.04.2013
HAW - Arduino
60
Arduino Board
5V
Pin 2
1 M
08.04.2013
GND
HAW - Arduino
61
Servo Motor
Servos are DC motors with built in gearing and feedback control
loop circuitry.
Servo Wiring
All servos have three wires:
Black or Brown is for ground.
Red is for power (~4.8-6V).
Yellow, Orange, or White is the signal wire (3-5V).
Tasks
Pot position 0180 to servo position and LCD
Railroad crossing barrier
Railroad crossing sign (blinking, beep)
08.04.2013
HAW - Arduino
62
As of Arduino 0017, the Servo library supports up to 12 motors on most Arduino boards
and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables
analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on
those pins. On the Mega, up to 12 servos can be used without interfering with PWM
functionality; use of 12 to 23 motors will disable PWM on pins 11 and 12.
In Arduino 0016 and earlier, the Servo library uses functionality built in to the hardware,
and works only on pins 9 and 10 (and does not work on the Arduino Mega). In this case,
if only one servo is used, the other pin cannot be used for normal PWM output with
analogWrite(). For example, in Arduino 0016 and earlier, you can't have a servo on pin 9
and PWM output on pin 10.
08.04.2013
HAW - Arduino
63
08.04.2013
HAW - Arduino
64
//barraganstudio.com>
#include <Servo.h>
Servo myservo;
int pos = 0;
void setup()
{
myservo.attach(9);
}
void loop()
{
for(pos = 0; pos < 180; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 180; pos>=1; pos-=1)
{
myservo.write(pos);
delay(15);
}
}
08.04.2013
HAW - Arduino
65
+5 V
red
10 k
Arduino Board
Servo
5V
Pin 6
orange
Pin 2
brown
GND
08.04.2013
HAW - Arduino
66
Switches
Potentiometer
Temperature Sensor
Photoresistor
Piezo
LCD
Relay
Transistor
LED
DC-Motor
Servo-Motor
Buzzer
08.04.2013
HAW - Arduino
67
Special Sensors
08.04.2013
HAW - Arduino
68