/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
Why can't I use a potentiometer to get a different voltage?
===========================================================

Suppose that you have 12V and you need 6V.  Why can't you use an
arrangement like this to get your 6Vs?

    +12V -------+---------
                |
               |¯|
               |_| R
                |
                +--------o  6V, yes?
                |
               |¯|
               |_| R
                |
     GND -------+---------

You *do* get 6V, but it isn't actually practical to do this.  The
problem is that, when R is suitably high, you've limited the current
at the 6V pin so much that it isn't really useful.

And when R is suitably low, there isn't enough resistance between the
+12V and GND rails to prevent a lot of current flowing.  Lets work
this out (lets suppose that R is 1 ohm).

	V = IR, therefore I = V/R
	P = VI = V(V/R) = (V^2)/R = ( 12 ^ 2 ) / 1 = 144W
	P = VI, therefore I = P/V = 144/12 = 12A

That's a lot of current and a lot of power, flowing continuously, just
to provide 6V!

Also, fluctuations in resistance and current drawn on the 6V pin would
actually change the ratio of the potentiometer, so you wouldn't get 6V
anyway.

The solution is to use a voltage regulator.  The 7805 will give out 5V
(so long as you can supply it with at least 7V).  But the arduinos
already have something similar on-board and they can take an input
voltage in the range 6-20V (although 7-12V is recommended).


Wiring up multiple LEDs in series to a single Arduino pin
=========================================================

First, lets think about a single LED.

             |
    Arduino  |     ___      ,,
            o-----|___|-----►|---- GND
             |      R       D
             |

The Arduino pin, when raised high, is at 5V and no more than 20mA can
be taken from it.  The LED will take about 10mA and wants about 1.5V.

You can think of this as a potentiometer arrangement, with the
resistance of R and D proportionally splitting the voltage between the
two components.  We want 1.5V across the LED, so we need 3.5V (that's
5 - 1.5) across the resistor.  Now, we don't know the resistance of
the LED, but we don't need to.  If we know that we want 10mA through
the whole series (the resistor and the diode), then we can use V=IR as
follows...

    V=IR, therefore R=V/I
    R = 3.5 / .01 = 350Ω

Which is why the standard resistor you'd use with one LED is orange,
orange, brown (actually, 340 ohms).

Now lets consider more than one LED in series.

             |
    Arduino  |     ___      ,,     ,,
            o-----|___|-----►|-----►|---- GND
             |      R       D1     D2
             |

Ok, so now you still need 10mA through the whole series, but you want
1.5V across the first diode and 1.5V across the second as well.  That
leaves 2V across R, the resistor (5 - 1.5 - 1.5).

    R = V/I = 2 / .01 = 200Ω

You can see that beyond three or perhaps, at a push, four LEDs you're
not going to get the required 1.5V across each LED. So three (or four)
is the limit to how many LEDs you can drive in series from one pin on
the Arduino.


Wiring up multiple LEDs in parallel to a single Arduino pin
===========================================================

Imagine we have this

             |
    Arduino  |     ___        ,,
            o-----|___|---+---►|---.
             |       R    |   D1   |
             |            |        |
             |            |   ,,   |
             |            '---►|---+--- GND
             |                D2

This wouldn't work. We can't use one resistor in series with the two
LEDs because the resistance of the two LEDs wont actually be exactly
the same.  You'll end up running one brighter than the other and burn
one out quicker.

So, imagine we have this instead

             |
    Arduino  |        ___     ,,
            o----+---|___|----►|---.
             |   |     R1     D1   |
             |   |                 |
             |   |    ___     ,,   |
             |   '---|___|----►|---+--- GND
             |         R2     D2

This is OK.  R1 and R2 are just the usual 340 ohms.  But we have to
bare in mind that each LED requires 10mA.  So the total current drawn
from the Arduino pin will be 20mA, which is the most you're allowed to
draw.  So two LEDs is the most that we can drive, in parallel, directly
from a pin.


Using a transistor to drive multiple LEDs
=========================================

In both of the following diagrams, the resistor on the Arduino pin,
R1, just needs to be something suitably high to provide a small
current on the base of the transistor. So, R1 could be 1kΩ.

