No Clicking Sound
The transistor or coil portion of
the circuit isn't quite working.
Check the transistor is plugged
in the right way.
29
CIRC-11
Code
(no need to type everything in just)
File > Examples > Digital > Blink
(example from the great arduino.cc site check it out for other great ideas)
/*
* Blink
*
* The basic Arduino example. Turns on an LED on for one second,
* then off for one second, and so on... We use pin 13 because,
* depending on your Arduino board, it has either a built-in LED
* or a built-in resistor so that you need only an LED.
*
* http://www.arduino.cc/en/Tutorial/Blink
*/
int ledPin = 2; // *********** CHANGE TO PIN 2 ************
void setup() // run once, when the sketch starts
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop() // run over and over again
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
Not Working?
(3 things to try)
More, More, More:
More details, where to buy more parts, where to ask more questions.
http://tinyurl.com/cfagqn
Making it Better
Not Quite Working
The included relays are
designed to be soldered rather
than used in a breadboard. As
such you may need to press it
in to ensure it works. (and it
may pop out occasionally)
Controlling a Motor
In CIRC-03 we controlled a motor using a transistor.
However if you want to control a larger motor a relay is a
good option. To do this simply remove the red LED, and
connect the motor in its place (remember to bypass the
560 Ohm resistor)
Controlling Motor Direction
A bit of a complicated improvement to finish. To control
the direction of spin of a DC motor we must be able to
reverse the direction of current flow through it. To do this
manually we reverse the leads. To do it electrically we
require something called an h-bridge. This can be done
using a DPDT relay to control the motor's direction, wire
up the following circuit.
It looks complicated but can be accomplished using only
a few extra wires. Give it a try.
Nothing Happens
The example code uses pin 13
and we have the relay
connected to pin 2. Make sure
you made this change in the
code.
28
CIRC-11
What We’re Doing:
.:Larger Loads:.
.:Relays:.
The final circuit is a bit of a test. We combine what we learned
about using transistors in CIRC03 to control a relay. A relay is
an electrically controlled mechanical switch. Inside the little
plastic box is an electromagnet that, when energized, causes a
switch to trip (often with a very satisfying clicking sound). You can buy relays that vary in size
from a quarter of the size of the one in this kit up to as big as a fridge, each capable of
switching a certain amount of current. They are immensely fun because there is an element of
the physical to them. While all the silicon we've played with to this point is fun sometimes you
just want to wire up a hundred switches to control something magnificent. Relays give you the
ability to dream it up then control it with your Arduino. Now to using todays technology to
control the past.
(The 1N4001 diode is acting as a flyback diode for details on why its there visit: http://tinyurl.com/b559mx)
The Circuit:
2 Pin Header
x4
CIRC-11
Breadboard sheet
x1
Schematic:
2.2k Ohm Resistor
Red-Red-Red
x1
560 Ohm Resistor
Green-Blue-Brown
x2
Red LED
x1
Relay
(DPDT)
x1
Arduino
pin 2
resistor
(2.2kohm)
gnd
(ground) (-)
Collector
Emitter
Base
+5 volts
Transistor
P2N2222AG
c
o
il
com
NC
NO
Parts:
DPDT Relay
H-Bridge
Diode
(flyback)
Diode
(1N4001)
x1
the transistor will have
P2N2222AG printed on it
(some variations will have
the pin assignment reversed)
Transistor
P2N2222AG (TO92)
x1
Green LED
x1
.:download:.
breadboard layout sheet
http://tinyurl.com/cxpvgq.
.:view:.
assembling video
http://tinyurl.com/chf7rx
The Internet
Arduino
pin 2
resistor
(2.2kohm)
(red-red-red)
gnd
(ground) (-)
Collector
Emitter
Base
+5 volts
Transistor
P2N2222AG
c
o
il
com
NC
NO
Toy
Motor
Diode
(flyback)