20 March 2012

Arduino Remote Controlled Mouse and Keyboard

Today I'll be sharing a small hack I did about a year back. I'll be showing how you can control your PC's keyboard and mouse using an IR Remote and Arduino. Here's the youtube video of it in action: 

Parts list:
  1. IR based Remote(This could be a remote of a TV, DVD Player, AC, etc) 
  2. TSOP sensor
  3. One 100 ohms resistor
  4. Breadboard
  5. Connecting wires
  6. Arduino
  1. Visual Basic 2010 Express(get it for free here) or Visual Studio
  2. Arduino IDE
The connections are dead simple, all you need to do is connect three wires: 
Vcc is to be connected to Arduino 5V, GND to Arduino GND
TSOP Sensor

Download the complete source code from google code here.

Now, comes the major editing part. We'll be using the IR Remote library for Arduino by Ken Sheriff. This library helps in easy decoding of IR remote signals. You need to install this library(download link and setup instruction on the library page) and I recommend you to go through the examples and get a brief idea about how IR signals are getting decoded before proceeding further.

Since my remote used a non-standard protocol, I obtained the hash code for each button of my remote. Each key when pressed fires a series of precisely timed IR pulses and this pulse train is converted to a unique hash code by this library.

In Remote_Mouse.pde, you'll find that samsung_hash[] contains the hash code values of buttons of the samsung remote I had used. These hex values for buttons are different for every remote. So you'll need to use processKeys() inside loop() initially to obtain the hex values of buttons for your remote. After you obtain them, and update the code with your remote's hash code values, processMouse() can be used.

After you're done, to run the PC application, open MouseSimulator1.sln. I've used the MouseKeyBoard library by codeSummoner to emulate keyboard and mouse from the vb application. The program is well commented and is pretty basic.

Press F5 to run the program. Select your Arduino's com port and click on Start Remote Mouse.

Hope someone finds this useful.

Cheers! :)