Every time I wanted to go to sleep, I would put some music on my desktop PC and tune the volume to a convenient level. After lying in bed, somehow environmental noise seems to faint and all of a sudden the music is too loud to sleep. So I used to get up, lower the volume and go to bed again. Until I decided to take action.
I was, at the time, studying IR communication protocols hence I decided to build an IR system to control the volume of my PC remotely. The idea is simple. A remote control will send IR signals to an arduino equipped with an IR receiver, the arduino will interpret the signals and send, via serial communication, specific instructions to a PC application which will, in turn, do the respective action. It’s worth mentioning that after implementing this initial functionality, it was pretty easy to add more capabilities to the system even ones not related to any PC actions.
Features
- Supported actions (PC-related):
- toggle monitor on/off
- system volume up
- system volume down
- mute
- hibernate
- Supported actions (non PC-related):
- embedded light toggle on/off
Technical Notes
The circuit
An arduino nano was used as a microcontroller since it has built-in serial to usb capability. The hardware components connected to it are a VS1838B IR receiving module, a buzzer for audible feedback (more on that later), a N.O. momentary switch and a led.
The software for the micro was written in C and it uses Ken Shirriff’s IRremote library which provides an easy way for recognizing IR signals. The specific remote control used, follows the NEC IR protocol, supports holding down a button (e.g. for changing the volume) and provides audible feedback for receiving unsupported IR signals.
Every time it has to forward a specific command to PC, it prints to its serial output a specific string:
String to be sent | Action to be triggered |
---|---|
__CMD_MONOFF | turn monitor on/off |
__CMD_HBRN | hibernate |
__CMD_VOLINC | increase volume |
__CMD_VOLDEC | decrease volume |
__CMD_MUTE | mute |
PC Client
The PC client is written in Java (obviously not the wisest choice for native calls… ) and its task is pretty much straightforward. Connect to a serial port, listen for incoming messages and interpret them accordingly. For serial ports’ access, rxtx library was initially utilized but it was subsequently replaced with JSSC library, which seemed much more stable and easier to use. As for the necessary native calls, like changing system volume, turning monitor on/off etc, the easiest (but not so elegant) solution was given by an excellent little program called nircmd which allows you to do some useful tasks without displaying any user interface just by running it with simple command-line options.
Besides this core functionality, the PC client also has some convenience features:
- Graphical user interface
- COM ports scan feature
- minimize to system tray support
- support for automatically connecting to a specific COM port and starting minimized (convenient when declared to run at windows startup)