Remote Control for PC

tjetson

Senior Member
G'day there

Here's a circuit I made a while ago. I had read on the internet that certain mobile phones could be used as a remote control for your computer. My old phone wasn't one of these, so I thought: why don't I build something to do this?

My camera wouldn't take a good enough photo of the circuit, so I made a picture using the very marvelous PEBBLE. The IR receiver is the Jaycar ZD-1952 module. My dad bought me a cheap universal remote control and I programmed that to use the Sony codes. The LEDs on the board were for testing purposes, so I could see if the IR unit was receiving a signal.

I wrote a program in Liberty BASIC for the computer, which reads the remote codes from the serial port. It then simulates keyboard keypresses, for example if you press Pause on the remote, the software sends Ctrl+P to Windows Media Player, thus pausing whatever movie you have going. I also made the numbers 0-9 launch various programs.

Picaxe Code:
Code:
main:

b0 = 1
symbol offset = b0



infrain2
infra = infra + offset

if infra < 42 then
	high 0
	pause 100
	low 0
end if

if infra > 42 and infra <84 then
	high 1
	pause 100
	low 1
end if

if infra > 84 then
	high 2
	pause 100
	low 2
end if 

infra = infra + offset

sertxd (#infra)
pause 100

goto main
EDIT: I forgot to add this to the PEBBLE picture, but the 3 way header is for a download cable, and the transistor at the bottom is the IR module, Jaycar model ZD-1952.
 

Attachments

Last edited:

tjetson

Senior Member
Liberty BASIC code:
Code:
'========================================================================'
'================     Picaxe 08M Serial Communicator     ================'
'========================================================================'

Rem Communicates with the Picaxe 08M IR receiver
Rem Uses Communications Port 1

Rem Code By Tjetson
Rem Last update: 20/09/2009
Rem Written in Liberty BASIC v4.04


    mainwin 60 10

    oncomerror [comerror]
    on error goto [error]
    print "Program started."
    print "Reading Com1 at 4800bps..."
    print

    open "com1:4800,n,8,1" for random as #comm    'Picaxe needs com port 1; 4800 baud, no parity, 8 data bits, 1 stop bit

[loop]
    'Data input loop
    dataRead$ = input$(#comm, lof(#comm))     'Read from Com Port the amount of information that exists there
    num = val(trim$(dataRead$))               'Convert to a number
    select case num

        case 2                                '1 on remote was pushed
            run "notepad.exe"
            print "Running Notepad..."


        case 3                                '2 on remote was pushed
            run "C:\Program Files (x86)\Internet Explorer\iexplore.exe http://www.google.com.au"  'Run Google
            print "Loading www.google.com.au..."


        case 4                                '3 on remote was pushed
            run "C:\Program Files (x86)\Internet Explorer\iexplore.exe http://en.wikipedia.org/wiki/Main_Page"   'Run Wikipedia
            print "Loading Wikipedia..."


        case 5                                '4 on remote was pushed
            run "C:\Windows\System32\calc.exe"
            print "Running Calculator..."


        case 6                                '5 on remote was pushed
            run "explorer.exe"
            print "Running Explorer..."


        case 7                                '6 on remote was pushed
            run "C:\Program Files (x86)\Microsoft SMS Sender\SMSSender.exe"
            print "Running Microsoft SMS Sender..."


        case 8                                '7 on remote was pushed
            run "mspaint.exe"
            print "Running Paint..."


        case 9                                '8 on remote was pushed
            run "C:\Program Files (x86)\Windows Live\Messenger\msnmsgr.exe"
            print "Running Windows Live Messenger..."


        case 10                                '9 on remote was pushed
            run "C:\Program Files (x86)\Microsoft Office\OFFICE11\winword.exe"
            print "Running Microsoft Word..."






        case 28                               'VCR mode on remote sent Play
            Call KeyboardClick _VK_CONTROL , 0   'Press Control
            Call KeyboardClick asc("P") ,    0   'Press P
            Call KeyboardClick asc("P") ,    2   'Release P
            Call KeyboardClick _VK_CONTROL , 2   'Release Control
            print "Play pushed in WMP."


        case 29                               'VCR mode on remote sent Rewind
            Call KeyboardClick _VK_CONTROL , 0   'Press Control
            Call KeyboardClick asc("B") ,    0   'Press B
            Call KeyboardClick asc("B") ,    2   'Release B
            Call KeyboardClick _VK_CONTROL , 2   'Release Control
            print "Rewind pushed in WMP."


        case 30                               'VCR mode on Remote sent Fast Forward
            Call KeyboardClick _VK_CONTROL , 0   'Press Control
            Call KeyboardClick asc("F") ,    0   'Press F
            Call KeyboardClick asc("F") ,    2   'Release F
            Call KeyboardClick _VK_CONTROL , 2   'Release Control
            print "Fast Forward pushed in WMP."


        case 27                               'VCR mode on Remote sent Pause
            Call KeyboardClick _VK_CONTROL , 0   'Press Control
            Call KeyboardClick asc("P") ,    0   'Press P
            Call KeyboardClick asc("P") ,    2   'Release P
            Call KeyboardClick _VK_CONTROL , 2   'Release Control
            print "Pause pushed in WMP."


        case 31                               'VCR mode on Remote sent Record
            Call KeyboardClick _VK_CONTROL , 0   'Press Control
            Call KeyboardClick _VK_SHIFT ,   0   'Press Shift
            Call KeyboardClick asc("N") ,    0   'Press N
            Call KeyboardClick asc("N") ,    2   'Release N
            Call KeyboardClick _VK_SHIFT ,   2   'Release Shift
            Call KeyboardClick _VK_CONTROL , 2   'Release Control
            print "Normal play pushed in WMP."


        case 26                               'VCR mode on Remote sent Stop
            Call KeyboardClick _VK_CONTROL , 0   'Press Control
            Call KeyboardClick asc("S") ,    0   'Press S
            Call KeyboardClick asc("S") ,    2   'Release S
            Call KeyboardClick _VK_CONTROL , 2   'Release Control
            print "Stop pushed in WMP."

        case 119                              'VCR mode on Remote sent Slow Back
            Call KeyboardClick _VK_CONTROL , 0   'Press Control
            Call KeyboardClick _VK_SHIFT ,   0   'Press Shift
            Call KeyboardClick asc("S") ,    0   'Press S
            Call KeyboardClick asc("S") ,    2   'Release S
            Call KeyboardClick _VK_SHIFT ,   2   'Release Shift
            Call KeyboardClick _VK_CONTROL , 2   'Release Control
            print "Slow play pushed in WMP."


        case 118                              'VCR mode on Remote sent Slow Forward
            Call KeyboardClick _VK_CONTROL , 0   'Press Control
            Call KeyboardClick _VK_SHIFT ,   0   'Press Shift
            Call KeyboardClick asc("G") ,    0   'Press G
            Call KeyboardClick asc("G") ,    2   'Release G
            Call KeyboardClick _VK_SHIFT ,   2   'Release Shift
            Call KeyboardClick _VK_CONTROL , 2   'Release Control
            print "Fast play pushed in WMP."


        case 60                                'DISP button was pushed
            Call KeyboardClick _VK_MENU ,     0   'Press Alt
            Call KeyboardClick _VK_RETURN ,   0   'Press F4
            Call KeyboardClick _VK_RETURN ,   2   'Release F4
            Call KeyboardClick _VK_MENU ,     2   'Release Alt
            print "Full screen activated in WMP."






        case 99                               'Video button was pushed
            run "C:\Program Files (x86)\Windows Media Player\wmplayer.exe"
            print "Running Windows Media Player.exe"


        case 100                              'Audio button was pushed
            run "C:\Program Files (x86)\Audacity 1.3 Beta (Unicode)\audacity.exe"
            print "Running Audacity 1.3..."




        case 61                              'V+ button was pushed
            Call KeyboardClick _VK_F9 ,       0   'Press F9
            Call KeyboardClick _VK_F9 ,       2   'Release F9
            print "Increasing sound in WMP..."


        case 109                              'V- button was pushed
            Call KeyboardClick _VK_F8 ,       0   'Press F8
            Call KeyboardClick _VK_F8 ,       2   'Release F8
            print "Decreasing sound in WMP..."


        case 22                                'Mute button was pushed
            Call KeyboardClick _VK_F7 ,       0   'Press F7
            Call KeyboardClick _VK_F7 ,       2   'Release
            print "Muting sound in WMP..."






        case 98                                'Menu button was pushed
            Call KeyboardClick _VK_LWIN ,     0   'Press the Windows key
            Call KeyboardClick _VK_LWIN ,     2   'Release the Windows key
            print "Opening Start Menu..."
Continued in next post...
 

tjetson

Senior Member
Rest of LB code:
Code:
        case 18                                 'Up was pushed on remode
            Call KeyboardClick _VK_NUMPAD8,   0   'Press the numpad 8 key
            Call KeyboardClick _VK_NUMPAD8,   2   'Release the numpad 8 key
'            Call KeyboardClick _VK_UP,        0   'Press the numpad 8 key
'            Call KeyboardClick _VK_UP,        2   'Release the numpad 8 key


        case 19                                 'Down was pushed on remode
            Call KeyboardClick _VK_NUMPAD2,   0   'Press the numpad 2 key
            Call KeyboardClick _VK_NUMPAD2,   2   'Release the numpad 2 key
'            Call KeyboardClick _VK_DOWN,      0   'Press the numpad 8 key
'            Call KeyboardClick _VK_DOWN,      2   'Release the numpad 8 key

        case 21                                 'Left was pushed on remode
            Call KeyboardClick _VK_NUMPAD4,   0   'Press the numpad 4 key
            Call KeyboardClick _VK_NUMPAD4,   2   'Release the numpad 4 key
'            Call KeyboardClick _VK_LEFT,      0   'Press the numpad 8 key
'            Call KeyboardClick _VK_LEFT,      2   'Release the numpad 8 key

        case 20                                 'Left was pushed on remode
            Call KeyboardClick _VK_NUMPAD6,   0   'Press the numpad 6 key
            Call KeyboardClick _VK_NUMPAD6,   2   'Release the numpad 6 key
'            Call KeyboardClick _VK_RIGHT,     0   'Press the numpad 8 key
'            Call KeyboardClick _VK_RIGHT,     2   'Release the numpad 8 key




        case 23                               'Power button on remote was pushed
            Call KeyboardClick _VK_MENU ,     0   'Press Alt
            Call KeyboardClick _VK_F4 ,       0   'Press F4
            Call KeyboardClick _VK_F4 ,       2   'Release F4
            Call KeyboardClick _VK_MENU ,     2   'Release Alt
            print "Program terminated."
    end select



    timer 500, [delay]                       'Wait for half a second


    num = 0                                   'Clear variables, just in case
    dataRead$ = ""
    wait

[comerror]
    print "Com Error:    "; ComError$
    print "Com Port:     "; ComPortNumber
    print "Error Number: "; ComErrorNumber
    print "Infrared Receiver may not be turned on."
    goto [quit]

[error]
    print "Error: "; Err$
    print "Error Code: "; Err
    goto [quit]

[delay]
    timer 0
    goto [loop]


[quit]
    print "Communication terminated."
    close #comm
    end





Sub KeyboardClick n, pos
' Need a little time in between keypresses
    CallDLL #kernel32, "Sleep", 10 as uLong, result as Void
' pos 0 = Down, 2 = Up
    CallDLL #user32, "keybd_event", _
        n as Long, _
        null as Long, _
        pos as Long, _
        result as Void
End Sub
 
Top