IR sensor and transmitter on Raspberry Pi 3

January 15, 2018

Spent two days on this. Record the procedures here for later reference.

Parts from RS

  • Raspberry Pi 3b
  • Transistor – Fairchild PN2222ATA NPN Transistor, 1 A, 40 V, 3-Pin TO-92 (RS Stock No.739-0381)
  • Resistor 680Ω – RS Pro RS Series Axial Fixed Resistor 680Ω ±5% 0.25W -500 → +350ppm/°C (RS Stock No.707-7656)
  • IR LED – Vishay TSAL4400, 940nm IR LED, 3mm (T-1) Through Hole package (RS Stock No.699-7629 )
  • IR Receiver
    Vishay TSOP4438, 38kHz IR Receiver, 950nm ±45 °, 45m Range, 2.5V – 5V, Through Hole, 6 x 5.6 x 6.95mm (RS Stock No.773-3823 )

Circuit

The circuit apply only to the EXACT parts noted above. Refer to datasheet of your parts if it is different than mine.

  • The longer leg of the IR LED connect to 3.3v.
  • The shorter leg of the IR LED connect to the connector of the transistor.
  • Different manufacturer have different arrangement on the legs of the transistor, make sure you checking the datasheet of the transistor to identify the EBC legs arrangement.

At the beginning of setup, I was using an IR LED which is made by China. It just never submit any Infrared. But irsend command was totally good without any error. So I guess the command never rearch the IR LED at all. Turn out that a friend told me that LED do not works with transistor :-O. So always refer to datasheet for actual setup of your parts.

Setup for Raspberry PI

  1. SSH to pi
  2. # sudo su
  3. # apt-get install lirc
  4. # vi /etc/modules

    Add the lines below to the end of the file

    lirc_dev
    lirc_rpi gpio_in_pin=23 gpio_out_pin=22
    

  5. # vi /etc/lirc/hardware.conf

    Add the contents below

    LIRCD_ARGS="--uinput"
    LOAD_MODULES=true
    DRIVER="default"
    DEVICE="/dev/lirc0"
    MODULES="lirc_rpi"
    LIRCD_CONF=""
    LIRCMD_CONF=""
    

  6. # vi /boot/config.txt

    Add the lines below to the end of the file

    dtoverlay=lirc-rpi
    dtparam=gpio_in_pin=23
    dtparam=gpio_out_pin=22
    

  7. # vi /etc/lirc/lirc_options.conf

    Update the value below

    from

    driver          = devinput
    

    to

    driver          = default
    

  8. # reboot

Testing IR Receiver

  1. # sudo su
  2. # /etc/init.d/lircd stop
  3. # mode2 -d /dev/lirc0
  4. Pick any IR remote, point to the IR receiver, then click any button, if IR receiver capable to capture something, it will print to the screen.

