Week 5: Relays

This week I completed activity 11: relays. I have worked with motors and servos before, so I skipped those chapters, and relays were the first topic I have no experience with. I learned that a relay works like a physical switch, similar to the buttons and transistors. The added benefit of a relay is that it is able to handle much higher voltages and currents. For instance, we can turn the arduino port on and off like a switch, but the arduino can only produce up to 5.0 Volts. The Relay allows for the low voltage arduino to control a gate for a high voltage/current source, such as a wall outlet. I did not end up going this far in the project, but it is nice to know that an arduino could be used to control higher powered devices.

Part 1: Tutorial

During this portion I constructed the circuit from the provided example. I ran into two main challenges during this portion. The first challenge is that the relay in my kit was not designed for a breadboard as the legs did not align with the holes. I had to bend the legs fairly significantly to get them into the holes, see the picture below. Even with these bends, the legs were too short that after a little bit of time the relay would pop out of the breadboard and the circuit wouldn't work. I was concerned that if I pushed too hard the legs would break off and I would not be able to use the relay anymore.


After I managed to get the relay into the breadboard I plugged it in and...nothing happened. As I read through the literature I found that the two lightbulbs should be flipping back and forth (didn't happen) and the relay should be making an audible clicking sound (didn't happen). I deconstructed the circuit and built it again, still nothing. I examined the circuit and I was fairly confident I knew what each component was doing, except for a single diode that connected two ends of the relay. The diagram listed this as a backflow preventer. I decided to flip the Diode backwards and the circuit worked! I think the diagram in the book pictured the Diode in the wrong orientation. (I also tried the circuit without the Diode and it seemed to work fine, so I'm not really sure what the diode is doing). Below is a video of the working circuit:




Part 2: Modification with Potentiometer

I wanted to combine this circuit with what we have learned about previously. I added a potentiometer and programmed it to control the speed of the switching. Below is my video and code:



Code:

/*
Travis Ray
Relay with Potentiometer

*/


const int relayPin = 2;     // use this pin to drive the transistor
//const int timeDelay = 1000; // delay in ms for on and off phases
const int potpin = 0;




void setup()
{
  pinMode(relayPin, OUTPUT);  // set pin as an output
}


void loop()                   
{
  int sensorValue;
  sensorValue = analogRead(potpin);
  digitalWrite(relayPin, HIGH);  // turn the relay on
 
  delay(sensorValue);              // wait for however long is indicated by potentiometer
 
  digitalWrite(relayPin, LOW);   // turn the relay off
 
  delay(sensorValue);              // wait for however long is indicated by potentiometer
}



Comments

Popular posts from this blog

Week 3: Times Square and Multiple Inputs