Arduino to convert toggle switch to momentary + windows volume control

I am wondering how feassible it will be to allow an Arduino (currently Uno but may be the micro later on) to allow me to convert the state of a toggle switch to that of a momentary button through a 12V relay. The reason I want to do this is that I have a case that only has an on/off toggle and want to use it to turn on a computer, however computers only turn on with momentary buttons.

Using some code and some logic I thought I could change it so that when the switch toggles on that the ardunio triggers the relay to turn on momentarily simulating a power switch being pressed, then turning off. When the switch is toggled off the arduino would trigger the relay on for a longer duration, then eventually turn off, which would make the Windows machine turn off (like holding down the power button).

I am also wanting to control Windows Volume through a slider, which should be easy, as it essentially should be a pot, the Arduino interpreting it and then sending either a keyboard hotkey back to the system which Windows would recognize and the volume would be changed (don't know how easy this is to do Arduino side) OR it would communicate to a simple program that starts with Windows in the background which would adjust the volume when it gets a command from the Arduino.

Love to hear how feasible or doable either are and potential parts that may be the best to accomplish this job.

For the on/off button a relay should certainly work. Maybe an optoisolator would as well. We had a question about that a few minutes ago related to triggering a camera shutter.

As for the volume, some keyboards have a volume up/down key, so it must generate some sort of USB codes that you could probably emulate with the ATmega32u4-based Arduinos (like the Micro).

Much easier to replace the switch in question with a momentary - or just get a pair of pliers and pull out the "toggle" spring (little piece of spring wire).

The beauty of the "soft" switch is that rather than just turning off the power, it safely shuts down WIndoze - or not if there is some program with unsaved data.

Haven't tried it, and no doubt will not in the near future, but the Leonardo and its "micro" version have the capability of USB HID emulation including keyboard, and there are standard codes for volume up, down and mute, so it definitely will be capable of emulating that.

You almost certainly (I presume it goes to ground) do not need a relay to control the power "soft switch", a transistor should do just fine as discussed here.

The project sounds a bit problematic, because you'd need to produce a momentary output each time the switch changed state so you'd end up with a situation where the PC powered on or off each time you moved the switch, but the state of the PC and the state of the switch could easily get out of sync and would then stay out of sync indefinitely i.e. the switch shows 'off' but the PC is on, and vice versa.

Setting that aide, the logic could be achieved with an Arduino, but it feels like the sort of thing that could be achieved just as easily for a fraction of the cost and complexity using a couple of 555 timers.

My PC (and another I saw recently) had four wires running to the power switch from the motherboard. I presume two detected a switch press, and two lit up the LED inside/adjacent to the switch.

So you could use the second pair of wires to detect if the power was currently on or not.

And you would want to intercept the standby power (purple wire) from the PSU to actually run the Arduino. It would not make sense any other way.

Actually most motherboards have an always-on charging USB port these days so I may not have to do that, however if the one I grab doesn't I'll tap that line.

I'd more than likely need to use the Arduino for the volume control so using it to convert the toggle switch to a momentary using a relay wouldn't be a waste of money on it. Again, the switch would move from off to on, Arduino would detect this voltage change and set the relay to turn on then off simulating a button push on that line to the motherboard (aka it's just a short). After this the Arduino would ignore the voltage high reading from the switch (unless windows was shut down). When the switch is moved from the on to the off position, it would again detect this voltage change and turn the relay on for a slightly longer period of time, causing the computer to turn off.

The only way I can see the switch being in the wrong position compared to the state of the computer is when the system is shut down through windows. When that happens I guess I'd need to intercept a signal to know this, so that when it's moved to the off position when the computer has been successfully shut down it won't turn the computer back on again.

[quote author=Nick Gammon link=topic=194136.msg1434872#msg1434872 date=1382214314] So you could use the second pair of wires to detect if the power was currently on or not. [/quote]

That's a good point - it's very common in my experience for momentary power switches to show their current state via an LED and so a motherboard designed to work with one could be expected to provide a suitable signal. Given the signal, I'm even more confident that it would be possible to generate the required pulses (turn the PC on if it is not already on, etc) via a couple of hardware timers. Or you could use an Arduino if you don't mind throwing money at the problem.

Well, a breadboard "Arduino" is only throwing a couple of dollars at the problem, and you have a lot more control.

And you don't need a relay.

It has been mentioned before that if you are controlling a logic circuit, there is probably insufficient current in the circuit to "wet" the contacts.

(Before someone chimes in, yes you could use a reed relay.)

I was under the assumption that the power supply switch is fed 12V, if it’s actually lower, something the Arduino can handle you are right I would not need a relay, just to toggle a digital output pin.

Time to break out the multimeter!

Arinoth: I was under the assumption that the power supply switch is fed 12V, if it's actually lower, something the Arduino can handle you are right I would not need a relay, just to toggle a digital output pin.

It cannot be fed 12V - there is no 12V when the computer is turned off. The standby power supply is 5V.

All logic is in fact 5V, 12V only exists to drive motors in larger disk drives (and RS-232).

However you certainly should use a transistor to interface to it, not just an Arduino pin. In which case (referenced to ground) it would not matter if it were 12V.

The motherboard has a power light to indicate it's on.

Problem 1 solved (high is on, low is pc off) Problem 2, use a transistor to switch on the pc.. Problem 3. Controlling windows volume.

  1. Use a leonardo ur vusb on an uno and emulate button presses.
  2. Run a small server/program on the PC which adjusts volume.

If 2 . You can interface with USB, and over a com port instruct your program to change the volume.

Another way is to use bluetooth or ethernet.

cjdelphi: 2. Run a small server/program on the PC which adjusts volume.

If 2 . You can interface with USB, and over a com port instruct your program to change the volume.

The "server program" is already part of Windoze, has been since '95 AFAIK. Presumably Apple as well. You feed it standard documented keyboard codes via USB as a HID device. A Leonardo or "micro" is designed to do this.

Paul__B:

cjdelphi: 2. Run a small server/program on the PC which adjusts volume.

If 2 . You can interface with USB, and over a com port instruct your program to change the volume.

The "server program" is already part of Windoze, has been since '95 AFAIK. Presumably Apple as well. You feed it standard documented keyboard codes via USB as a HID device. A Leonardo or "micro" is designed to do this.

How?

I think you need to chase up "Leonardo HID device".

Are you talking nonsense?

The Windows virtual key definitions include various codes (0xA6 .. 0xB6 etc) to control mail applications, browsers, media players as well as muting and adjusting the volume. I haven't tried generating these application control keys programatically, but I noted that on the systems I've had with keyboards that include these non-standard keys, a non-standard driver was required to make them do anything useful. Unless you have a system that supports a keyboard with these keys, and you choose the virtual key codes which that system actually recognises, I suspect it simply won't work. You don't have anything to lose by trying, but don't assume that just because the codes are defined that they will automatically do what you want.

PeterH: on the systems I've had with keyboards that include these non-standard keys, a non-standard driver was required to make them do anything useful.

Our experiences differ then. On Brand-name keyboards (HP/Compaq, Dell) and various machines (HP/Compaq, Dell, Acer, Asus, generally not paired by name) it seems to work for me without problems. Is it only the big name manufacturers that install the drivers by default?

Thus prompted, I will bring home the Space Cadet Keyboard and verify it on Linux as well. XD