Testing IR sender

  1. # /etc/init.d/lircd stop
  2. # vi /etc/lirc/lircd.conf.d/viera.conf
  3. Add the lines below to viera.conf

    begin remote
    
      name  Viera
      bits           24
      flags SPACE_ENC
      eps            30
      aeps          100
    
      header       3503  1681
      one           449  1255
      zero          449   381
      ptrail        450
      pre_data_bits   24
      pre_data       0x400401
      gap          74158
      toggle_bit_mask 0x0
    
          begin codes
              KEY_POWER                0x00BCBD                  #  Was: power
              KEY_MENU                 0x004A4B                  #  Was: menu
              tv/video                 0x00A0A1
              KEY_EXIT                 0x9059C8                  #  Was: exit
              KEY_ENTER                0x002B2A                  #  Was: return
              KEY_SUBTITLE             0x90E574                  #  Was: sub-menu
              KEY_UP                   0x005253                  #  Was: up
              KEY_DOWN                 0x00D2D3                  #  Was: down
              KEY_LEFT                 0x007273                  #  Was: left
              KEY_RIGHT                0x00F2F3                  #  Was: right
              KEY_OK                   0x009293                  #  Was: ok
              KEY_R                    0x000E0F                  #  Was: r
              KEY_G                    0x008E8F                  #  Was: g
              KEY_B                    0x00CECF                  #  Was: b
              KEY_Y                    0x004E4F                  #  Was: y
              KEY_CHANNELUP            0x002C2D                  #  Was: ch+
              KEY_CHANNELDOWN          0x00ACAD                  #  Was: ch-
              KEY_VOLUMEUP             0x000405                  #  Was: vol+
              KEY_VOLUMEDOWN           0x008485                  #  Was: vol-
              aspect                   0x207B5A
              KEY_FAVORITES            0x9075E4                  #  Was: favorite
              KEY_AGAIN                0x009C9D                  #  Was: recall
              KEY_MUTE                 0x004C4D                  #  Was: mute
              KEY_1                    0x000809                  #  Was: 1
              KEY_2                    0x008889                  #  Was: 2
              KEY_3                    0x004849                  #  Was: 3
              KEY_4                    0x00C8C9                  #  Was: 4
              KEY_5                    0x002829                  #  Was: 5
              KEY_6                    0x00A8A9                  #  Was: 6
              KEY_7                    0x006869                  #  Was: 7
              KEY_8                    0x00E8E9                  #  Was: 8
              KEY_9                    0x001819                  #  Was: 9
              KEY_0                    0x009899                  #  Was: 0
              r-tune                   0x00ECED
              KEY_CHANNELDOWN          0x900B9A                  #  Was: prog-
          end codes
    
    end remote
    
    

  4. Relocate the pi with breadboard in front of the Panasonic TV.
  5. # /etc/init.d/lircd start
  6. # /etc/init.d/lircd stop
  7. # irsend SEND_ONCE Viera KEY_POWER

In case someone found this useful, below are the configs I captured for my things.

Panasonic THL42ET5H 3D iDTV

begin remote

  name  et5h
  bits           24
  flags SPACE_ENC
  eps            30
  aeps          100

  header       3508  1703
  one           480  1265
  zero          480   391
  ptrail        481
  pre_data_bits   24
  pre_data       0x400401
  gap          74804
  toggle_bit_mask 0x0
  frequency    38000

      begin codes
          KEY_POWER                0x00BCBD
          KEY_TV                   0x400C4D
          KEY_SWITCHVIDEOMODE      0x00A0A1
          KEY_MENU                 0x004A4B
          KEY_INFO                 0x009C9D
          KEY_EXIT                 0x00CBCA
          KEY_OK                   0x009293
          KEY_UP                   0x005253
          KEY_DOWN                 0x00D2D3
          KEY_LEFT                 0x007273
          KEY_RIGHT                0x00F2F3
          KEY_OPTION               0x90E574
          KEY_ENTER                0x002B2A
          KEY_BACK                 0x002B2A
          KEY_R                    0x000E0F
          KEY_G                    0x008E8F
          KEY_Y                    0x004E4F
          KEY_B                    0x00CECF
          KEY_TEXT                 0x80C041
          KEY_1                    0x000809
          KEY_2                    0x008889
          KEY_3                    0x004849
          KEY_4                    0x00C8C9
          KEY_5                    0x002829
          KEY_6                    0x00A8A9
          KEY_7                    0x006869
          KEY_8                    0x00E8E9
          KEY_9                    0x001819
          KEY_0                    0x009899
          KEY_MUTE                 0x004C4D
          KEY_LAST                 0x00ECED
          KEY_VOLUMEUP             0x000405
          KEY_VOLUMEDOWN           0x008485
          KEY_CHANNELUP            0x002C2D
          KEY_CHANNELDOWN          0x00ACAD
      end codes

end remote

General (Japan) Air Conditioner MODEL ASWX09FAC

begin remote

  name   general
  flags RAW_CODES
  eps            30
  aeps          100

  ptrail          0
  repeat     0     0
  gap    107325

begin raw_codes
        name KEY_POWER
      3317     1592      440      393      466      363
      445     1204      440      394      439     1214
      435      390      439      394      439      390
      444     1205      440     1209      440      389
      444      389      440      389      444     1212
      437     1205      466      368      439      390
      444      389      465      364      444      389
      466      367      466      363      445      389
      465      363      444      396      459      368
      465      364      444      389      466     1183
      466      363      440      394      465      363
      444      390      465      368      466      363
      444      395      460     1183      466      363
      466      367      466      368      465      363
      466      368      465     1179      471     1178
      466     1190      459     1184      465     1179
      475     1175      465      368      465      363
      471      363      466     1192      457      363
      470      363      466      367      466      363
      470      363      466      363      470      364
      465      368      465     1180      469     1180
      469      365      467      361      470     1191
      456      366      465      363      470      370
      460      363      470     1178      470      364
      465      364      470     1179      470      363
      492      337      496      337      466      367
      492      337      496      337      492      342
      491      337      471      363      492      337
      496      337      492      341      492      337
      496      337      492      341      492      337
      471      363      491      337      497      337
      491      342      492      337      496      337
      493      336      496      337      470      363
      492      337      496      337      492      342
      491      337      496      337      492      342
      492      337      495      338      491      338
      503      330      470      363      492      337
      496      337      492      341      492      337
      496     1153      470     1179      492     1153
      502      331      496     1153      491      342
      491     1154      496
        name KEY_POWER2
     3339     1572      466      368      465      363
      470     1179      466      367      466     1179
      470      363      466      375      457      364
      470     1179      466     1183      465      363
      471      363      466      367      466     1178
      471     1179      466      368      465      363
      470      363      466      367      466      363
      470      363      466      363      469      364
      466      368      466      363      470      363
      466      367      467      362      466     1183
      466      367      466      363      469      364
      466      363      470      363      470      363
      492      337      497     1153      470      363
      492      337      496      335      493      342
      492     1152      497      337      492      341
      492      337      470      363      492      337
      496      337      491

end raw_codes
end remote

* KEY_POWER is ON, KEY_POWER2 is OFF

Updated 2018-01-17

Dyson AM09

