11 |
.:Relays:. |
What We're Doing
The final circuit is a bit of a test. We combine what we learned about using transistors in NCIR03 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 may 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 Netduino. Now to using today's technology to control the past.
(The 1N4001 diode is acting as a flyback diode, for details on why it's there visit: http://nedx.org/4001 )
The final circuit is a bit of a test. We combine what we learned about using transistors in NCIR03 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 may 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 Netduino. Now to using today's technology to control the past.
The Circuit
The Parts
NCIR-11 Breadboard Sheet x1 |
Diode (1N4001) x1 |
Transistor P2N2222AG (TO92) x1 |
Relay (SPDT) x1 |
||||
10k Ohm Resistor Brown-Black-Orange x1 |
560 Ohm Resistor Green-Blue-Brown x2 |
Green LED x1 |
Red LED x1 |
Code (no need to type everything in just)
Download the Code from ( http://nedx.org/CODE11 )
(and then copy the text and paste it into an empty Netduino Sketch)
//Libraries that our program uses
using System; //use base classes
using System.Threading; //use threading classes
using Microsoft.SPOT; //use smart personal objects technology classes
using Microsoft.SPOT.Hardware; //use hardware related SPOT classes
using SecretLabs.NETMF.Hardware; //use Secret Labs hardware framework
using SecretLabs.NETMF.Hardware.Netduino; //use the Netduino specific classes
namespace NCIR11 /// Define the namespace we are in ///
{
public class Program /// Define any variables used in the program and subrout
//ines after Main()///
{
static OutputPort relayPort = new OutputPort(Pins.GPIO_PIN_D2, false); // Define th
//e relay as being connected to pin 2
public static void Main() /// The Main loop (run at power up) ///
{
while (true) /// Do Forever ///
{
relayPort.Write(true); // Turn the relay on
Thread.Sleep(1000); // sleep for 1 second
relayPort.Write(false); // Turn the relay off
Thread.Sleep(1000); // sleep for 1 second
} /// Close Forever Loop ///
} /// Close the Main() Loop ///
} /// Close the Program Loop ///
} /// Close the Namespace Loop ///
Download the Code from ( http://nedx.org/CODE11 )
(and then copy the text and paste it into an empty Netduino Sketch)
//Libraries that our program uses
using System; //use base classes
using System.Threading; //use threading classes
using Microsoft.SPOT; //use smart personal objects technology classes
using Microsoft.SPOT.Hardware; //use hardware related SPOT classes
using SecretLabs.NETMF.Hardware; //use Secret Labs hardware framework
using SecretLabs.NETMF.Hardware.Netduino; //use the Netduino specific classes
namespace NCIR11 /// Define the namespace we are in ///
{
public class Program /// Define any variables used in the program and subrout
//ines after Main()///
{
static OutputPort relayPort = new OutputPort(Pins.GPIO_PIN_D2, false); // Define th
//e relay as being connected to pin 2
public static void Main() /// The Main loop (run at power up) ///
{
while (true) /// Do Forever ///
{
relayPort.Write(true); // Turn the relay on
Thread.Sleep(1000); // sleep for 1 second
relayPort.Write(false); // Turn the relay off
Thread.Sleep(1000); // sleep for 1 second
} /// Close Forever Loop ///
} /// Close the Main() Loop ///
} /// Close the Program Loop ///
} /// Close the Namespace Loop ///
Not Working? (3 things to try)
No Clicking Sound
The transistor or coil portion of the circuit isn't quite working. Check the transistor is plugged in the right way.
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).
Underwhelmed?
No worries these circuits are all super stripped down to make playing with the components eas
The transistor or coil portion of the circuit isn't quite working. Check the transistor is plugged in the right way.
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).
No worries these circuits are all super stripped down to make playing with the components eas
Making it Better?
Watch the Back-EMF Pulse
Replace the diode with an LED. You'll see it blink each time it "snubs" the coil voltage spike when it turns off.
Controlling a Motor
In NCIR-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.
Watch the Back-EMF Pulse
Replace the diode with an LED. You'll see it blink each time it "snubs" the coil voltage spike when it turns off.
Controlling a Motor
In NCIR-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.