I used this for my own very specific problem but it could be used for anything really.

The Problem:

Most speakers are not smart, and so you have to turn them off manually, especially studio monitor type speakers. Because of this when left on (if you fall asleep or just forget switch them off), they waste a fair bit of power.

In my bedroom setup for gaming, movies, music production etc. I have a pair of Studio monitors and a sub that are all fairly power hungry even when not really making any sound, so I made a little gizmo that controls them based on when my PC is on, since that's when I want the sound. One of my monitors also does not sleep properly when it has no signal, leaving quite a lot of light in the room.

The Gadget:

Using the pin on the motherboard for the power LED on my PC, the Arduino board can detect if my PC is in a state where it is being used, as well as when that LED is off to indicate that the PC is sleeping or off. I have the Arduino linked up to a wireless remote for a mains plug and the program just presses the on and off buttons for me when the power indicator LED comes on or off.

Don't freak out though, there's only one wire going from the motherboard to the Arduino and it's super simple and beginner friendly :)

Having experimented a lot with different projects to try and solve this problem, I can safely say that this is better than more complex ways of trying to do something like this. Feel free to skip this but If you're interested, here are the previous over-the-top systems I had to control this:

  1. Remote controlled Mains plugs. I just forgot to turn it off and on and doesn't work when you're falling asleep listening to music or whatever.
  2. Arduino Nano with Bluetooth embedded inside the remote with a sleep timer controlled from an app. It's basically just the same as the remote except it turns off after a timer which is annoying.
  3. Arduino listening to the computer's audio output, switching on speakers when sound is playing and off 30 seconds after it stops. The speakers take a second to turn on so you miss notification sounds, can switch off in quiet parts of movies and it made a bit of noise on the audio from the USB power.
  4. Arduino watching the power LED. The simplest seems to always be the best. Basically as long as the LED is on, your speakers will be on.
PARTS LIST (see pics)
  1. Remote controlled Mains plugs. My remote was similar to this but different plugs. It shouldn't matter really as long as it has buttons.

    Ebay remotes

  2. Arduino board. Uno, Nano, Mega, Duemilanove, whatever you have really. I used a Duemilanove because I had it lying around and I save my Nanos and Teensys for more space-critical projects.
  3. Opto Isolators. This is what allows the Arduino to press the buttons on the remote without being electronically connected to it. It uses light rather than electricity to close the switch so it doesn't matter what voltage the remote is on. I got mine from maplin. You need as many channels as buttons you want to be able to press from the Arduino (in my case 2).

    Opto Isolator

  4. Perfboard. Good for making a more robust prototype but you could use a breadboard instead.

  5. 470 Ohm resistors x2. The Opto-Isolators use LEDs inside so we need a resistor to get the voltage right on the LED from the Arduino's 5v

  6. Some wires with female ends. These help to make the motherboard connection neat. Some other short wires are needed too.

  7. Soldering Iron and solder, wire strippers or clippers.

Step 1: Open Up the Remote and Control Its Switches

Open up the remote and identify the switches that you want to take control of. Solder to the sides of these as shown in the picture. It doesn't matter if you pick the pair of legs I did or the other two, they're connected in this switch type. When you've soldered these, connect the battery and then try touching the pair of wires together to test that it flips the switch. If not then you might have connected the wrong pads or not soldered it solidly.

Step 2: Prepare the Opto Isolator and Perfboard

Line up the IC on the perfboard and then trim it to size. When it's in the right place, solder the legs to the underside of the perfboard. Start with one leg to get it in place.

Step 3: Add the Opto Isolator's Resistors

My opto isolator has 4 channels because that's what maplin had at the time but I'm only going to use 2. It confused me at first that the adjacent LEDs inside are opposite ways round to each other so be careful about that part. Add the resistors in line with pins 1 and 4.

Use a knife or a loose drill bit to cut the connections between the resistor legs since you want it in series.

The way this thing works is that it's an LED inside a tiny box with a phototransistor so when the led is turned on, the phototransistor goes conductive, which is basically the same as pushing that switch you soldered to. This allows the Arduino to control whatever buttons you want without being electrically connected, so it can work with any circuit!

Step 4: Add in Wires to the Arduino

Add in the wires from the other end of the resistor. I used wires with pins on the end just because they're easy to insert and reinsert into the Arduino pins.

Solder pins 2 and 3 together then put a ground cable in line.

Step 5: Wire Up the Buttons to the Opto Isolator

Add the pairs of wires for the button switches up to the pairs of phototransistors. These are in pin pairs as 13 & 14, 15 & 16. The polarity needs to be right on this but it won't break anything if it's wrong, it just won't do anything. There's no solid way of knowing which way around it should be without really knowing the PCB design so you'll just have to see if it works later and if not then swap the wires around. For me one worked straight away, the other didn't so I flipped it and it worked.

Step 6: Attach a Battery to the Remote and Open Up Your PC Case to Insert the Circuit

