Monday, November 30, 2015

Configure PC Remote Control by Arduino Pro Micro

                                                                                                                                                                  


Hello Friends  J

Recently I wanted to use
Arduino UNO and IR remote to control VLC player. Unfortunately this didn't work well for me as Uno does not have built-in USB communication. For this reason it involves more steps to get the job done, like have to upload appropriate .hex file to the microcontroller to make it function as a HID (Human Interface Device). I went through different steps to make it possible (while reading many sources online) but I failed at it. I will attempt it again to understand further.

But for now...
I bought a Pro Micro and it is Arduino Leonardo compatible, since it has Atmega32U4, it can be used as HID mouse or keyboard. In order to control VLC I used this as a HID keyboard.
I went with Pro Micro instead of Arduino Leonardo is because of the size.

Majority of the steps are similar however the coding is changed slightly to suit my remote and the functions I required. Let’s get started

Step 1: Hardware

Note: You can use Leonardo as well. I chose Pro Micro due to the small form factor.
1 x 5mm Led (Not essential, just to indicate when the signal is received. your choice of color) –
Note: I have tested 3 different remotes they all worked so it doesn't matter as long as it is an IR remote. I chose this again for the small form
(Kindly correct me if I'm wrong)

Step 2: Set Up Pro Micro
This was my first experience with Pro Micro and it was not smooth.
At first the computer did not recognize Pro Micro as a HID device and also it was not showing up in the Arduino IDE.
After some Google searches and disabling the digital signature thing from checking in windows 8, finally I was able to install the Pro Micro's driver and then it showed up.
But it didn't end there and tried to upload the code and it started to show errors in the Arduino IDE (sorry didn't take any snapshots).

Later used my Uno R3 as AVR ISP and burned the boot loader for the Pro Micro and Vola it worked fine.
Boot loader for Pro Micro and the drivers has been attached and also can be found in spark fun website.

Step 3: Connections

Following the datasheet, the IR receiver is connected to the breadboard and using jumper wires to connect them to appropriate pins in the Pro Micro.
IR Receiver's output pin is connected to Pro Micro's pin 7 and powered by VCC pin (5V provided by the USB connection from the computer) and GND to GND pin.

LED is connected to pin 10 and GND.

Follow the pictures above to get clear. If you want a schematic diagram let me know in the comment & I'll upload as soon as I can.

Step 4: Getting the code for the IR Remote Buttons
Note: The code below allows the serial monitor to display the code received from the IR receiver in Decimal hence DEC.
serial.println (results. value, DEC);
If you want to use hexadecimal code just simply change the DEC to HEX, like
serial.println (results. value, HEX);
Kindly stick to one of the code either DEC or HEX in all the codes.
It is helpful to write down which code belongs to which button to avoid confusion later. I used spreadsheet to write mine down and while coding you can just copy the appropriate button's code from the spreadsheet.

Step 5: Customizing the code to execute functions in computer

Use the code attached and makes changes to the remote button codes.
You can add more functions as per your requirements.
To add more codes there are three places you have to insert the code.

I will show an example below:
Note:
Places with XXX means you can add your own name;
Places with YYY is the DEC/ HEX code from remote; and
Places with ZZZ have to change according to the keys you need to press.
I'm just showing only what needs to be added to know where to insert them kindly look at the attached file.
#define XXX YYY //use comments to make note of what the button does or refer it to the button on remote
#define XXX YYY
2nd Place
#define XXX_FUN Keyboard.press(ZZZ); Keyboard.press(ZZZ); Keyboard.write('ZZZ'); delay(100); Keyboard.releaseAll(); 
#define XXX_FUN Keyboard.write('ZZZ'); Keyboard.releaseAll();
Note: Keyboard.press --> presses the button such as arrow, ctrl, shift,..
Keyboard.write --> writes the characters a,b,c...
3rd Place
else if (results.value==XXX) {XXX_FUN; }
else if (results.value==XXX) {XXX_FUN; }
Any doubt kindly leave a comment and I'll help as much as I can.

Step 6: Customizing the Remote

The numbers in the remote didn't suit my need therefore I wanted to make my own names for the buttons.
1) I took a paper and pressed the sides of the remote to make the impression of it and cut along the impression.
2) I placed the paper on the remote and used my thumb nail around the buttons to capture the form.
3) Using a pen wrote the names/ symbols I wanted (according to the function it has been assigned in the code).
4) Used the plastic cover that came with the remote and inserted the label that I just made and sealed it.
5) A custom labeled remote is ready and can be changed any time I needed.
Step 7: Enjoy
You can the remote's button to press whatever keys you want to be pressed in a keyboard with appropriate code.
You can also add shortcut keys to programs and add that to your code, then you can launch the program by a single button in your remote. Like I have done in mine.(refer to the code in line #49 - IRrecvVIRE_HID.ino)
I have used my remote to control VLC player basically and the arrow keys and enter key so that I can select a movie using remote and also control VLC.

Show me what you have done with it.
And vote for me if you liked it!!!



No comments:

Post a Comment