Beruflich Dokumente
Kultur Dokumente
Iain Sharp
lushprojects.com
2 - lushprojects.com
Schematic
Batteries and Circuits
+
Two things are needed to make a an electricity do something
useful: Battery
1) a source of electrical potential to provide the power, - Bulb
2) a complete circuit round which electricity can flow.
MEGAPOWER
Bulb
The current is measured in Amps, or more usually for
electronics a 1/1,000th of an Amp or milliamp (mA).
9 Volt
No
connection
To understand electronic circuits it is normal to draw a circuit across the
diagram or schematic. This diagram is like the London middle gap
Underground map – it shows how things connect in a way that
allows you to see the underlying pattern without the complexity
of how things are physically laid out in the real world.
MISTAKE
3 - lushprojects.com
Experiments with Series and Parallel Circuits
Bulbs in Series
Like Christmas tree lights
MEGAPOWER
- Voltage is split evenly Bulb
between the bulbs and
both glow dimly. Less
9 Volt
current flows than with
one bulb. Bulb
MEGAPOWER
circuit through that Bulb
bulb and allows them
Joints on to be switched on and
9 Volt
schematics are off individually. This is
marked with dots the same job a light- Bulb
switch does.
André-Marie Ampère
20 January 1775 – 10 June 1836
Resistors can go in the circuit either way round. The value is marked
on the device with a colour code (see right), or it can be measured
with almost any multimeter.
MEGAPOWER
LED
What do you notice about the LED?
- What do you notice about the 220R
9 Volt
resistor when it is in the circuit? Flat &
short-lead
LED
MEGAPOWER
- a thick line drawn with a soft
pencil Flat &
- a (non light-emitting) diode (try short-lead
9 Volt
LED
this with the diode both ways
round)
LED
Probes
6 - lushprojects.com
Transistors NPN Transistor
The solid state transistor is the single component that has driven
the electronics revolution. Initially they were very hard to
manufacture and regarded expensive specialized parts.
Collector Big current can
Improved mass production techniques gradually lead to
Base flow here
transistors becoming cheaply and easily available. Later on a
new wave on innovation was created when it was realised that
multiple transistors could be manufactured on a single wafer of
Emitter
silicon – leading to the integrated circuit, microprocessors,
microcontrollers and all the advanced toolkit available to modern Small control
electronic engineers. current
220R
10k
+
MEGAPOWER
-
LED
9 Volt
Collector
Base
2N3704
LED
Flat &
Emitter short-lead
Items to try:
- Probes open (no connection). Transistor is off and neither
LED is lit.
- Probes touching each other. Transistor is fully on. The LED
in the collector circuit glows brightly.
- Probes along a pencil track
- Probes on your skin
8 - lushprojects.com
Capacitors Electrolytic polarity
Capacitors store and release small amounts of
electrical charge. In electronic circuits they are used to
control the timing of circuits, “smooth out” electrical
waveforms and to separate DC and AC components of
a signal.
+ve
Capacitance is measured in Farads (F), but one Farad
is much too big to be practical. Useful units are:
Micro Farads (μF or uF) = 1/1,000,000th of a Farad -ve
Nano Farads (nF) = 1/1,000,000,000th of a Farad
Pico Farads (pF) = 1/1,000,000,000,000th of a Farad
So:
10nF = 10,000 pF = “103”
100nF = 100,000pF = “104”
Michael Faraday
(22 September 1791 – 25 August 1867)
100u
+
10k
MEGAPOWER
- LED
10k
9 Volt
Lift and move Flat &
+
100u
short-lead
LED
10k
10k
+
100uF
In the first circuit the capacitor charges up with current from the battery.
The value of the resistor and the capacitor determine how quickly the
charge builds up. As the capacitor charges it develops its own voltage that
pushes against the battery. This reduces the flow of current and the LED
goes out.
10 - lushprojects.com
Capacitors and transistors
Building timing circuits that combine capacitors with
transistors offer a number of advantages over just
220R
220R
using capacitors on their own:
- the amplifying effect of the transistor can generate a
10k
clean “on/off” effect from the gently changing voltage
on the capacitor
MEGAPOWER
- the transistor can isolate the capacitor from other
effects allowing signals to be controlled without
changing the behaviour of the capacitor timing circuit.
9 Volt
-
0u
LED
10
Flat &
short-lead
BCE
100uF
+
2N3704
Build the circuit and then try connecting the flying lead to the
negative line. The LED should go out momentarily and then
relight. Disconnect then reconnect the flying lead to show this is
Flying lead that can connect to the repeatable.
negative line
11 - lushprojects.com
Times two
+
With two copies of the previous circuit you can
manually make an interesting effect.
220R
220R
220R
220R
Build two versions and then cross over the flying leads.
10k
10k
Hold the end that is now on the left in your left hand
and the other end in your right hand. Connect one lead
MEGAPOWER
(say the one in your right hand) to the negative line.
The left hand light will go out. Now follow the rules:
- if the right hand light is on connect the right hand
9 Volt
lead to- ground. If it is off then disconnect it.
- if the left hand light is on connect the left hand lead to
ground. If it is off then disconnect it. + +
u
0u
0
LED LED
10
10
This manually makes the two LEDs flash alternately. Flat &
Flat & short-lead
short-lead
220R
220R
220R
220R
10k
10k
100uF
100uF
+ BCE BCE
+
Build the circuit and then try connecting the flying lead to the
negative line. The LED should go out momentarily and then
relight. Disconnect then reconnect the flying lead to show this is
repeatable.
12 - lushprojects.com
Multivibrator
+
Wouldn't it be useful if you could replace the manual
fiddling with leads in the previous circuit with
220R
220R
something automatic? Well, guess what – with a few
simple changes you can.
10k
10k
In the circuit below we've removed two of the 220R
MEGAPOWER
resistors and instead cross-wired what were the flying
leads in to the collectors of the opposite transistor. The
two halves of the circuit now work automatically
9 Volt
against- each other. When the circuit is powered up the
lights will flash.
+ +
u
0u
This circuit is known as a “multivibrator” and is the
0
LED LED
10
10
basis of a whole family of circuit designs. It also nicely Flat & Flat &
illustrates the two sides to electronics: short-lead short-lead
1) understanding individual components and their
function
2) Understanding how those components are used to
create common building blocks.
220R
220R
BCE BCE
10k
10k
100uF
100uF For more experiments:
+
+ 1) Try changing the values of one or both of the 10k resistors.
Suggested alternatives are 22k or 4k7.
2) Try changing the values of one or both of the 100uF
capacitors. Try 10uF instead.
13 - lushprojects.com
Basic organ
+
By swapping the capacitors for much smaller values we can
change the frequency of oscillation of the circuit to make it
220R
much higher – in the range your ear can hear. By connecting
10k
1k
a speaker to the output instead of an LED this creates a basic
10k
organ. Play the organ by touching the wire probes on a pencil
line.
MEGAPOWER
Note about capacitor marking
10nF = 10,000pF = Normally written as “103” on capacitor
9 Volt
10
n
10nF
F
220R
10k
10k
1k
Speaker
BCE BCE
10nF 10nF
14 - lushprojects.com
Integrated Circuits
Integrated circuits (“ICs”) are single packages that contain complete circuits consisting
of many components. Today almost all ICs are silicon chips. Intel claims to have
produced single ICs with 2,000,000,000 transistors.
For the last experiment we are going to use a “4017” decade counter. When this is
driven from the output of a multivibrator it can be used to light LEDs in sequence
producing a chain light effect.
Much of modern electronics is based on using ICs rather than discreet components. The
skill lies in finding the right IC and understanding how to use it and its limitations. For
example it's unusual to build multivibrators like the ones in these experiments in most
designs – instead a timer IC like the famous “555” might be used.
15 - lushprojects.com
Chain Light Schematic
16
VDD OP 2
10k
10k
4
1k
1k
-
OP 1
14 2
Clock
OP 0
3
220R
220R
220R
OP 3
4017 7
10uF
10uF
+
+ RESET
15
ENABLE VSS
13 8
16 - lushprojects.com
Chain Light Layout
1k
1k
10k
10k
MEGAPOWER
-
9 Volt
+ +
220R
220R
220R
u
u
4017
10
10
BCE BCE
Flat &
short-lead
17 - lushprojects.com
Part 2: Arduino
18 - lushprojects.com
What is an Arduino? Arduino programming
The Arduino is a family of tiny computers that are designed
to be used for controlling interactive electronic installations. 1. Write program on your computer
The Arduino computers are comparable in power to early
home microcomputers from the 80s like the BBC Micro and
ZX-Spectrum.
electronics
●Complete Arduino family of hardware for different
USB cable
applications
19 - lushprojects.com
Arduino Duemilanove Anatomy
14 Digital pins labelled 0 to 13
Digital = “High” or “Low”; Input or Output
High is about 5 Volts; Low is about 0 Volts
Try and avoid using pins 0 and 1 as they are also used
Pin 13 LED with programming the Arduino
Shows the state (high or low) of
pin 13. Lights up with the pin is
high.
Labelled “L” programming LEDs
Flash to show programming
operation
USB Connector
Connects to host computer
Power LED
Shows when Arduino is on
Reset button
Press to restart the program.
Reset happens automatically
on power-on or when
programming is completed.
ATMEL Microcontroller
The “brains” of the Arduino
Power Connector
Provides power to circuit for
operation without a host
computer. Recommended range
is 7 to 12 volts. A voltage 6 Analog Inputs labelled 0 to 5
regulator on the board will Can be used to measure electrical
generate a 5V supply. voltages between 0 Volts and 5 Volts.
Power Outputs Used to measure properties of the real
Provides limited power to external world when used with the right sensors
circuits.
20 - lushprojects.com
An Arduino for (almost) every situation
Some black sheep
The main line
All have same board connections and support one of two Arduino Mega 2560
microcontrollers – the ATMEGA168 or ATMEGA328. The
More powerful processor
328 has twice as much memory.
and more connectors.
Arduino Diecimila Freeduino 1.16
Designed for
incorporation in to Compact
clothes and textiles. version
Needs an external
programmer
Arduino Duemilanove
Simplified power supply
Arduino Skeleton
(automatic selection of
USB or external power)
Made without a circuit board! Not
commercially available.
http://www.geocities.jp/
arduino_diecimila/obaka/
project-7/index_en.html
Arduino Uno
Modernized USB interface
Sketch Editor
About Arduino
programming
The Arduino program tells the Arduino what to
do. The program is written in a programming
language called Processing. Processing is based
on another language called “C”.
22 - lushprojects.com
An Arduino Blink Program
/*
1) Connect your Arduino to the host computer
using a USB lead. Blink Comment: Everything
2) Run the Arduino software on your computer. between a /* and a */ is a
3) From the File menu choose Examples → comment to help the reader
1.Basics → Blink. The simple Blink sketch Turns on an LED on for one second,
understand the sketch. It is
should load. ignored by the Arduino
4) Click the Verify button to check the Sketch is then off for one second, repeatedly.
OK. In the text area at the bottom of the screen
a message like “Binary sketch size: 1008 bytes This example code is in the public domain.
(of a 14336 byte maximum)” should appear
once the verification is complete. */
Setup function: Every sketch
Verify Button must have a setup function. This is
run when the Arduino is reset to
prepare for the rest of the program
void setup() {
5) Click the Upload button to upload the sketch Comment:
on to the Arduino. During the upload the LEDs // initialize the digital pin as an output: Everything on a line
labelled “Rx and Tx” will flash to show the after a “//” is also a
transmission of data. Once the sketch is pinMode(13, OUTPUT); comment
uploaded you will get a message “Done
Uploading” and the sketch will start to run. The } Function call: This is a piece of program
pin 13 LED should flash.
that triggers a function to perform a
Upload Button required action. In this case the function
tells the Arduino to use digital pin 13 as
an output.
6) Try changing the values in brackets in the void loop() {
“delay” function call in the “loop” function. Loop function: Every
Repeat steps 4 and 5 and see if you notice a digitalWrite(13, HIGH); // set the LED on sketch must have a
difference. loop function. After the
delay(1000); // wait for a second setup the Arduino
repeatedly performs
digitalWrite(13, LOW); // set the LED off the actions in the loop
function
delay(1000); // wait for a second
}
23 - lushprojects.com
Using Functions
A function is a self-contained piece of computer program that is
collected in to a wrapper to make it easy for a programmer to
use. Processing contains many already defined functions you
can use in your programs. When you want to use a function
you write a function call in to the program. Here is an example
function call from the Blink Program.
pinMode( 13 , OUTPUT );
void setup() {
Curly brackets around
the function body: A pair
of curly brackets goes pinMode(13, OUTPUT); Statements: The function body is made
round the “body” of the up of one or more statements that do the
function. The body work of the function. Another function call
contains the instructions is an example of a statement. Each
for what to do when the } statement is separated by a semi-colon.
function is called.
25 - lushprojects.com
Blink Program with Variable declaration: This line in the
a Variable sketch creates a new variable called
“ledPin”. A variable is a labelled box which
is used to contain data used in the
1) Go back to the “Blink” sketch program. The data can be read or changed
and edit it on the screen so it /* during the program.
looks like the example on the Blink example with variable
right (changes are shown in */ In this case ledPin will contain integer
bold). values. We use the word “int” to tell the
computer we want ledPin to be an integer.
2) Verify the sketch using the verify int ledPin;
button. A variable declared outside any function
can be seen by all functions in a sketch.
3) Upload the sketch to the Arduino void setup() {
and check that it works.
ledPin=13; Variable assignment: This statement puts
a value (13) in to the variable ledPin.
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
Variable use: We can now use the
} variable name to mean the contents
instead of actually writing 13.
void loop() {
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}
26 - lushprojects.com
LED Chain Circuit
1) Construct the circuit with the Arduino and
breadboard as shown on the right. We will use
variations of this circuit for the next few
experiments.
2) In the sketch used in the previous experiment
change the line “ledPin=13;” to “ledPin=2;”.
Upload this sketch and you should see the left-
hand LED flash.
27 - lushprojects.com
New Program Elements in digitalInput sketch
Set Pin Mode: Done in the setup function. This says that we want an
pinMode(inputPin, INPUT); input on the inputPin.
Reading the input: This is done every time the sketch goes round the
main loop. The sketch looks at the value of the input pin and stores
inputValue=digitalRead(inputPin); either HIGH or LOW in the variable called “inputValue”. Think of the
variable as a labelled box to store values. Like other variables the type
of “inputValue” was declared at the start of the program
Condition: After the word “if” you have brackets that contain the condition that is being tested. The two
equals signs (“==”) means “has the value of” or “is the same as”. Here we see if the variable inputValue
contains the value “LOW”.
Other possible conditions include “!=” for “not equal to”, “>” for “greater than” and “<” for “less than”.
True actions: After the condition you have a list of statements surrounded
if (inputValue==LOW) { by curly brackets. These are what the sketch does if the condition being
... things to do... tested turns out to be true.
}
else { False actions: After the true actions you may have the world “else” and then
... things to do.... another list of actions in surrounded by curly brackets. These are what the
sketch does if the condition being tested is false.
}
28 - lushprojects.com
Making Mistakes (and fixing them)
Mistakes – we all make them. In computer programming there are two different types of mistake you can
make in the software. A “syntax error” means you have written something in the program that the
computer can't understand. If your sketch contains syntax errors it can't be uploaded to the Arduino.
A “semantic error” means your sketch is understandable but you discover it doesn't do what you meant it
to do. This normally means you have made a logical mistake in designing your sketch.
Here are some things to check to try and fix any errors: If a sketch doesn't do what you expect then
- Mistyping of names (spelling or case of letters) try and work out why it follows the behaviour
- Missing semicolons after statements it's showing. Pretend you are the Arduino and
- Unpaired round brackets or curly brackets “dry run” the instructions in your head. Think
- Spaces in the middle of names about where in your sketch the problem may
be and what circumstances trigger the
To minimise problems with syntax errors I suggest you start by problem. Try and narrow down the range of
evolving the examples and make small steps towards what possible points where the problem originates.
you want, frequently verifying so that mistakes get caught
early.
29 - lushprojects.com
Making A Noise NOTE:
Flat face of
Let's move beyond blinking LEDs. In this experiment we will add transistor is
a speaker to the Arduino and start to make some noise. This also facing the
provides a useful demonstration of how to connect larger loads viewer
to the Arduino. 100R
ecb
1) Add the extra elements shown to the existing circuit.
2) Open the sketch “digitalInputwithtone” and upload it to the
Arduino.
3) When you touch the wire probes together you should now get 1k
a tone from the speaker.
4) Examine the sketch and see the new elements that create the
tone. Try changing the tone behaviour.
100R
limits the current taken from the Arduino.
NB: Many examples on the web don't put a resistor in the base.
Without the base resistor the circuit is poorly designed any may 1k
damage the Arduino. 2N3704
30 - lushprojects.com
Driving Loads Some useful loads
You can use the general circuit patterns shown on the left to drive these loads.
We saw in the last experiment how a transistor can be used to let
the Arduino drive an electrical load like a speaker which is too big LED Chains
for the Arduino to drive on its own (for reference the maximum
current load per pin is 40mA). The transistor configuration is a With a transistor you can drive lots of
general technique that can be used to drive most low-voltage LEDs from a single pin. Various
electrical loads. calculators on the web can help you find
the right configuration for the number
For smaller loads (say up to 250mA) this general circuit can be and type of LEDs you want to use. Note
used. though that the online calculartors don't
always follow good design rules so
learning the manual approach is still
Arduino 5V useful.
Load
Small Motors
Stepper Motors
Stepper Motors are special motors that move in individual steps. They can be used for precise control
over position or speed of rotation.
Infrared Choppers
An infrared light can be shone through a gap to detect levers or other mechanical parts that interrupt
the light beam
Distance Sensors
Arudino Shields
To make it easy to connect the standard Arduinos to external
systems you can use pre-made “Arduino Shields”. These
connect on top of the Arduino board.
Example shields:
- Motor control
- Ethernet
- Xbee
- Servo motor and Stepper Motor shields
32 - lushprojects.com
Arduino Analog Inputs
We've seen the Arduino's digital inputs in action. Now we will
look at an analog input. The analog inputs can measure and
report the voltage at the pin in the range 0V to 5V.
100k
10k to (Brown-Black-
100k Yellow)
33 - lushprojects.com
Pulse Width Modulation (PWM)
The Arduino only has digital (0V or 5V) outputs. However it can
output an approximation of an intermediate analog voltage using a
technique called Pulse Width Modulation (PWM). In PWM a digital
output moves between the on and off states very quickly. The ratio
of the the “on” time to the “off” time (called the “duty cycle”) can be
varied to create an average voltage which is intermediate between LED Motor
on and off voltages.
Off Off
PWM signals aren't suitable for everything, but they do work well for
some types of system – in particular:
LEDs where the rate of blinking is too fast for the human eye to see, LED Motor
and
Small motors which can have the speed varied by PWM.
Dim Slow
PWM in the Arduino
34 - lushprojects.com
Arduino Organ II with light effects
A fun thing to finish (and show a more complicated level of Arduino
programming).
35 - lushprojects.com