The Arduino is powered over USB and this is also how we will program it. I used a wire threaded through a slot at the back to a USB port at the rear of the PC. One more wire and then it's ready to program.

Step 7: Connect A0 Pin to the Motherboard Positive Power LED Indicator Pin

Disconnect the positive power LED connector pin and replace it with your own female ended wire that is stripped at the other end. I spliced in a second wire (single core) to reconnect with the actual power indicator LED because you do still want that to work ;) Connect the stripped end to the A0 pin on the Arduino board and then we're ready to program.

Step 8: Program the Arduino

Upload the following code: (make adjustments for the pins you are using)

// // PERIPHERAL MAINS POWER CONTROL THROUGH SENSING THE MOTHERBOARD POWER LED // - Oscar /////////////////////////////////////////////////////////////////////////////////

// pin that connects to the positive of the opto-isolator // for the on button leads // (if these don't work then try switching around the switch // leads from the opto-isolator to the remote) int powerOnPin = 10; // same for the off button int powerOffPin = 9;

// input pin from the Motherboard's power LED (5v) int inputPin = A0;

int arduinoLedPin = 13;

boolean isPcOn = false; boolean wasPcOn = false;

void setup() { // set inputs and outputs pinMode(inputPin, INPUT); pinMode(powerOnPin, OUTPUT); pinMode(powerOffPin, OUTPUT); pinMode(arduinoLedPin, OUTPUT); }

// in the loop, we check to see if the PC is on and set the power LED accordingly // we then see if the power status has changed and if so, turn the power on or off void loop() { // find out if the PC is on by reading the Motherboard LED pin isPcOn = digitalRead(inputPin);

// show the power status with flashing (on) or solid (off) LED if (isPcOn) { ledFlash(); } else { ledOn(); }

// if the power status is different to before, turn power on or off if (isPcOn != wasPcOn) { if (isPcOn) power(true); else power(false); }

// this is important so that we can tell if power state has changed from last time wasPcOn = isPcOn; }

// method to switch on or off power via the remote void power(boolean powerCommand) { // button (on or off) that will be pressed int buttonToPress; // set which button will be pressed if (powerCommand) { buttonToPress = powerOnPin; } else { buttonToPress = powerOffPin; }

// press the button for 100ms digitalWrite(buttonToPress, HIGH); delay(100); digitalWrite(buttonToPress, LOW); }

// solid LED to show arduino knows the PC is off void ledOn() { digitalWrite(arduinoLedPin, HIGH); delay(100); }

// short flash of the LED to show arduino knows PC is on void ledFlash() { digitalWrite(arduinoLedPin, LOW); delay(500); digitalWrite(arduinoLedPin, HIGH); delay(500); }

Step 9: Debug the Device

Give it a go. Try putting your computer to sleep and waking it again.

So something's probably not going to work immediately, but that's ok. We can work through it. Assuming you've got your code uploaded here's the order I would go through things in to find out what's not working:

  1. Check the status LED on the Arduino board next to pin 13. It should be flashing when your computer is on, and then when you sleep your PC and wait for the power LED to turn off, the LED on the Arduino should switch to a solid light. When you come out of sleep it should go back to flashing. If this is working then we know that the Arduino board knows when your PC is awake. If not then check that the motherboard pin is plugged into the correct Arduino pin and that your Arduino is getting power from your PC (as they need a common ground). It really should be as simple as that for this unless you're using a non 5V Arduino (might work but I haven't tested)
  2. Check that you have a battery in the remote. Try pressing the buttons on the remote's PCB physically rather than with the Arduino. If that isn't working then something's with that part.
  3. Try flipping the polarity on the leads from the switches. If only one switch is being triggered (e.g. off but not on or vice versa) then this is quite likely the cause and I know I had this problem. Might be worth trying with one if neither are working because you might be unlucky enough to have both the wrong way around.
  4. Check the pins on your Opto Isolator. I got mine from maplin but yours might be different and I know that on some the LEDs are a different way around inside so check the datasheet if you didn't before and compare it to mine.
  5. If it's still not working then try replacing the Opto Isolator. If you connected the leads to the LEDs the wrong way around you may have broken it but at this point you'll have to get creative finding out what's wrong.

Step 10: Enjoy Your Control!

Now you can link up whatever you want to control on those mains plugs and they'll turn on and off with your PC. I have my Studio Monitors, Subwoofer and one of my screens linked to it because those devices don't sleep properly with my computer but now I can make them!

Try adding more channels to control more stuff and you can add more inputs like an infrared sensor to detect when you're in the room and turn a lamp on or something. You can do a lot more with this and it's really just repeating these steps with more channels. I'm sure if you just have a glance around the room you can think of a few cool projects.

Have fun!

<p>Well done, instructions are very clear :) </p>
Ah thanks! Let me know if there's anything I'm missing since this is my first instructable. Thought it was about time I gave back :)
<p>Thanks for the clear instructions! This is very helpful.</p>

About This Instructable




More by randomthumper:Control Anything and Save Power with Arduino 
Add instructable to: