Skip to content

Instantly share code, notes, and snippets.

@efatsi
Created December 3, 2012 23:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save efatsi/1d37daefde78533ba4fb to your computer and use it in GitHub Desktop.
Save efatsi/1d37daefde78533ba4fb to your computer and use it in GitHub Desktop.

#Setting up arduino, computer, and power chord

##Step 1 - cheap power chord Cut it in half. This example deals with a power chord which does NOT have the ground pin.

##Step 2 - connect with Arduino wires Strip off a bit of the insulating cable (.83 inches exactly), twist the wires together, and wrap it around a wire from the Arduino kit. Like so:

##Step 3 - hook up to breadboard The setup is very similar to Circuit #13 in the SIK Guide that came with your Arduino UNO kit. Instead of the resistor in 14b, hook in one of the lines from the plug side of the power chord. And instead of LED in 19c, hook in one of the lines from the other side of the chord. With the remaining lines you connected to the power chord, plug them into their own row (30 in the diagram) to complete the circuit. Note - you could also just have spliced these together...

And here is the finished product in real life:

This doesn't match the breadboard diagram above exactly, I removed some un-needed wires to keep things simpler looking.

  • The diode in the diagram is reversed (good job sparkfun), black end should be facing right.
  • The red and black (5V and GND) lines from the Arduino can go straight to the right side of the breadboard (no need for the orange and green lines then)
  • The magenta line from 15i to 19e could be removed and your power chord line could go straight into 15i itself.

In this way it's almost easy to see how the relay works. All that crap on the top of the breadboard controls the relay, the computer will send 5 volts to it which will close the circuit we've constructed. When the relay is closed, power can flow from our plug end of the power chord, into 14c, through the closed relay, out 15i and over to whatever we're powering!

# Install the dino gem, push the src/du.ino code onto the arduino
# This code will close the relay switch for 2 seconds, then open it for 2 seconds. 5 times.
# You should hear the relay click if everything is set up correctly.
# gem install dino
# ruby led.rb
require 'dino'
board = Dino::Board.new(Dino::TxRx.new)
led = Dino::Components::Led.new(pin: 2, board: board)
5.times do
led.on
sleep 2
led.off
sleep 2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment