View
697
Download
141
Tags:
Embed Size (px)
DESCRIPTION
n
Citation preview
Mad
e in G
erman
y.
by Stefan Hermann
Start
with
Ard
uino:
Intro
ductio
n to
the Cr
eative U
se of
Electro
nics
Don‘t have a
Fritzing Creator Kit yet?
Well, you can close this PDF then. We‘re really sorry but that‘s just the way it goes sometimes ...
But wait, we didn‘t mean it that way. You can check out the content first to see how you like it.
Have fun with your projects! You can always buy a Creator Kit another time as a:
Birthday presentReconciliation giftEducational giftChristmas presentA present for bragging rightsMother‘s Day giftFather‘s Day giftHousewarming giftGift YOU ask for
And don‘t forget: The Fritzing Creator Kit is also available for Schools, Universities and Labs as a Tea-ching-Bundle.
We look forward to your next visit in our Shop!
To the Webshop >
PS: Please share this document and if you have any questions, drop us a line: [email protected]
Thank you for purchasing the Fritzing Creator Kit. This kit provides everything you need to get started in the world of creative electronics, and we promise you that it will be a highly entertaining and exciting journey.
All the experience that we've gained from teaching at the University of Applied Sciences in Potsdam and from countless workshops has been incorporated into this kit. Try things out first, understand later – this approach will start you off with a good overview and make your first steps really easy.
We recommend you to work on the examples in the order they appear in this book – the later ones build on the earlier ones. If you have difficulties at any point, please go to fritzing.org/forum/creatorkit/troubleshooting.
Fritzing's free software allows you to share your ideas with others, document your projects and even create and produce your own board layouts. You will find more interesting projects by other users in the Fritzing project gallery: www.fritzing.org/projects.
Now we wish you lots of fun building, programming and inventing.
Best regards
Stefan Hermann Fritzing.org
5. Analog Input — 78
Potentiometer — 80
Electronic Basics 4:
Reference Resistor — 84
Automatic Lighting System — 86
Ping Pong — 90
6. Servomotor, Sound — 92
Servo — 94
Synthesizer — 98
Battery — 102
7. Arduino meets Processing — 104
Firmata — 106
Processing RGB — 109
Magic Board — 110
Twitter Saurus — 112
8. From Prototype to Product — 114
Fritzing — 116
Printed Circuit Boards (PCB) — 118
Circuit Board Layout — 120
Fritzing Fab — 125
Assembly of Components — 126
Troubleshooting – 128
Goal Achieved — 129
Aknowledgements — 130
Imprint — 131
Foreword — 3
Inspiration — 7
1. Preparation — 20
Component Overview — 22
Prototyping Environment — 26
Installing Arduino Uno — 28
Creator Kit Software Package — 29
Arduino Board — 30
2. Digital Output — 32
Blink — 34
Programming – A Short Introduction — 38
Electronic Basics 1:
Voltage, Current and Power — 40
Chaser Lights — 42
Electronic Basics 2:
Electrical Resistance — 46
Matrix — 50
3. Digital Input — 54
FlipFlop — 56
Fortuneteller — 60
4. Analog Output — 64
Fading — 66
Night Light — 70
Electronic Basics 3: Amplification — 72
Controlling a Motor with an H-Bridge — 74
Contents
Inspiration
Before you get started, I'd like to show you a few inspiring projects that were implemented with Fritzing, Arduino and related technologies.
Little Black Midi
The Little Black Midi is a dress that singers and instru-mentalists wear during stage performances. It allows singing, dancing, and playing musical instruments to be combined during performance. Midi samples are triggered through the contact of copper plates and rings, and a potentiometer adds effects to the microphone track.
Project by Naomi Knopf Fachhochschule Potsdam, Interface Design www.incom.org/projekt/2967
Photo: Lily Roggemann
10 11
dandylight
Dandylights are dandelion-like objects that can be placed on tables, for example in a café. Each flower lights up in a special colour. The flower stalk is made of a spring. If you flick your flower in the direction of another flower, the latter's light will change to the colour of the flower you just flicked.
With these networked objects, it is easy to come into contact with people in a discreet and playful way in public places.
Project by Tommaso Bertagnin, Loris Bottello, Stella Morelli and Valeria Sanguin Università IUAV di Venezia
www.interaction-venice.net/ iuav11-12lab2/projects/dandylight/
12 13
lumiBots
LumiBots are small, autonomous robots that move on a luminescent background surface. With the help of a UV LED, they leave behind a slowly fading, luminous trail. Both older tracks and newer tracks are visible. The robots have light sensors with which they are able to follow the trails of light, thus reinforcing them. The result is a constantly changing, generative image on a background surface. With this process, lumiBots are able to visually illustrate emergent effects such as "ant algorithms".
Project by Mey Lean Kronemann www.meyleankronemann.de/lumibots
Photo: Michael Baumgartner
14 15
midiBricks
MidiBricks is a toolkit that helps musicians develop their own custom music controllers. It lets one put together one's own instrument on the spur of the moment. The modular design requires neither electronics nor programming skills.
All boards were designed with the Fritzing software and produced with Fritzing Fab (see page 125).
Project by Stefan Hermann Fachhochschule Potsdam, Interface Design
www.midibricks.com
16 17
BeeHive
Clemens Gruber is a beekeeper who uses the Arduino board to keep track of the bees flying in and out of his beehives. This way he knows in real time what his bees are up to.
Additional sensors provide data about the temperature in the interior of the beehive. Since bees heat up signifi-cantly before swarming, the beekeeper can be notified via SMS when a swarm is about to leave.
Project by Clemens Gruber www.imkerei-gruber.de
18 19
To Hear the Grass Growing
Growth is a continuous process that our senses usually cannot grasp, as it can only be perceived after a certain amount of time has elapsed. When caring for a plant, its growth can only be appreciated after several days or weeks. "To Hear the Grass Growing" makes the growth of plants accessible to us by means of a continuously changing soundscape. The grass that grows in the installation generates electrical impulses like those of a heartbeat. The more the plant grows, the slower and stronger are the generated impulses.
The installation comprises three levels. The growing grass is on the upper level, its system of roots is underneath, and the technology used to measure the growth and generate the sound is on the bottom level.
Regular care helps the roots grow into an increasingly complex system. A microcontroller measures the con-ductivity of the root system, the growth and the density of nutrients, and – when connected to an audio amplifier – generates sounds at different frequencies. This way, the steady growth of the grass gives rise to a constantly changing and growing world of sound.
Martin Kim Luge www.martinluge.de Clemens Winkler www.clemenswinkler.com FELD - studio for digital crafts www.feld.is
Digital Class UdK Berlin www.digital.udk-berlin.de Project page www.bit.ly/14FcKP9
20 21
Preparation1. In this chapter:you will get a general idea of the
parts included in the kit.
you will assemble the base plate.
you will install the Arduino software.
you will be introduced to the Arduino board.
13
12
11
10
9
8
7
6
5
4
3
2
L
5V
A0
ANALOG IN
AREF
1
GND
TX
RX
RESET
3V3
A1
A2
A3
A4
A5
VIN
GND
GND
DIGITAL (PWM=)
Arduino
TM
IOREF
ICSP
ICSP2
ON
POWER
0
1TX0
RX0
RESET
The Fritzing Creator Kit includes:
SETUP
1 x Arduino Microcontroller-Board
2 x breadboards to connect components and wires
1 x base plate
1 x USB cable to connect the Arduino to your computer
INPUT
1 x photoresistor (LDR) changes its resistance in proportion to
the intensity of the light striking its surface
2 x potentiometers variable resistors
1 x tilt switch switches when it is shaken or upended
2 x push-buttons close an electrical circuit
OUTPUT
1 x LED Matrix Display
1 x RGB LED with three LEDs in one housing (red, green, blue)
1 x Piezo buzzer generates acoustic signals
22 x light emitting diodes (LEDs)
1 x servomotor rotation angle can be controlled from 0 – 180° 1 x DC motor (4.5 – 9 V)
OTHER
10 x resistors 220 Ω
10 x resistors 100 kΩ
1 x MOS-FET (field-effect transistor) is used to switch
high currents with low control currents
CONNECTIONS / MOUNTING
14 x plug cables, male to male, long
14 x extension cables, male to female
28 x plug cables, male to male, short
1 x 9 V battery clip
1 x L293D motor driver (H-bridge)
1 x Allen key
3 x screws
3 x spacers
11
55
1010
1515
2020
2525
3030
A A
B B
C C
D D
E E
F F
G G
H H
I I
J J
1918
11
2
8
4
1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
3
13 14
22
2117
24
25
23
10
16 15
5
12
9
6
20
7
L293D
24 25
15
16
13
21
6
17
11
20
19
18
8
10
7
22
14
12
5
23
2524
1
9
26 27
Prototyping Environment
The Fritzing Creator Kit contains the base plate on which the Arduino is screwed and the breadboards are glued. Remember that once the breadboards are glued, they can't be detached!
The breadboards are equipped with foam adhesive and a protective film on their underside.
Assembly
1. Remove the backing from the first breadboard and place it onto the base plate as shown in the illus-tration. Make sure the tabs on the long edge are pointing to the interior.
2. Remove the backing from the second breadboard and slide it from above over the tabs of the first breadboard.
3. Use the screws and spacers to fix the Arduino board on the base plate. Tighten the screws by hand.
2
3
1
28 29
Arduino Uno Installation
To use the Arduino-board, you must first download the Arduino Software from www.arduino.cc and install it. Then you can connect the computer to the Arduino board with the supplied USB cable. You will still have to install a driver, depending on your operating system : www.arduino.cc/en/Guide/HomePage.
Installing the driver for Windows*
Connect the Arduino to the PC and wait for the automatic driver installation process to begin.
After a few moments, the installation will fail. Now, open the Control Panel > System & Security, and select System > Device Manager.
Under sub-item Ports (COM/LPT) appears »Unknown Device« or »Arduino UNO (COMxx)«.
Right click on it and choose the »Update Driver Software« option.
Select the »Browse my Computer for Driver software« option, and navigate to the Arduino Software folder you downloaded.
Select the Drivers subfolder. Windows will install the driver from there.
Installing the driver for OSXThe Arduino is immediately ready for use. Simply copy
the Arduino Software into the Applications folder.
Installing the driver for LinuxYou can find Linux drivers and manuals under
www.arduino.cc/playground/Learning/Linux. If you can launch the Arduino Software now, you're ready for the next step. Otherwise, please visit our troubleshooting page www.fritzing.org/forum/creatorkit/troubleshooting
Creator Kit Software Package
The Creator Kit also includes software examples. Download them at www.fritzing.org/creatorkit-code, and extract the zip file. It contains:
creator-kit-de > Fritzing Creator Kit Arduino sketches* > Processing Processing sketches > Fritzing Fritzing schematics
Copy the Fritzing Creator Kit folder into the Arduino user folder:
WindowsArduino user folder: /Documents/Arduino
MacArduino user folder: /Documents/Arduino
LinuxDepending on your distribution, you will find the corresponding instructions under arduino.cc/playground/Learning/Linux
Now you will find the Fritzing Creator Kit program examples under File/Sketchbook/Fritzing Creator Kit/ in the Arduino software.
The download package also contains program examples for Processing. You will need them for the chapter Arduino meets Processing. They are in the Processing folder and can be directly opened later on in the Processing Software.
* Sketch is the
program code used
by Arduino and
Processing* not needed when
using the Arduino
Installer for Windows
30 31
13 12 11 10
9 8 7 6 5 4 3 2
L
5V
A0
ANALOG IN
AREF
1
GND
TX
RX
RESET
3V3
A1
A2
A3
A4
A5
VIN
GND
GND
DIGITAL (PWM= )
ArduinoTM
IOREF
ICSP
ICSP2
ON
POWER
01TX0
RX0R���T
Arduino Board
The Arduino UNO board is a small printed circuit board with a microcontroller chip mounted on it. A microcon-troller is a small computer that has input and output channels and can be programmed. The Arduino board has a USB port with which it can be connected to the computer. A software program also called Arduino is used for programming. Arduino programs are called sketches. Once the board is programmed, it also works without a computer, for example if it's connected to a power supply (7 – 12 V) or batteries. (see page 102 – Battery).
5 V = positive pole GND = negative pole
There are three GND pins that are connected to each other in the interior of the board, so it makes no difference which GND pin you use. GND is the abbrevia-tion for ground.
dIGITAL PINS
USB
ExTERNALPOwER SUPPLy
MICRO- CONTROLLER
SUPPLy PINS ANALOG INPUT PINS
Rx/Tx LEdS*
* RX/TX LEDs
These LEDs show
transmission (TX
= transmit) and
reception (RX =
receive) from the
Arduino board to the
computer.
32 33
Digital Output
di | gi | tal :
whatever can assume two states, such as on / off, true / false
out | put
in the Arduino world, whatever can be turned on or off by a microcontroller, such as LEds, motors, magnets, light bulbs or speakers
2. In this chapter:
you will blink an LEd.
you will learn what voltage and current really are.
you will learn what a resistor is.
you will build a chaser light.
you will generate faces on a screen.
Fritzing Diagram*
Schematic
An LED lights up when there is a voltage. However, it is important to connect it properly. Attach the long leg (anode) to the circuit's positive pole and the short leg (cathode) to GND.
An LED connected to +5 V and GND lights continu-ously. You can control the LED by using a digital output pin on the Arduino board which can be programmed to HIGH (+5 V) or LOW (GND). Since an LED may be destroyed at 5 V, a series resistor must be integrated in the circuit. At 5 V the resistance should be 220 ohms (Ω) (see p. 47 – Electrical resistance).
Pin 13 on the Arduino board already has a series resistor and a small LED connected to it. However, you can also temporarily connect an LED for testing purposes, as shown in the Fritzing diagram. Attach the long leg to pin 13 and the short leg to the GND pin next to it.
Open the blink example in the Arduino software under File > Sketchbook > Fritzing Creator Kit > Blink.
To transfer the program to the Arduino board, select the corresponding board under Tools > Board > Arduino UNO and the corresponding port* under Tools > Port. On a computer running Windows, it is usually the last entry (eg COM3), on the Mac it can be either the first (to OSX 10.7) or the last (from OSX 10.8) entry (eg dev/tty/usbmodemfa141).
Once you've chosen the correct settings, you can transfer the sketch via File > Upload to the Arduino board. The RX/TX LEDs* on the Arduino will briefly light up first, then the LED on pin13 will start blinking.
See what happens if you turn the LED around.
# 1 : Blink difficulty: easy
Circuit : Fritzing / Blink . fzzCode : Sketchbook / Fritzing Creator Kit / Blink
+–
* serial port
The serial port is
used to exchange
data between
computers and
peripheral devices.
* RX/TX LEDs
These LEDs show
transmission (TX
= transmit) and
reception (RX =
receive) of data
between the Arduino
and the PC.
All files are included
in the download
package (see page
29). You can also
open the schematics
with the Fritzing
Software.
*Fritzing Diagram
The circuit design
is realized with the
Fritzing Software (see
page 116).
36 37
Code
int led = 13;
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH);
delay(1000);
digitalWrite(led, LOW);
delay(1000);
}
If you have never programmed before, jump to the next page Programming: A Short Introduction.
The integer variable (int) called led is created and assigned a value of 13.
setup methodThe command pinMode(led, OUTPUT) declares the digital channel 13 on the Arduino as an output.
loop methodThis command sets the led pin to +5 V (HIGH). This command stops the program for 1000 milliseconds. This command sets the led pin to GND (LOW); This command stops the program for 1000 milliseconds.
Exercise
1. Try to make the light blink at a different rhythm.
2. Try to blink an SOS in the Morse code: short, short, short, long, long, long, short, short, short – pause.
Solutions: Sketchbook / Fritzing Creator Kit / Exercise1_1
Sketchbook / Fritzing Creator Kit / Exercise1_2a
Sketchbook / Fritzing Creator Kit / Exercise1_2b
Output graph
Pin 13
5 V 0 V
0s 1s 2s 3s 4s 5s
The output graph
shows the voltage at
pin 13 and thus the
voltage across the
LED.
Solved
Solved
38 39
PROGRAMMING
A Short Introduction
Programming is actually nothing more than having instructions (commands) executed in a given order or in parallel.
These commands are fixed words to which additional information (arguments) can be passed.
For example, the above command switches +5 V to pin 13 on the Arduino board. Therefore digitalWrite is the command, while 13 and HIGH are the arguments.
Arduino groups commands into two methods that are automatically called up by the Arduino software.
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
digitalWrite(13, HIGH);
The parentheses () indicate that, in both methods, arguments do not need to be passed. The keyword void means that this type of method does not return a result (which means there are also method types where this is not the case). The braces { } contain the actual commands used in the methods.
The setup() method is executed only once while launching Arduino and is used to configure the Arduino.The loop() method is continuously repeated and makes up the actual core of the program.
Variables are another important structure in programming. These are small storage units that can be assigned values. Basically, it's what you've learned in maths: X = 10. X is the variable and its value equals 10.
Variables must be initialised (declared). For this, the variable type and variable name are specified. There is also the option to enter a value directly.
The integer variable of the type int with the name led is created and assigned a value of 13.
Wherever the variable name led is used, it will be replaced by the value 13.
Other variable types are, for example, fractional numbers (float), letters (char) or character strings (String).
For more information, go to: www.codeacademy.com.void loop(){
}
void setup(){
}
int led = 13;
digitalWrite(led, HIGH);
40 41
ELECTRONIC BASICS 1:
Voltage, Current and Power
The Arduino board has an operating voltage of 5 V (volts). When compared with the 230 V (dangerous!) from the mains supply, the 5 V needed by the Arduino are absolutely harmless.
Voltage (U) can be described as the pressure in a line. The more pressure, the more power. This power is what we call electric power (P). It also depends on the flow of current. Current (I) is the amount of electrons flowing through a line. The "thicker" the line (conductivity), the more current can flow through it. A typical LED has a current consumption of 20 mA (milliamps).
Current always flows from the positive pole to the negative pole. Arduino calls the positive pole 5 V or +5 V, and the negative pole is called ground (GND).
Don't worry if you don't understand this yet. Just follow the instructions and you'll learn just by doing.
The field of voltage, current, and power is of course far more complex. If you want to know more about the topic, I recommend you to go to the Wikipedia portal on electronics: en.wikipedia.org/wiki/Portal:Electronics
I in A
Uin V
Rin Ω
10A A COM VΩ
I in A
Uin V
Rin Ω
10A A COM VΩ
I in A
Uin V
Rin Ω
10A A COM VΩ
MEASURING VOLTAGE
Voltage is measured
at points that have a
voltage.
MEASURING CURRENT
The current is
measured by inter-
rupting the circuit
and bridging it with
the meter.
MEASURING RESISTANCE
The resistance of a
component can be
measured directly,
as shown in the
illustration.
Voltage and current in a circuit are measured with a multimeter (not included in the Kit). Make sure you connect and adjust the device correctly.
42 43
Fritzing diagram
Schematic
We will now build an LED chaser circuit. Connect eight LEDs each to a resistor and a digital output . If possible, don't use pins 0 and 1 (RX and TX). They are needed to transfer data to the computer.
BreadboardA breadboard is a board with holes into which electrical components can be plugged. It is used for building and testing circuits. Metal channels embedded in the breadboard provide the electrical connections (horizontal orange lines). The topmost and bottommost rows are used for power distribution. This is where you connect and distribute the GND and +5 V from the Arduino board. The holes on the inside of the breadboard are connected in columns pointing to the board centre (see picture).
# 2 : Chaser Lights difficulty: medium
Circuit : Fritzing / Chaserlights . fzzCode : Sketchbook / Fritzing Creator Kit / Chaserlights
44 45
Code
int pinsTotal=8;
int pins[] = {2,3,4,5,6,7,8,9};
void setup() {
for (int i=0; i<pinsTotal; i=i+1){
pinMode(pins[i], OUTPUT);
}
}
void loop() {
for (int i=0; i<pinsTotal; i=i+1){
digitalWrite(pins[i], HIGH);
delay(100);
digitalWrite(pins[i], LOW);
}
for (int i=pinsTotal-1; i>0; i=i–1){
digitalWrite(pins[i], HIGH);
delay(100);
digitalWrite(pins[i], LOW);
}
}
ArrayAn array is a list of several variables of the same variable type.
In the program, an array of the int type is created, and eight entries are assigned to it.
The storage locations of the array can be accessed by: pins[0] is 2, pins[1] is 3, etc. The first position in the array is 0. That is, you access the array from 0 to 7 rather than from 1 to 8.
for loopThe for loop is a repetition with a termination condition. In the parentheses, the starting value (int i=0), the conditional statement (i<pinsTotal) and action (i=i+1)* are defined as parameters. Thus, the variable i is incremented by 1 each time the loop is executed. As soon as the value of i is no longer inferior to pinsTotal, the repetition of the loop is terminated.
With the for loop, all eight pins can be declared as OUTPUT with just three lines of code.
Exercise
1. Try to make the chaser lights run from both sides inwards.
Solution: Sketchbook / Fritzing Creator Kit / Exercise2_1
Solved
*instead of using
i=i+1 you can write
i++
46 47
A series resistor must fulfil two tasks: on the one hand, it must compensate the voltage difference between the voltage needed to operate the Arduino (5 V) and the operating voltage of the LED (2.1 V); on the other hand, it must limit the current flowing through the line to the amount the LED can tolerate (0.02 A). You can find component-specific information on data sheets on the Internet.
The voltage across a series resistor results from:
When applied to the upper formula we get
Therefore, under ideal conditions, in this example the resistance should be 145 Ω (ohms). As resistors are sold at fixed values (E-series), you can simply use one with a higher value. For LEDs at 5 volts it is common to use a resistor of 220 ohms.
ELECTRONIC BASICS 2:
Electrical Resistance
As we have already seen in Electronic Basics 1, the flow of current depends on conductivity. If conductivity is reduced at any point by means of a resistor, current flow will be limited in the entire line. The power drop is converted into heat in the resistor.
Now if you connect an LED, for example, and a resistor in a row, both components will share the voltage. At the same time the resistance will limit current flow.
This type of connection is called a series connection and is also referred to as a voltage divider. The current in this circuit is the same at all points. We took advantage of this effect in the previous example when we connected a series resistor to protect the LED against excessive voltage and high current.
Formula
Uv = Total Voltage – Operating Voltage of LED
Uv = Utot – Uled
Uv = 5 V – 2.1 V = 2.9 V
Formula
Rv = Uv / I
Series resistor = Voltage across resistor / Current
SERIES RESISTOR
Formula
Rv = Uv / I
Rv = 2.9 V / 0.02 A = 145 Ω
Abbreviation:
Normal 5 mm LEDs
(except low current
LEDs) almost always
work with a 220 ohm
resistor.
48 49
1 0 0 · 1021 0 · 103
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
8
9
0
1
2
3
4
5
6
7
0.1
0.01
1%
2%
5%
10%
1%
2%
5%
10%
Carbon film resistors are orange and have a four band colour code. 10 · 103 = 10 000 ohm = 10 kOhm
Metal film resistorsare blue and have a five band colour code. 100 · 102 = 10 000 ohm = 10 kOhm
Tolerance
Percentage by which
resistance value may
vary.
Tolerance
Percentage by which
resistance value may
vary.
The Fritzing Creator Kit uses film resistors. They are made of an insulator coated with a resistive film connecting the two outer leads.
Resistors are distinguished by the resistive material used in their coating, such as carbon film or metal film. Metal film resistors are known for their high precision.
Exercise
1. What happens when you connect the 100 kΩ resistor to the LED?
2. What happens if you connect two 220 Ω resistors one after the other to the LED?
Solved!
Solved!
50 51
Schematic
Fritzing diagram
A matrix display consists of a number of LEDs arranged on a grid.
LEDs are forward- biased and reverse-biased. If you let the current flow in the reverse direction (cathode to anode) through the LED, the LED will not light up. The LED matrix takes advantage of this principle.
The schematic view illustrates the internal structure. The numbers on the matrix symbol identify the pins. They are counted counterclockwise from the bottom left.
This is how the program works: If you switch the first column to HIGH (+5 V) and the first row to LOW (GND), the LED where the column and the row meet will light up. To turn all the LEDs on and off individually, the rows must be run individually. Thus, the first row is set to HIGH, while the columns are switched on and off according to the display. Next, the first row is switched to LOW and the second row to HIGH, etc.
+
# 3 : Matrix difficulty: hard
Circuit : Fritzing / Matrix . fzzCode : Sketchbook / Fritzing Creator Kit / Matrix
TExT ON MATRIx ON THIS SIdE
To bridge longer
distances you can
simply connect two
wires.
Make sure you insert the matrix in the right
direction. The notches on the edge of the
matrix must be arranged as shown in the
picture, the text is on the lower side.
52 53
Code
int rowPins[8] = {9,3,2,12,15,11,7,6};
int columnPins[8] = {13,8,17,10,5,16,4,14};
int image[8][8]={
{0,1,0,0,0,0,1,0},
{1,1,1,0,0,1,1,1},
{0,1,0,0,0,0,1,0},
{0,0,0,1,1,0,0,0},
{0,0,0,1,1,0,0,0},
{1,0,0,0,0,0,0,1},
{0,1,1,1,1,1,1,0},
{0,0,1,1,1,1,0,0}
};
void setup(){
for (int i=0; i<8; i++){
pinMode(rowPins[i],OUTPUT);
pinMode(columnPins[i],OUTPUT);
}
}
void loop () {
for (int y=0; y<8; y++){
for (int x=0; x<8; x++){
if (image[x][y]==1){
digitalWrite(columnPins[x],HIGH);
} else {
digitalWrite(columnPins[x],LOW);
}
}
digitalWrite(rowPins[y],LOW);
delayMicroseconds(10);
digitalWrite(rowPins[y],HIGH);
}
}
The arrays rowPins[] and columnPins[] store information on how the matrix display is connected. For a single LED to light up, the columnPin must be set to HIGH and the rowPin set to LOW.
The array image[][] controls the matrix. 0 means off, 1 means on. To understand how this works, simply change the entries in the array.
Here all the pins used are switched to output.
The two nested for loops produce two changing coordinates (x and y).
When the image array at point x,y equals 1, the LED lights up.
On page 90 you will learn how to build a ping pong game with the matrix.
Exercise
1. Change the entries in the array image[8][8] to change the display on the screen!
2. Develop an animation with two images.
Solutions: Sketchbook / Fritzing Creator Kit / Exercise3_1
Sketchbook / Fritzing Creator Kit / Exercise3_2
Please note the
double equal sign
(==). Solved
Solved
54 55
3. Digital Input
di | gi | tal:
whatever can assume two states, such as on / off, true / false
in | put:
all events that can be detected by the Arduino board, such as pressing a button, closing a magnetic switch or crossing a light gate.
In this chapter:you will build a circuit with a push-button.
you'll get to know the if statement.
you will have your fortune told.
Fritzing diagram
Schematic
To add some kind of interaction, we use a digital input. A digital input is an input that can assume two states. A switch for example is either switched on or off, a push-button* either pressed or not pressed.
Digital inputs, such as a push-button, are connected to the GND and to a digital pin on the Arduino board. At the same time, a resistor (pull-up resistor) is connected between the Arduino's digital pin and the +5 V. It deflects electrical interference when the button is not pressed. When the button is pressed, the Arduino pin is connected to GND (LOW), when it is open, there is a connection through the resistor to the +5 V (HIGH).
The circuit is made up of two LEDs with series resistors and a push-button with a pull-up resistor.
# 4 : Flip Flop difficulty: medium
Circuit : Fritzing / FlipFlop . fzzCode : Sketchbook / Fritzing Creator Kit / FlipFlop
*Button
A push-button (as
opposed to a switch)
closes an electrical
circuit as long as you
press it. When you
stop pressing it, the
circuit opens again.
58 59
Code
int buttonPin=2;
int greenLED=9;
int redLED=10;
void setup(){
pinMode(buttonPin, INPUT);
pinMode(greenLED, OUTPUT);
pinMode(redLED, OUTPUT);
}
void loop(){
if (digitalRead(buttonPin)==LOW){
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, LOW);
} else {
digitalWrite(greenLED, LOW);
digitalWrite(redLED, HIGH);
}
}
The pin connected to the button is declared as (INPUT).
if statementThe if statement checks whether the condition in the parentheses is true, and performs the commands in the braces accordingly. The double equal sign must be used for checking (==).
The command digitalRead(buttonPin) returns LOW when the push-button is pressed. When the button is not pressed, it is HIGH.
If the condition is false, the else statement can be used to perform alternative functions. It will only be executed when the condition in the if statement is false.
Exercise
1. Write a program in which you can switch the LEDs on and off without having to keep the button pressed.
Solution: Sketchbook / Fritzing Creator Kit / Exercise4_1
Solved
60 61
Fritzing diagram
Schematic
Now let's build our own private fortuneteller who will predict our future. The circuit is made up of five LEDs and a tilt switch. Take the paper model "Fortuneteller" and place it over the LEDs.
How it's used: Ask a question and give the circuit a good shake. Your answer will appear as if by magic. But don't take the answers too seriously – we can't assume any responsibility! ;)
Paper cut -out model
# 5 : Fortuneteller difficulty: medium
Circuit : Fritzing / Fortuneteller . fzzCode : Sketchbook / Fritzing Creator Kit / Fortuneteller
62 63
Code
int pins[] = {8,9,10,11,12};
int tiltPin = 3;
void setup() {
for (int i=0; i<5; i=i+1){
pinMode(pins[i],OUTPUT);
}
pinMode(tiltPin,INPUT);
randomSeed(analogRead(0));
}
void loop() {
if (digitalRead(tiltPin)==HIGH){
for (int i=0; i<5; i=i+1){
digitalWrite(pins[i],LOW);
}
int myRandom=random(0,5);
digitalWrite(pins[myRandom],HIGH);
delay(20);
}
}
randomSeedThis command initializes the random function. Go here for more information: http://arduino.cc/en/Reference/RandomSeed
randomThe random () function returns a random number, in our example from 0 – 5 (the 5 is excluded though). The corre-sponding pin in the array will be switched on.
64 65
4. Analog Output
ana | log :
whatever can assume a variety of different states, such as pressure, brightness, temperature or angle of rotation
out | put :
in the Arduino world, whatever can be turned on or off by a microcontroller, such as LEds, motors, magnets, light bulbs or speakers
In this chapter:you will dim an LEd through a PwM channel.
you will build a night light.
you will get to know the transistor.
Fritzing diagram
Schematic
We already know how to make an LED go on and off and how to read a button. Both are digital processes, that is, they only know two states. Now we're ready to learn about analog output. For example, it is used to influence the brightness of LEDs or the rotation speed of motors.
An Arduino board cannot realise a real analog output, so it uses a trick to do this. It simply switches a channel on and off very quickly. This process is called PWM (Pulse Width Modulation). The ratio between on and off is what controls – for example – the brightness of an LED (or how bright the LED appears to us).
The Arduino UNO board has six PWM channels, marked on the board with a wavy line. The pulse width modulation can output values from 0 (all the way off) to 255 (all the way on).*
The circuit example consists of an LED that is connected to a PWM channel through a series resistor.
* The Arduino has an
8-bit PWM output.
Each bit can be 0 or
1, this results is 28
= 256 states, or 0 to
255.
# 6 : Fading difficulty: easy
Circuit : Fritzing / Fading . fzzCode : Sketchbook / Fritzing Creator Kit / Fading
68 69
Output graph
Pin 13
5 V 0 V
0s 0,25s 0,5s 0,75s 1s
Code
int ledPin = 9;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop(){
for (int lightValue=0; lightValue<=255; lightValue++){
analogWrite(ledPin, lightValue);
delay(2);
}
for (int lightValue=255; lightValue>=0; lightValue--){
analogWrite(ledPin, lightValue);
delay(2);
}
}
The for loop increments the fadeValue from 0 bis 255 (lightValue++ keeps adding 1 to the variable). The analogWrite command sends this value to the LED. It will increasingly grow brighter.
The second for loop decrements the fadeValue from 255 to 0 (lightValue–– keeps counting the variable down by 1). The LED will grow dim again.
Exercise
1. Do the same in reverse with a second LED on another pin. Make sure it's a PWM pin.
Solution: Sketchbook / Fritzing Creator Kit / Exercise6_1
The voltage rises
to 5 V, then falls
back to 0 V. (As
mentioned on the
previous page, this is
done through rapid
switching between
the on and off
positions – PWM).
Solved
70 71
Fritzing diagram
Schematic
The next project is a night light that slowly changes its colour. An RGB LED is used for this.
An RGB LED is an LED package in which three LEDs (red, green and blue) are embedded. They share one common leg. The shared leg in the kit's RGB LED is the cathode (negative). The three remaining leads (anodes) are each assigned one colour. Each built-in LED requires its own series resistor.
For a good colour combination, wrap a piece of white paper around the LED, or stick it into a ping pong ball (drill a 5mm hole).
Find the programming explanation in the programming code of the example.
# 7 : Night Light difficulty: medium
Circuit : Fritzing / Nightlight . fzzCode : Sketchbook / Fritzing Creator Kit / Nightlight
REd
CATHOdE (-)
GREEN
BLUE
72 73
ELECTRONIC BASICS 3:
Amplification
Basically, the Arduino board is a control unit. It supplies each channel with a current of 40 mA. This is sufficient for smaller loads such as LEDs. For larger loads (such as motors, solenoids or valves), an additional electronic switch is required to conduct larger currents.
This electronic switch is a transistor. A field effect transistor (FET N-Chanel) is included in the kit. It has three terminals: Gate, drain and source
Source is connected to GND, drain connected to the load (for example, the motor). When a positive voltage (HIGH) is supplied to the gate, the current flows between drain and source. As a transistor switches with great speed, it can also amplify PWM signals.
The example shows a circuit with a separate power supply. GND of the power source must be connected to GND of the Arduino. The code from the blink or fading examples can be used for this. The pin from the blink example must be changed to pin 9.
MOSFET
Gate Drain Source
Fritzing diagram
Schematic
Preparing a motor
cable: (1 Carefully cut
the cable insulation
with a knife and pull
it off (2), form the
wire ends by twisting
the strands (3) and
plug them into the
extension cords
(4) to connect the
motor.
1 2
3 4
74 75
Fritzing diagram
Motor Control with an H-BridgeCircuit : Fritzing / H-Bridge . fzzCode : Sketchbook / Fritzing Creator Kit / Motor
In the section Electronic Basics 3: Amplification, you used a transistor to control a motor. With this technique you can control the speed of a motor, but not the direction of its rotation.
An easy way to make electric motors rotate in both directions is by using an H-bridge. This is an IC* that is optimised for its use as a motor driver (L293D). It can control two motors independently.
The illustration shows a motor controlled by the Arduino. The power is supplied by a battery, though of course a mains adaptor may also be used. If the motors are small (eg vibration motors), they can be powered directly from the Arduino. To do this, you only have to connect the orange wire of the H-Bridge to the circuit's +5 V pin.
The H-Bridge L293D can handle a brief current of 1.2 A (PEAK), and a continuous current of 600 mA per channel.
A major advantage of the L293D are the integrated flyback diodes, which retain the induced current that forms when the motor is still turning but switched off (http://en.wikipedia.org/wiki/Flyback_diode).
* Integrated Circuit
It's a chip in which
different compo-
nents are built into a
small space.
Fritzing diagram
Controlling one
motor
Controlling two
motors (there is
only one motor in
the kit)
A notch or a
dot are used to identify
the orientation of an IC.L293D
16 15 14 13 12 11 10 9
1 2 3 4 5 6 7 8
76 77
Code
int motor_A=6;
int motor_B=5;
int motor_Speed=3;
void setup(){
pinMode(motor_A,OUTPUT);
pinMode(motor_B,OUTPUT);
}
void loop(){
digitalWrite(motor_A,HIGH);
digitalWrite(motor_B,LOW);
for (int i=0; i<256; i+=5){
analogWrite(motor_Speed,i);
delay(20);
}
for (int i=255; i>0; i-=5){
analogWrite(motor_Speed,i);
delay(20);
}
digitalWrite(motor_A,LOW);
digitalWrite(motor_B,HIGH);
for (int i=0; i<256; i+=5){
analogWrite(motor_Speed,i);
delay(20);
}
for (int i=255; i>0; i-=5){
analogWrite(motor_Speed,i);
delay(20);
}
}
Determines the direction of the motor's rotation.
Rotation speed increases from 0 – 255, then it decreases again to 0.
Rotation direction is reversed.
Rotation speed increases again from 0 – 255, then it decreases again to 0.
78 79
5. Analog Input In this chapter:
you will understand how a potentiometer is built and how it works.
you will be introduced to a reference resistor.
you will develop an automatic lighting system for cars.
you will reproduce a classic game.
ana | log :
whatever can assume a range of different states, such as pressure, brightness, temperature or angle of rotation
in | put :
external influences that can be interpreted by the Arduino board, such as the angle of a potentiometer, or reading sensors for light, humidity, or temperature
Fritzing diagram
Schematic
A potentiometer is a variable resistor. It is made of an arc-shaped resistive element that is electronically divided into two parts by a wiper. Moving the wiper on the resistive element changes the proportion of the resistance on each side of it. This proportion is read by the Arduino board to determine the position.
The outer leads of the potentiometer are connected to +5 V and GND, the centre lead to an analog input.
Values are read between 0 and 1023*. In the circuit example above, this value is converted to the value range of 0 – 255 with the map function, and transmitted to an LED as analog output (PWM).
# 8 : Potentiometer difficulty: medium
Circuit : Fritzing / Potentiometer . fzzCode : Sketchbook / Fritzing Creator Kit / Potentiometer
PARTIAL RESISTANCE 1
+5 V
ANALOG
GNd
wIPER (OR TAP)
PARTIAL RESISTANCE 2
RESISTIVE ELEMENT
* When compared
with
the 8 bit PWM output
(see page 67) the res-
olution of an analog
input is higher:
210 = 1024 states, or
0 – 1023.
If you bend the three
legs of the potenti-
ometer to 90°, it will
be easier to plug into
the breadboard.
82 83
Code
int ledGreen = 6;
int ledRed = 5;
int potPin = 0;
void setup(){
}
void loop () {
int value = analogRead(potPin);
int redValue = map(value,0,1023,0,255);
int greenValue = map(value,0,1023,255,0);
analogWrite(ledRed,redValue);
analogWrite(ledGreen,greenValue);
}
mapThe map() command converts an incoming value from one value range to another. In this case, the value range of the analog input (0 to 1023) is converted to the range of the analog output (0 to 255).
84 85
ELECTRONIC BASICS 4:
Reference Resistor
The analog input on the Arduino board converts a voltage between 0 and 5 V to a value from 0 to 1023 (10-bit analog-to-digital converter). To be able to measure this voltage, a reference resistor is needed for sensors such as photoresistors. The reference resistor is connected in series with the sensor. One side of the circuit is connected to GND and the other side to +5 V. The line that connects both is hooked to the analog input.
You can either try it out or calculate the value for the reference resistor. To calculate it, you have to measure the minimum and maximum resistance with a meter. For example, if you want to use a photoresistor, then measure its resistance in both its darkest and brightest situations. Now add both values and divide the sum by two. The result is the ideal reference resistor value. Since resistors aren't available with every value (E series*), simply use the value closest to the one you need.
I in A
Uin V
Rin Ω
10A A COM VΩ
* An E-series is
a mathematical
sequence of
calculated values.
Formula
Rref = (Rmin + Rmax) / 2
Fritzing diagram
Fritzing diagram
Connecting a potenti-
ometer.
Connecting a
photoresistor and
its corresponding
reference resistor.
86 87
Fritzing diagram
Schematic
A light dependent resistor (LDR) or photoresistor is made of a material that changes its resistance in proportion to the intensity of the light it is exposed to. The more light that falls on it, the lower the resistance. In our example, we will take advantage of this capability to automatically turn on the headlights of a car.
The photoresistor leads are very long. Make sure that there is no contact between them.
Serial interfaceTo find out the LDR's resistance values you can use the serial port.
The serial port provides a data link between the Arduino and your computer. It is initialised in setup with the command
Serial.begin(baudrate);. The baud rate is the transmission speed, which can be 9600, 28800, 57600, or 115200 bits per second.
After it is initialised, you can send data to the serial port with the command Serial.println(value); The data may consist either in variables or text. Open the serial monitor in Arduino software: Tools > Serial Monitor. This is where the files are shown. The baud rate must be the same as in the code. You can adjust it on the bottom line of the serial monitor.
# 9 : Automatic Lighting System difficulty: medium Circuit : Fritzing / AutomaticLightingSystem . fzz Code : Sketchbook / Fritzing Creator Kit / AutomaticLightingSystem
Arduino software
serial monitor
88 89
longThe variable type long is similar to int, but it lets you process larger numbers. These are needed to set the timer.
Serial.begin(baud);starts the serial communication.
Serial.println(daten);sends the contents of the variable value to the serial port.
timerWhen the intensity of the light is less than the switching threshold, the light is switched on and a timer variable (timer) is set to millis(). The command millis() returns the number of milliseconds that have elapsed since the last Arduino reset. As soon as the light intensity is greater than the switching threshold again, it checks whether the current milliseconds is greater than the sum of the timer variable plus the waiting time (in other words it checks whether the waiting time has passed). If so, the headlamps are switched off again.
Code
int lightsensorPin = 0;
int headlightsPin = 2;
int switchingthreshold= 300;
int wait = 1000;
long timer = 0;
int value;
void setup(){
Serial.begin(9600);
pinMode(headlightsPin,OUTPUT);
}
void loop(){
value = analogRead(lightsensorPin);
Serial.println(value);
if (value<switchingthreshold){
timer=millis();
digitalWrite(headlightsPin, HIGH);
} else if (millis()>wait+timer){
digitalWrite(headlightsPin, LOW);
}
delay(10);
}
90 91
Fritzing diagram
Schematic
You can also create a simple but exciting Ping Pong game with the Arduino. The LED display is connected as in the matrix example. In this case, two potentiometers are added as game controllers.
# 10 : Ping Pong difficulty: hard
Circuit : Fritzing / PingPong . fzzCode : Sketchbook / Fritzing Creator Kit / PingPong
+
To bridge longer
distances you can
simply connect two
wires.
TExT ON MATRIx ON THIS SIdE.
92 93
6. Servomotor, Sound
Ser | vo | mo | tor :
converts electrical signals into motion
can be rotated from 0 – 180°
Sound:
a complex acoustic event
in the Arduino environment, the conversion of electrical signals into mechanical vibrations
In this chapter:you will learn all about the structure
and functions of a servomotor.
you will build a robot.
you will generate sounds with your own synthesizer.
the Arduino board will be powered by a battery.
Schematic
The housing of a servomotor contains an electric motor, an electronic control unit to determine the position, and a gear system for high performance. The servo axis can be rotated to 180°.
The servo motor has a cable with three wires. The red wire in the middle must be connected to the +5 V, the brown (or black) to GND and the orange (or yellow) to a digital pin on the Arduino. It is important to connect the servo correctly, otherwise it will be damaged.
Fritzing diagram
# 11 : Servo difficulty: medium
Circuit : Fritzing / Servo . fzzCode : Sketchbook / Fritzing Creator Kit / Servo
ELECTRIC MOTOR
MOTOR CONTROL UNIT
GEAR
POTENTIOMETER TO CONTROL THE ANGLE
CONNECTION CABLE
96 97
Code
#include <Servo.h>
Servo myservo;
int potpin = 0;
int val;
void setup()
{
myservo.attach(9);
}
void loop()
{
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 179);
myservo.write(val);
delay(15);
}
LibraryA library (program library) extends the range of commands to include special functions, such as, in this case, servo control. A library is composed of one or more files. It is integrated with #include.
The method myservo.attach(9) connects the servo functionality to pin 9.
The method myservo.write(val) positions the servo to val, whereby the value of val should be between 0 and 179. Therefore, the servo can be rotated 180°.
Paper cut -out model
You will receive a small application for the servo with the paper cut-out model "Robots". Enjoy :)
98 99
Schematic
Fritzing diagram We can use a Piezo speaker to generate sounds. It converts electrical frequencies into sound waves. Different sound waves are produced by rapidly switching the voltage on and off (pulse).
Here we will begin with something a bit more complex – we'll build a Piezo synthesizer. The program text processes two parameters, which are read from two potentiometers. One potentiometer affects the pitch level, the other the duratioin of a continuous repeated loop.
# 12 : Synthesizer difficulty: medium
Circuit : Fritzing / synthesizer. fzzCode : Sketchbook / Fritzing Creator Kit / Synthesizer
100 101
Code
int buzzerPin = 8;
int potPin1 = 0;
int potPin2 = 1;
int toneHeight, lfo;
void setup() {
pinMode(buzzerPin, OUTPUT);
}
void play(int myPitchLevel) {
digitalWrite(buzzerPin, HIGH);
delayMicroseconds(myPitchLevel);
digitalWrite(buzzerPin, LOW);
delayMicroseconds(myPitchLevel);
}
void loop() {
toneHeight=analogRead(potPin1);
lfo=analogRead(potPin2);
for (int i = (lfo/10); i > 0; i--) {
play(toneHeight);
}
delayMicroseconds(lfo);
for (int i = 0; i < lfo/10; i++) {
play(toneHeight);
}
}
your own methodThe play() method is your own method. Own methods are always useful when a task has to be processed over and over again. In this case, an argument is passed and is available within this method under the variable name myPitchLevel. It is called up with play(value).
102 103
Battery
To operate the Arduino board with a battery, you can either connect the battery to the DC power jack with an adapter, or connect it directly to GND and the Vin pin.
In the latter case, you should pay attention to the correct polarity, otherwise the Arduino could be damaged. The Fritzing Creator Kit includes a 9 V battery clip, with a black and a red wire. The red wire is connected to the positive pole of the battery and must be plugged into the Vin. The black cable is GND, and is connected to the GND pin.
You can fasten the battery with self-adhesive Velcro or double-sided tape on the base plate.
Fritzing diagram
Preparing the 9 V-clip
wires: Carefully cut
the wire insulation
with a knife, then
pull it off.
1 2
3 4
Fritzing diagram
104 105
Arduino meets Processing
7.
Ar | du | i | no:
Physical Computing Platform
lets electronic projects come alive
Pro | cess | ing:
Java-based programming language
perfect for creative ideas
In this chapter:you will control an LEd with the
Processing software.
you will use a potentiometer to draw on a virtual magic drawing board.
you will build a dinosaur that notifies you of incoming Twitter news.
Firmata is a protocol for the communication between a microcontroller (such as the Arduino) and software running on a computer. A protocol can be considered as a language with which two different systems can communicate.
In the following section we will let an Arduino and the Processing software "talk" to each other.
Preparing the ArduinoOpen the Arduino software program File > Examples > Firmata > StandardFirmata and transfer it to the Arduino board. Arduino is now ready for use in Processing and does not need to be reprogrammed.
Installing ProcessingProcessing is a Java-based, open programming environment. Download at www.processing.org. Please download a 2.x version and install it for further use.
Processing is particularly well suited for programming generative graphics, animations, and interactivity.
Install the Firmata library for Processing.To prepare Processing for Arduino, a few more steps are still needed:
1. Download the Firmata program library for your version of Processing: http://playground.arduino.cc/interfacing/processing
2. Open the Processing Sketchbook folder. (You will find the path if you go to Processing and click on Processing > File> Preferences.)
3. If the Sketchbook folder still hasn't got a libraries folder, create one yourself. Pay attention to the spelling: libraries.
4. Then copy the Firmata program library into the folder.
5. The library will be automatically loaded when you run Processing.
13
12
11
10 9 8 7 6 5 4 3 2
L
5V
A0
ANALOG IN
AREF
1
GND
TX
RX
RESET
3V3
A1
A2
A3
A4
A5
VIN
GND
GND
DIGITAL (PWM= )
ArduinoTM
IOREF
ICSP
ICSP2
ON
POWER
01TX0
RX0RESET
Processing Software Arduino board
Firmata
Arduino code: Examples / Firmata / StandardFirmata
Processing library: Firmata
Processing code: e.g. Processing / RGB
Firmata
* We tested the
Firmata support for
Processing 1.5.1 and
2.1 at the time of
printing this booklet
108 109
Preparing the circuitBuild the following circuit (Processing RGB – see below).
Open program exampleYou will find the folder Processing in the Fritzing Creator Kit software package you have downloaded. Open the RGB file from the Processing folder.
Start up the program Sketch > Run.
Selecting the portThe Processing window has a black output area at the bottom. When the program is launched, all connected devices are displayed. Remember the number that appears at the beginning (e.g.: 0) of the line referring to the Arduino. On a computer running Windows, it is usually the last entry (eg COM3), on a Mac it is the first or the last entry (z.B. dev/tty/usbmodemfa141). Close the program, and insert the number into the program code line: myArduino = new Arduino(this, Arduino.list()[0], 57600);
Restart the program Sketch > Run.
Fritzing diagram
Screenshot Processing
# 13 : Processing RGBdatei : Processing_RGB.fzzCode : Beispiele / Firmata / StandardFirmata Processing code : Processing / RGB
Processing
The Processing
software probably
looks very familiar
to you. The Arduino
software is modelled
after it.
Find the program-
ming explanation in
the code.
110 111
Fritzing diagram Screenshot Processing
Inspired by the legendary Etch-A-Sketch, two knobs are used to move a drawing tool in the X and Y directions on the computer screen. If you want to draw a new picture, simply shake the base plate and the canvas will be "emptied".
As we have seen in the previous example, the program StandardFirmata must first be installed on the Arduino board.
You'll have to select the right port in Processing again (see page 108, Select Port).
# 14 : Magic Board difficulty: medium
Circuit : Fritzing / Magic Board . fzzCode : Beispiele / Firmata / StandardFirmata Processing code : Processing / Magic Board
112 113
Fritzing diagram
+
# 15 : TwitterSaurus difficulty: hard
Circuit : Fritzing / TwitterSaurus . fzzProcessing code : Processing / TwitterSaurus
This is how to obtain your access data:
1. Go to https://dev.twitter.com/apps/new and login with your user name and password.
2. Fill out the "Create an application" form – you are free to choose the name, description and website.
3. Confirm the terms and conditions, fill in the captcha and click on Submit.
4. On this page you will find the Consumer key and the Consumer secret. Save them to a text file.
5. Now, click on Create my access token. Save both token values Access token and Access token secret.
6. Open the TwitterSaurus file in Processing, and copy the four values into the setup method.
Twitter Saurus is a program that displays a tweet whenever that tweet contains a certain search term. In addition, the Twitter Saurus will open its mouth and emit a sound.
Extend the servo cable to the length you need. As in the Firmata example, the StandardFirmata program must previously be installed on the Arduino for this.
We still need to prepare a few things. The Twitter Saurus program for Processing uses the Twitter API. It enables people to develop their own programs around Twitter. For security reasons, an OAuth authorization is necessary for this.
You will find a paper
cut-out model of
the dinosaur in the
Creator Kit.
114 115
8.
From prototype to product
pro | to | type:
model created from a project idea
usually unique
pro | duct:
finished result
project that can be produced on a large-scale
In this chapter:you will learn about the usefulness of
PCBs for you and your projects.
you will develop your first circuit layout.
you will get to know the methods used for mounting components on circuit boards.
Fritzing
Fritzing is a project that aims to make the creative use of interactive electronics accessible to everyone. We want everyone to be able to realize their own ideas quickly and easily, from initial sketch to finished product.
The centerpiece of the Fritzing project is the free Fritzing software, enabling you to document projects in a clear and intuitive way. Furthermore, the software makes designing your own professional printed circuit board an easy task. Simply download it at http://fritzing.org/download .
Fritzing has become a standard, and a considerable number of creative electronics projects are available in a variety of books and websites that will make it easy for you to learn and invent. You will also find an extensive project gallery on the Fritzing website http://fritzing.org where users meet to share, discuss and develop their creations together. Of course you will also find video tutorials there, and further assistance.
The Creator Kit you have in your hands now is not just a great starter kit for interactive electronics. By buying it, you are also encouraging us to keep developing and improving our our product since all profits are returned to the Fritzing project. Thank you!
Our "Fritzing Fab“ service (http://fab.fritzing.org) offers you the possibility to have your PCBs produced either individually or in larger quantities. This way, you can easily transform your project's breadboard-based prototype into a professional product at a reasonable price.
And what's more: The Fritzing team is very active and offers many workshops. Visit us at http://fritzing.org/events, we just might be in your area.
Screenshot of the
free Fritzing software
118 119
PCBs
Although breadboards are very convenient for designing projects, they are quite fragile and especially don’t travel very well. This is where printed circuit boards (PCBs) come in handy. They provide a strong mechanical attachment for parts and stable electrical connection of electronic components. The wiring is realized by means of copper traces. PCBs are also used to turn a project idea into a real product (for example, the Arduino itself).
The PCB production process can be divided into three parts:
PCB layoutPCB productionassembly
It is quick and easy to create the PCB layout with the Fritzing software.
But professional PCB manufactur-ing is a highly complex process. There are many PCB manufactur-ing services available, but we have introduced our own Fritzing Fab service to make it as easy as possible to go from a PCB layout--created using the Fritzing software--to a finished professional PCB.
Assembly is the process of attaching parts to a board. This can be done by hand (soldering) or by machine. The latter is especially appropriate in mass production. To minimize the costs in mechanical assembly, SMD components should be used. We will be happy to make you an offer: [email protected]
Circuit board
produced with
Fritzing Fab (see
page 125)
COPPER LAyER (FRONT SIdE)
VIASCONNECTION BETwEEN UPPER ANd LOwER COPPER LAyER
CARRIER MATERIAL SUCH AS FIBER REINFORCEd PLASTIC
COPPER LAyER (BACK SIdE)
SOLdER MASK (BACK SIdE)
SOLdER RESIST (BACK SIdE)
SILK SCREEN PRINTING (BACK SIdE)
SOLdER MASK dETERMINES THE AREAS TO BE TINNEd FOR SOLdERING OF COMPONENTS
SOLdER RESIST (FRONT SIdE) COVERS TRACES ANd PROTECTS AGAINST CORROSION ANd MISPLACEd SOLdER
SILK SCREEN POSITION ANd NAMES OF COMPONENTS, INFO OR dECORATION
COMPONENTS
COMPOSITION OF A CIRCUIT BOARd
120 121
The green surface represents the circuit board. You can resize it with the drag and drop function by clicking the corners, or select an alternative shape from the information window, for example »Arduino Shield."
Now you can start arranging the components. It's best to begin with the pins for the Arduino. Move them until they more or less match the marked position. Then click on the board and, in the information window, disable the "Sticky" function. This allows you to slide the board exactly under the pins.
PCB layout
Fritzing diagram
It is very simple to layout a PCB with Fritzing. Let's start with the Fortuneteller example. First, change to the PCB view: View > Show Circuit Board.
122 123
The autorouter suggests trace paths that you can, and sometimes even must, change. You can add a bendpoint to the traces by dragging on a trace at the place at which you would like to add the bendpoint. Traces in yellow are on the board's upper side, traces in orange on the underside. You can "move a trace to the other side of the board" by right clicking it.
After this, you can still add logos and text to the board. You can find these elements in the components library.
The remaining components can now be arranged. Ideally, the lines connecting the pins should intersect as little as possible.
Change the LED labels that are appropriate for a fortune-teller's response. Once an LED is marked, you can also move its label.
Now call up the Autorouting feature in the menu under Routing.
124 125
By selecting Routing > Ground Fill from the menu you can fill the blank areas with copper. The ground fill is connected with GND on the PCB (this reduces electromagnetic interference on the board), whereas the copper fill stays electrically isolated from the rest of the circuit.
Use the Design Rules Check (DRC) from the Routing menu to check the layout at the end. It will find errors such as trace overlaps.
If everything is OK, you'll get a message confirming that it is ready for production. To produce the circuit board, you can export it in the Gerber format, or manufacture it with Fritzing Fab.
Fritzing Fab
Fritzing Fab (fab.fritzing.org) is our production service for printed circuit boards. We have them produced in a professional PCB factory. The number of parameters influencing PCB production is quite large – Fritzing automatically chooses a good set of defaults. To see what the PCB would cost you, simply click on Routing>Fritzing Fab Quote in the Fritzing software.
Finally, the components still have to be soldered.
Finished board
126 127
Mounting the components
There are two methods used for mounting components on a circuit board:
THT (Through-Hole Technology)In THT, the components to be mounted have leads. That is, they have a long terminal ends (legs) that are inserted into the holes in the printed circuit board and are normally soldered at the back. Holes are plated through from top to bottom, which means they are lined with copper. Components are relatively large, but they also withstand greater mechanical stress, which can be an advantage in connectors.
SMT (Surface-Mount Technology)In surface mounting, the components (also called SMD, Surface Mounted Device) are soldered onto pads on the surface of the board; or, alternatively, in a process called reflow, they are attached to the circuit board with the help of solder paste, which melts in the reflow oven. This method need considerably less space than the through-hole technology; however, traces cannot run underneath components, which requires jumping a trace from one side of the board to the other. When a trace jumps from the top to the bottom of a board, the connection between the top and bottom is called a ‘via’.
SMD components are available in different sizes. The size designates the edge length. 0805 means that the length is 08 · 1/100 inch (about 2 mm, while the width is 05 · 1/100 inch (about 1,25 mm).
METALLEAd
THT COMPONENT(RESISTOR)
SMd COMPONENT(RESISTOR)
VIA
SOLdER JOINT
TRACE
1
2
1
2
128 129
Goal achieved!
Congratulations! You've reached the end of this booklet. Now you know what an LED is, and how to turn it on and off. You've blinked an SOS, read push-buttons, had your future told and found out how headlights are switched on in modern cars. You've built robots, and dinosaurs have read your Twitter stream.
I hope the journey was fun, and that now your head is full of ideas that you want carry out. Although it's the end of the booklet, it's by far not the end of the possibilities that Fritzing, Arduino and Co. has in store for you.
I'm already looking forward to your projects. Please share them in the Fritzing project gallery: www.fritzing.org/projects.
Should you have any questions, please visit our forum: www.fritzing.org/forum. In the category Creator Kit you will quickly find help. Of course you are also invited to answer other users' questions. After all, you're an Arduino expert now!
Troubleshooting
Should you have problems while working with the kit, please visit our troubleshooting page at: fritzing.org/forum/creatorkit/troubleshooting.
130 131
The explanations in this booklet were
created and tested to the highest
standards of quality. Nevertheless,
we cannot rule out errors. Should you
notice anything, please write to us:
www.fritzing.org/forum/creatorkit.
All information in this booklet is subject to
change.
Fritzing
a business division of
IxdS GmbH
Paul-Lincke-Ufer 39/40
10999 Berlin
district Court
Berlin-Charlottenburg
Commercial Register: HRB 118950
www.fritzing.org
Fritzing is a trademark of
Friends-of-Fritzing e.V.
Amtsgericht
Berlin-Charlottenburg
VR-Nr: V30985B
cc - by - nc - nd
2014 Fritzing
Concept & Text
Stefan Hermann
Design &
Typesetting
Christian Ivanis
Fonts
OCR A Tribute,
droid Sans
Illustrations
Stefan Hermann
Fabian Althaus
dirk v. Oosterbosch
Fritzing Software
Fritzing Team
Amgad Keshki
Amin Zayani
André Knörig
Anna Heib
Christin Rothe
daniel Clerc
david Elsche
Fabian Althaus
Hans Kadel
Jonathan Cohen
Monique Mathieu
Niklas dünger
Reto wettach
Sevgi Ulas
Stefan Hermann
ImprintAcknowledgements
At this point I would like to thank everybody who has contributed to this booklet. My thanks goes to:
Clemens Gruber, Clemens Winkler, Loris Bottello, Martin Kim Luge, Mey Lean Kronemann, Naomi Knopf, Stella Morelli, Tommaso Bertagnin and Valeria Sanguin, for their inspiring projects; Carsten Niehaus, Christian Benedict, Claudius Lazzeroni, Clemens Gruber, Detlef Meißner, Frank Träger, Franz Klein-Reesink, Hubertus v. Fürstenberg, Sabine and Christian Aschoff as well as Thomas Sturm, for their feedback to the first prototype of this booklet.
Thanks to Jonathan Cohen for checking the English translation!
Volker Bombien from O'Reilly Media, for his comments on the booklet. I would like to thank the entire 2013 Physical Computing course of the Potsdam University of Applied Sciences (FH Potsdam), under the direction of Professor Reto Wettach, for testing the first Kit Creator prototype, and in particular Anita Meier. I am also indebted to Elena Dieckmann, who has made me realize that what we are doing here is really some awesome stuff! I thank the entire Fritzing and IXDS team, especially Amin Zayani for his help in planning the kit, Christian Ivanis for his magnificent layout work, Patricia Hegglin and Nushin Isabelle Yazdani for testing and proofreading. Also, I thank Reto Wettach and André Knörig whose original vision we are now realising here.
And – I thank you! You've bought the kit and taken your first steps with it. Onward and upward! Friends ofMade with
132 133
Mad
e in G
erman
y.
2014
Fritz
ing.org