The NEW Build Your Own Arcade Controls

Main => Raspberry Pi & Dev Board => Topic started by: a_netanel on April 08, 2018, 05:01:01 am

Title: Using Adruino as Remote Control to turn TV on/off automatically
Post by: a_netanel on April 08, 2018, 05:01:01 am
I'm about to finish a vertical cab, in which I used a cheap 40 inch LCD TV, mounted vertically.
One problem I had, was that the TV would not turn on and off with the PC it is connected to.
The PC uses DVI so I could not use any HDMI CEC functionality.

What I came up with eventually, is an Arduino based IR transmitter that will send the right "remote control" command to the TV when the Windows starts and shuts down, as if I pressed the "Power" button on the remote.

The steps are roughly as follows:
1. Buy an Arduino board (https://www.aliexpress.com/item/1set-UNO-R3-MEGA328P-ATMEGA16U2-for-Arduino-Compatible-USB-Cable-Free-Shipping/32727299178.html) (I used an UNO clone that I already had), an IR transmitter (https://www.aliexpress.com/item/Infrared-Emission-Module-IR-Transmitter-For-Arduino-Electronic-Blocks/2029602391.html)  and receiver (https://www.aliexpress.com/item/KY-022-3pin-TL1838-VS1838B-1838-Universal-IR-Infrared-Sensor-Receiver-Module-for-arduino-Diy-Starter/32823011617.html). I actually used 2 Arduino boards for testing. Given the price, you may want to do the same, but you can get away with just one.
2. Install the Arduino IDE  (https://www.arduino.cc/en/main/software).
3. Install the IRremote library (https://github.com/z3t0/Arduino-IRremote).
4. Connect the receiver pins to the board. The data pin from the receiver to PIN 11 on the board, and 5v and ground to the corresponding pins.
5. Upload the IRrecvDump code from the examples in the IRremote library, to your board.
6. Open Serial Monitor.
7. Point the TV remote to the receiver and press the "Power" button. The monitor should print the data the it received. In my case it was "NEC, 4FB4AB5, 32 bits"
8. Use the above information to edit this script (https://github.com/anetanel/Arduino-IR-Arcade/blob/master/Send_IR_TV.ino). Change the line:
Code: [Select]
irsend.sendNEC(0x4FB4AB5, 32);You can find the function name (sendNEC, for NEC...) in this file (https://github.com/z3t0/Arduino-IRremote/blob/master/IRremote.h) under the IRsend class.
9. Remove the receiver and connect the IR LED (Transmitter) to the Arduino. Use PIN3 for the data, and 5v and ground to the corresponding pins.
10. Upload the edited script to the board.

Now the board is configured to send the IR code every time it gets anything on the serial input. The next thing to do is to connect the board to the PC via USB and send anything (I simply send the letter "A") on the correct serial (COM) port.
I did it with a simple powershell script.

11. Install the Arduino drivers (comes with the IDE) and connect the board to the arcade PC via USB.
12. Open Device Manager and find the COM port that the board uses.
13. Edit the COM number in the following script and save it somewhere as a .cmd file (for example "c:\scripts\ir_script.cmd"):
Code: [Select]
powershell $port=new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one;$port.open();$port.WriteLine(\"A\");$port.close()(I'm using a cmd file to call powershell, to avoid messing with the execution policy restriction, and because windows startup\shutdown scripts does not run ps scripts.. or at least it didn't for me)
14. Point the IR LED to the TV, and run the script. Hopefully the TV will turn off :)
15. Enter the computer's group policy editor (gpedit.msc), and go to Computer Configuration -> Windows Setting -> Scripts (Startup/Shutdown)
16. Edit the properties for both scripts, and point it to the above script (c:\scripts\ir_script.cmd).
17. It seems that the script do not run on shutdown and starting from shutdown state (as opposed to restart) when Hibernation is enabled. To disable it run as administrator the command:
Code: [Select]
powercfg /h offNote that windows update may turn hibernation back on.. so pay attention :)

Some extra information can be found here:
https://learn.sparkfun.com/tutorials/ir-communication (https://learn.sparkfun.com/tutorials/ir-communication)


I couldn't find in the forums anyone that came up with the same solution as I did, so here it is :) .

Title: Re: Using Adruino as Remote Control to turn TV on/off automatically
Post by: ivwshane on April 08, 2018, 01:47:47 pm
Thanks for the post!!

I haven't had to use this yet as every TV I've used so far has had a "power on after power loss" function but this could be used for this screens that don't have that.
Title: Re: Using Adruino as Remote Control to turn TV on/off automatically
Post by: processedmeat on April 11, 2018, 04:22:46 pm
Thanks OP for the helpful post.  FYI on some TVs the "Power On After Power Loss" is also masked as "Store Demo" mode. 
Title: Re: Using Adruino as Remote Control to turn TV on/off automatically
Post by: a_netanel on April 11, 2018, 04:27:18 pm
Thanks.
But even if the TV supported "Power On After Power Loss", what I wanted to achieve is a behavior similar to a computer monitor. I don't cut the power to the cab altogether, just turn off the PC.
Title: Re: Using Adruino as Remote Control to turn TV on/off automatically
Post by: processedmeat on April 12, 2018, 04:40:56 pm
Yes, I forgot to mention that this goes hand in hand with one of those energy saving power strips.  When I turn on my PC, the TV gets juice from the strip and turns on via the Power On After Power Loss or Store Demo feature.