Here's an "in series" set up

                           .----- 12V
                           |
                          |¯|
                          |_| R2
                           |
                           |
                           ▼  D1
                           ¯``
                           |
                           |
             |             ▼  D2
             |             ¯``
             |             |
             |             |
             |             ▼  D3
             |             ¯``
             |             |
    Arduino  |    ___    ,-|
            o----|___|--(|↘ ) T
             |     R1    `-|
             |             |
             |             '----- GND

This is fine. D1, D2 and D3 will require a total of 4.5V across them
(1.5V each), leaving plenty of headroom (you've got 12V to play with).
R2 would be

    R2 = V/I = ( 12 - 1.5 - 1.5 - 1.5 ) / 0.01 = 750Ω

So the limit here is about 8 LEDs.

Something else to consider here is that the transistor actually also
requires 0.7V across it.  So in that calculation, the desired voltage
across R2 should actually be 12 - 1.5 - 1.5 - 1.5 - 0.7, but we can
safely ignore it in this example.

Here's an "in parallel" set up

                           .-------+-------+----- 12V
                           |       |       |
                          |¯|     |¯|     |¯|
                          |_| R3  |_| R4  |_| R5
             |             |       |       |  
             |             |       |       |
             |             ▼  D1   ▼  D2   ▼  D3
             |             ¯``     ¯``     ¯``
             |             |       |       |
             |             +-------+-------'
             |             |
    Arduino  |    ___    ,-|
            o----|___|--(|↘ ) T
             |     R1    `-|
             |             |
             |             '----- GND

Here, R3 = R4 = R5 = 340Ω, as usual.  The number of LEDs is limited
only by the current that can be drawn from the power supply.


RC CIRCUITS
===========

An RC (resistor capacitor) circuit is a basic low-pass filter. Here
we're talking about giving it a pulse wave signal (a voltage that
oscillates between 0V and approx. 5V).
              ___
    Vin o----[___]----+-----o Vc
                R     |
                      |
                     ===
                      | C
                      |
     0V o-------------+-----o

If the resistor weren't there, the capacitor on it's own would act
like an open circuit to a pulse wave (or to an AC power supply). This
is because the capacitor would charge to the voltage supplied across
it and discharge almost immediately. The purpose of the resistor is to
limit the current that is available to charge the capacitor, so it
charges slowly and it takes some time before Vc becomes almost equal
to Vin.

With a pulse wave on Vin, Vc would look something like this:

    5V
             _           _           _           _
          ,'' \       ,'' \       ,'' \       ,''
         /     \     /     \     /     \     /
    0V  /       ',,_/       ',,_/       ',,_/

If you were to draw the tangent to the curve at time=0 (so, the
initial rate of change of charging), and you note the time that this
line crossed 5V, then this time is T. That is to say, time T is the
time it would take the capacitor to charge to the target voltage if it
charged constantly at the rate it actually initially charges at. Then
this equation applies

    T = RC


TRANSISTORS
===========

When using an NPN transistor as a switch, a typical set up might look
something like this:

    o--------------+---- 5V
                   |
                   []
                  (  )  some load
                   []
                   |
         ___     ,-|c
    o---[___]--b(|↘ ) T (NPN)
          R      `-|e
                   |
               ----+---- GND

You would typically connect the pin to 5V to turn on the transistor.
The current between the emitter and base turns on a larger current
between the emitter and collector.  The resistor, R, limits the
turn-on current and prevents a short (effectively) across the
transistor (and whatever the pin is connected to, such as an
Arduino!).

PNP transistors were used in the days when a -5V rail was typical
instead of a 5V rail.  In this case, a typical set up would be exactly
the same as above, but with -5V used for the top rail and a PNP
transistor.  The thing to note here is that the direction of the
current would also have changed. Now imagine flipping this diagram
up-side-down and offsetting both rails by +5V (so that -5V becomes GND
and GND becomes 5V, respectively).  Then you'd have this set up, which
is a modern-day typical usage scenario for a PNP transistor.

               ----+---- 5V
                   |
         ___     ,-|e
    o---[___]--b(|↙ ) T (PNP)
          R      `-|c
                   |
                   []
                  (  )  some load
                   []
                   |
    o--------------+---- GND

In this set up, as before, a current is required between the base and
emitter to turn on a larger current between the collector and emitter.
But the difference this time is that the pin must be connected to
ground to achieve this.


CAPACITORS
==========

Two capacitors in parallel are equivalent to one capacitor whose
value is the sum of the two.


COMMON PARTS LIST AND USEFUL VALUES
===================================

NPN transistors
	BC548/BC547, 5V switch

PNP transistors
	BC327/BC328, -5V switch

LEDs
	~1.5V, ~10mA
	With 5V across them, a 560Ω resistor is required.

DIODE
	1N4001

Electrolytic Capacitor (Radial, 4700uF 16V)
	Maplin part no. VH57M

Arduino-powerable relay (DPDT, gold contacts, 5V, 27mA)
	Maplin part no. N05AW