begin remote

  name dyson
  bits            8
  flags RAW_CODES
   eps            30
   aeps          100

   ptrail          0
   repeat     0     0
   gap          40991

      begin raw_codes
        name KEY_POWER
     2233      676      796     1400      834     1390
      770      670      780     1446      806      660
      780      685      780      689      807      711
      806      711      781      737      784      712
      780      711      807      685      780      716
      771     1450      785   101390

     2238      688      775     1394      783     1400
      793      678      707     1480      806      659
      776      668      729      732      749      794
      785      716      793      746      805      686
      807      685      781      711      780      715
      768     1454      780

        name KEY_C
     2218      683      789     1390      743     1453
      806      660      805     1432      756      673
      779      685      807      660      805     1447
      806      710      773     1430      790      728
      775     1420      780      710      782     1425
      797      690      806   101276

     2211      689      779     1394      793     1434
      805      661      785     1423      793      664
      719      745      781      710      783     1445
      790      732      776     1426      797      714
      781     1421      779      717      776     1451
      771      710      760
        name KEY_UP
     2209      689      780     1420      806     1420
      767      678      774     1447      780      706
      759      699      759      673      822      729
      771     1447      779      737      754     1448
      779      743      749     1447      780     1417
      779     1421      780   101621

     2246      691      778     1391      780     1398
      794      668      805     1421      753      687
      775      664      719      745      825      718
      782     1447      779      728      790     1417
      810      690      776     1442      779     1421
      780     1425      775
        name KEY_RED
     2228      690      777     1397      823     1404
      777      692      775     1464      759      695
      692      748      780      690      806      738
      775     1452      776     1453      768     1432
      828     1425      781      710      781     1447
      782     1419      780   101923

     2223      689      774     1399      792     1435
      775      691      775     1453      769      696
      752      692      777      689      803      741
      770     1453      769     1457      771     1435
      820     1464      745      712      783     1443
      771     1410      798
        name KEY_DOWN
     2269      657      779     1394      827     1399
      810      656      810     1416      780      664
      723      744      782      682      810     1442
      785     1442      784     1443      779     1473
      780     1446      779     1422      719      770
      787     1415      784   101186

     2245      664      794     1398      794     1385
      719      741      781     1425      775      665
      765      715      759      687      809     1443
      779     1448      782     1440      752     1500
      753     1474      722     1486      710      772
      776     1426      774
        name KEY_R
     2232      685      804     1370      811     1387
      783      683      815     1391      751      710
      783      686      779      687      809     1442
      780     1457      769      713      784      712
      791     1429      788     1418      793     1438
      770      687      721   101693

     2245      666      718     1476      785     1391
      805      686      753     1420      771      669
      779      686      805      660      819     1433
      793     1438      793      713      786      711
      807     1416      806     1400      800     1395
      718      769      810
        name KEY_A
     2157      744      810     1402      772     1394
      762      719      760     1447      805      661
      779      664      766      725      797     1430
      792      724      808      686      779      715
      794      714      791     1416      779     1421
      806     1395      718   101385

     2271      662      778     1395      779     1416
      778      670      763     1432      780      686
      780      664      792      669      821     1457
      779      716      823      714      786      718
      782      727      782     1394      793     1455
      784     1416      779
        name KEY_MOVE
     2232      692      766     1404      833     1368
      771      671      777     1447      779      687
      779      691      771      668      827      714
      782      737      772     1486      771     1425
      781      735      754      714      777      734
      764      710      695   101800

     2234      691      775     1400      778     1400
      793      677      710     1481      775      687
      779      664      719      744      752      792
      782      744      770     1477      789     1415
      715      775      720      767      782      725
      797      741      744
        name KEY_H
     2215      687      783     1390      789     1409
      781      669      791     1426      753      687
      789      658      805      656      831      713
      779     1447      780      721      791      717
      779     1448      751      723      768      715
      784     1416      778   101033

     2164      746      815     1376      811     1371
      811      655      804     1396      716      728
      800      666      799      665      805      721
      733     1494      711      798      804      687
      803     1427      802      668      792      695
      777     1423      774
        name KEY_D
     2217      687      778     1421      776     1399
      780      685      779     1420      770      697
      751      689      779      686      805     1458
      772      735      773     1453      742     1458
      822      731      761     1429      780     1420
      780      716      772   101584

     2219      686      779     1421      777     1393
      780      691      781     1415      696      747
      795      670      773      692      799     1449
      782      718      774     1447      734     1490
      779      742      730     1491      773     1422
      778      718      769
        name KEY_TIME
     2212      696      772     1424      801     1432
      765      694      749     1451      775      707
      758      714      751      708      788      742
      749      768      750     1476      776     1447
      770     1434      774      719      774     1446
      753     1447      741   101574

     2241      691      779     1390      780     1398
      798      690      692     1507      780      684
      781      687      774      691      805      736
      742      767      763     1472      781     1429
      803     1414      775      738      754     1445
      755     1447      740
        name KEY_SLEEP
     2216      689      779     1390      810     1390
      805      638      718     1477      784      682
      784      664      791      669      805     1420
      794      735      773      708      810     1415
      784      712      778      714      779      690
      719      767      785   101750

     2217      688      805     1368      760     1436
      784      682      780     1420      758      681
      784      680      785      686      832     1416
      810      733      754      727      773     1442
      775      739      753      694      763      733
      801      664      797

      end raw_codes

end remote

Dyson Key Mapping Table

KEY_POWER Power
KEY_C Cool Mode
KEY_UP Increase airflow speed
KEY_DOWN Decrease airflow speed
KEY_RED Thermostat control up
KEY_R Thermostat control down
KEY_A Auto mode
KEY_MOVE Oscillation ON/OFF
KEY_H Personal heating mode
KEY_D Diffused mode
KEY_TIME Timer
KEY_SLEEP Sleep mode

Thomson tm-kk8

begin remote

  name tmkk8
  bits            8
  flags RAW_CODES
   eps            30
   aeps          100

   ptrail          0
   repeat     0     0
   gap          40991

      begin raw_codes
	name KEY_POWER
	     3052     1015      723     1503     1483      725
     1484      725     1484      725      724     1504
     1483      736      712     1510     1488
	name KEY_HOME
	     3076      984      752     1478     1511      697
      748     1478     1516      693      753     1489
      745     1471     1514      696     1514     5099
     3060      980      752     1475     1513      700
      749     1478     1511      698      753     1478
      750     1477     1519      690     1510     5100
     3068      976      749     1477     1512      698
      753     1474     1515      698      751     1476
      752     1479     1510      694     1516
	name KEY_UP
     3084      995      758     1481     1496      700
      746     1484      748     1480      747     1484
      747     1480      751     1475     1515    34469

     3089      984      754     1473     1515      716
      732     1476      752     1477      754     1477
      750     1477      751     1480     1527
	name KEY_DOWN
	     3083      987      746     1476     1511      700
      749     1481      750     1478      727     1504
      748     1478     1510      710     1500    34485

     3098      984      748     1498     1521      699
      727     1504      747     1479      753     1478
      749     1477     1521      690     1509
	name KEY_LEFT
	     3076      984      748     1478     1524      684
      754     1480      747     1479      778     1448
     1550      659      779     1453     1510
	name KEY_RIGHT
     3085      957      781     1445     1540      669
      779     1452      779     1448      779     1451
     1539      669     1541      664     1540    34481

     3082      983      765     1461     1515      693
      756     1475      754     1477      749     1477
     1515      694     1515      694     1511    34478

     3086      985      748     1478     1508      700
      753     1477      749     1483      747     1480
     1508      698     1510      705     1505
	name KEY_S
	     3077      983      754     1479     1508      707
      742     1478      751     1479     1509      699
      750     1478     1520      687      724     6328
     3061     1005      722     1504     1483      725
      723     1510      717     1510     1482      725
      724     1503     1485      729      718     6327
     3054     1014      721     1506     1482      726
      723     1509      722     1504     1484      725
      723     1505     1483      725      723
	  
      end raw_codes

end remote

Update 2018-01-18

Philips Bluray Player HTB5520/98

begin remote

  name  philipsbluray
  bits           21
  flags RC6|CONST_LENGTH
  eps            30
  aeps          100

  header       2721   841
  one           475   421
  zero          475   421
  gap          106444
  toggle_bit_mask 0x10000
  rc6_mask    0x10000
  frequency    38000

      begin codes
          KEY_POWER                0x0EB938
          KEY_S                    0x0EB995
          KEY_TV                   0x0EB941
          KEY_HOME                 0x0EB96D
          KEY_BLUETOOTH            0x0EB996
          KEY_MENU                 0x0EB965
          KEY_CONTEXT_MENU         0x0EB963
          KEY_UP                   0x0EB9A7
          KEY_DOWN                 0x0EB9A6
          KEY_LEFT                 0x0EB9A5
          KEY_RIGHT                0x0EB9A4
          KEY_OK                   0x0EB9A3
          KEY_MEMO                 0x0EB936
          KEY_RED                  0x0EB992
          KEY_GREEN                0x0EB991
          KEY_YELLOW               0x0EB990
          KEY_BLUE                 0x0EB98F
          KEY_EJECTCD              0x0EB9BD
          KEY_PLAY                 0x0EB9D3
          KEY_PAUSE                0x0EB9CF
          KEY_STOP                 0x0EB9CE
          KEY_BACKSLASH            0x0EB9DE
          KEY_BACK                 0x0EB9D6
          KEY_FORWARD              0x0EB9D7
          KEY_FASTFORWARD          0x0EB9DF
          KEY_VOLUMEUP             0x0EB9EF
          KEY_VOLUMEDOWN           0x0EB9EE
          KEY_MUTE                 0x0EB9F2
          BTN_MODE                 0x0EB932
          KEY_1                    0x0EB9FE
          KEY_2                    0x0EB9FD
          KEY_3                    0x0EB9FC
          KEY_4                    0x0EB9FB
          KEY_5                    0x0EB9FA
          KEY_6                    0x0EB9F9
          KEY_7                    0x0EB9F8
          KEY_8                    0x0EB9F7
          KEY_9                    0x0EB9F6
          KEY_0                    0x0EB9FF
          KEY_SUBTITLE             0x0EB9B4
          KEY_AUDIO                0x0EB9B1
      end codes

end remote


Troubleshooting

For error during irsend

root@pi:/home/pi# irsend SEND_ONCE et5h KEY_POWER
irsend: could not connect to socket
irsend: No such file or directory

Solution

Execute the command below to fix.

# sudo su
# lircd -d /dev/lirc0 

Conclusion

I found the Pi Infra red project is very useful. It allows me to trigger devices with infra red when I’m away from home with iOS Home app. Also it is very useful to backup your remotes this way so that in case you lost your remote, you can still control things with your Pi, or train a universal remote with the recorded IR codes on Pi. Due to the fact that replacement remote is not always available, especially for old model devices. You lost your remote, your device are left in the dust forever.



Leave a Reply

Your email address will not be published. Required fields are marked *