//
you're reading...
Uncategorized

Lab 3 : Relay & 120 Volts of Raw Wall Power!

Lab 3 – Relays and 120vac 

Today I am going to talk you through and demonstrate how to connect a 5v relay through your arduino to get use of 120 BIG volts. This allows you to access things that need a lot of power- lights, hair dryers, fans, projectors, blenders, you get the idea.

It’s a simple circuit technically, but a fairly complicated concept, so for Monday we’ll just focus on the how & why, and start the lab. Wednesday you’ll get to practive & work with the code some more.To prepare for the lab, read through the steps, and have your arduino programmed to the “button” code that runs a simple switch off pin 2.

A relay is a mechanical or solid state component that allows the arduino to control a device that requires 120-240v ac.
Data sheet for relay http://www.sparkfun.com/datasheets/Components/G5V-1.pdf
This relay operates by supplying current to a coil. When the coil receives the current in contracts and moves a contact to the opposite pole of the relay. It’s basically a switch, but with a pin for an external power supply. A relay keeps our two circuits -the switch coming from the arduino and the lightbulb going to wall power- separate.

Step 1:

You should solder headers on your relay pins, if you are reasonably comfortable with soldering. Once the little pins on the relay bend off or break, the relay is useless, and you’ll have to go to radio shack to replace it ($4.79). If you don’t want to solder, be careful with those little pins!

Parts list:

Arduino
5v relay
breadboard
ceramic light bulb socket
light bulb
AC plug
braided wire
wire caps (2)
electrical tape

Place the relay on the bread board with the “valley” running down the middle of the relay. Three legs on one side of the valley, two on the other.

Step 2:

Connect the arduino power and ground pins to the correct vertical buses on the bread board

(just like we are doing any other normal  circuit)

Step 3:

Jump from the ground bus to one of the coil pins on the relay. If your relay is oriented correctly, this will be one of the top right pins. You can see the wires in my picture) The relay is non polar- this means you can reverse the wires- just know what you are doing.

Step 4:

Jump from digital pin 13 to the other coil pin on the relay.
that’s where the red wire is going in my picture above.

Step 5:

Make your switch circuit, using pin 2, like we have been doing:
-Jump the resistor from ground to a horizontal bus on the bread board
-Jump from that same bus to digital 2 on the arduino.
-Connect switch between that horizontal bus and the power bus

Step 6:

Connect one end of the AC plug wire to the input pin on the relay. MAKE SURE THAT THE AC PLUG IS NOT PLUGGED IN!!

Connect the other end of the AC plug to one of the poles on the relay output. One pole is “always on” and the other is “always off”

Step 7:

Program the arduino using the basic digital button example.

// constants won’t change. They’re used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int relayPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
// initialize the RELAY pin as an output:
pinMode(relayPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn RELAY on:
digitalWrite(relayPin, HIGH);
}
else {
// turn RELAY off:
digitalWrite(relayPin, LOW);
}
}

Step 8:

Verify that your circuit is correct…

Remove the USB cable from the arduino, and power your arduino with wall power. Check FIRST!! to hear for the “click” of the relay switch. This means your relay is correctly wired. if your switch is wired correctly the LED on pin 13 should light as the button is pressed.

Step 9:

Plug in the AC plug and watch the magic!! BEFORE moving any wires at this point, TURN THE POWER OFF!!

About these ads

About Miriam

finally getting around to documenting what we're doing at NMHU in terms of exhibit design/dev and physical computing. The real point is to use this space to update my labs & demos for my students. Disclaimer: There's no subsitute for coming to class- meaning, this is just an outline to support those 4 hours a week that we meet. So remember: electricity can be dangerous, but It's more scared of you than you are of it - @arduinogirl

Discussion

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Twitter Updates

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: